-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReportStorageWebExtension1.vb
64 lines (55 loc) · 2.11 KB
/
ReportStorageWebExtension1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports DevExpress.XtraReports.UI
Namespace DevExpressWebFarmsWebGardenReporting
Public Class ReportStorageWebExtension1
Inherits DevExpress.XtraReports.Web.Extensions.ReportStorageWebExtension
Private ReadOnly workingDirectory As String
Public Sub New(ByVal workingDirectory As String)
Me.workingDirectory = workingDirectory
End Sub
Public Overrides Function IsValidUrl(ByVal url As String) As Boolean
Return True
End Function
Public Overrides Function SetNewData(ByVal report As XtraReport, ByVal defaultUrl As String) As String
Me.SetData(report, defaultUrl)
Return defaultUrl
End Function
Public Overrides Function GetData(ByVal url As String) As Byte()
If url = "Invoice" Then
Return SerializeReport(New InvoiceReport())
End If
url &= If(url.EndsWith(".repx"), "", ".repx")
Using fileStream = File.OpenRead(Path.Combine(workingDirectory, url))
Dim report = XtraReport.FromStream(fileStream, True)
Return SerializeReport(report)
End Using
End Function
Public Overrides Function GetUrls() As Dictionary(Of String, String)
Dim dictionary = New Dictionary(Of String, String)()
dictionary.Add("Invoice", "Invoice Report")
Dim files = Directory.GetFiles(workingDirectory)
For Each item In files.Where(Function(x) x.Contains(".repx")).Select(Function(x) x.Split("\"c).Last())
dictionary.Add(item, item)
Next item
Return dictionary
End Function
Public Overrides Sub SetData(ByVal report As DevExpress.XtraReports.UI.XtraReport, ByVal url As String)
url &= If(url.EndsWith(".repx"), "", ".repx")
Using fileStream = File.OpenWrite(Path.Combine(workingDirectory, url))
report.SaveLayoutToXml(fileStream)
End Using
End Sub
Public Overrides Function CanSetData(ByVal url As String) As Boolean
Return True
End Function
Private Function SerializeReport(ByVal report As XtraReport) As Byte()
Using stream As New MemoryStream()
report.SaveLayoutToXml(stream)
stream.Position = 0
Return stream.GetBuffer()
End Using
End Function
End Class
End Namespace