-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReportStorageWebExtension1.cs
62 lines (53 loc) · 2.22 KB
/
ReportStorageWebExtension1.cs
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
using System.Collections.Generic;
using System.IO;
using System.Linq;
using DevExpress.XtraReports.UI;
namespace DevExpressWebFarmsWebGardenReporting {
public class ReportStorageWebExtension1 : DevExpress.XtraReports.Web.Extensions.ReportStorageWebExtension {
readonly string workingDirectory;
public ReportStorageWebExtension1(string workingDirectory) {
this.workingDirectory = workingDirectory;
}
public override bool IsValidUrl(string url) {
return true;
}
public override string SetNewData(XtraReport report, string defaultUrl) {
this.SetData(report, defaultUrl);
return defaultUrl;
}
public override byte[] GetData(string url) {
if(url == "Invoice")
return SerializeReport(new InvoiceReport());
url += url.EndsWith(".repx") ? "" : ".repx";
using(var fileStream = File.OpenRead(Path.Combine(workingDirectory, url))) {
var report = XtraReport.FromStream(fileStream, true);
return SerializeReport(report);
}
}
public override Dictionary<string, string> GetUrls() {
var dictionary = new Dictionary<string, string>();
dictionary.Add("Invoice", "Invoice Report");
var files = Directory.GetFiles(workingDirectory);
foreach(var item in files.Where(x => x.Contains(".repx")).Select(x => x.Split('\\').Last())) {
dictionary.Add(item, item);
}
return dictionary;
}
public override void SetData(DevExpress.XtraReports.UI.XtraReport report, string url) {
url += url.EndsWith(".repx") ? "" : ".repx";
using(var fileStream = File.OpenWrite(Path.Combine(workingDirectory, url))) {
report.SaveLayoutToXml(fileStream);
}
}
public override bool CanSetData(string url) {
return true;
}
byte[] SerializeReport(XtraReport report) {
using(MemoryStream stream = new MemoryStream()) {
report.SaveLayoutToXml(stream);
stream.Position = 0;
return stream.GetBuffer();
}
}
}
}