-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFilesystemReportStorageWebExtension.cs
99 lines (85 loc) · 3.28 KB
/
FilesystemReportStorageWebExtension.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.IO;
using System.Collections.Generic;
using System;
using DevExpress.XtraReports.UI;
using System.Web;
using System.ServiceModel;
namespace T227679 {
public class FilesystemReportStorageWebExtension : DevExpress.XtraReports.Web.Extensions.ReportStorageWebExtension {
HttpContext _context;
public const string STORAGE_FOLDER_PATH = @"~\App_Data\ReportsStorage\";
public FilesystemReportStorageWebExtension(HttpContext context) {
this._context = context;
}
public HttpContext Context {
get {
return _context;
}
}
protected string GetPath(string url) {
if (Path.IsPathRooted(url)) {
return url;
}
return Context.Server.MapPath(Path.Combine(STORAGE_FOLDER_PATH, url));
}
public override bool CanSetData(string url) {
string filePath = GetPath(url);
return File.Exists(filePath);
}
public override byte[] GetData(string url) {
try {
string filePath = GetPath(url);
return File.ReadAllBytes(filePath);
}
catch (Exception ex) {
//Pass readable exception message to the Web Report Designer
throw new FaultException(ex.Message);
}
}
public override Dictionary<string, string> GetUrls() {
string storagePath = Context.Server.MapPath(STORAGE_FOLDER_PATH);
Dictionary<string, string> urls = new Dictionary<string, string>();
string[] reportFiles = Directory.GetFiles(storagePath, "*.repx", SearchOption.AllDirectories);
foreach (string filePath in reportFiles) {
urls.Add(filePath, filePath.Replace(storagePath, String.Empty));
}
return urls;
}
public override bool IsValidUrl(string url) {
string filePath = GetPath(url);
if (File.Exists(filePath))
return true;
try {
File.Create(filePath).Close();
File.Delete(filePath);
return true;
}
catch {
return false;
}
}
public override void SetData(XtraReport report, string url) {
try {
string filePath = GetPath(url);
throw new NotSupportedException("Saving is not allowed."); //Comment this line to enable saving
report.SaveLayoutToXml(filePath);
}
catch (Exception ex) {
//Pass readable exception message to the Web Report Designer
throw new FaultException(ex.Message);
}
}
public override string SetNewData(XtraReport report, string defaultUrl) {
try {
string filePath = GetPath(defaultUrl);
throw new NotSupportedException("Saving is not allowed."); //Comment this line to enable saving
report.SaveLayoutToXml(filePath);
return filePath;
}
catch (Exception ex) {
//Pass readable exception message to the Web Report Designer
throw new FaultException(ex.Message);
}
}
}
}