-
Notifications
You must be signed in to change notification settings - Fork 0
/
C1ReportHttpHandler.ashx
177 lines (154 loc) · 7.42 KB
/
C1ReportHttpHandler.ashx
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<%@ WebHandler Language="C#" Class="C1ReportHttpHandler" %>
//C1ReportHttpHandler.ashx
using System;
using System.Web;
using System.Collections;
using C1.Web.UI.Controls.C1Report;
public class C1ReportHttpHandler : IHttpHandler
{
#region IHttpHandler Members
public void ProcessRequest(HttpContext context)
{
// list of common MIME types and their corresponding file extensions.
// http://www.webmaster-toolkit.com/mime-types.shtml
System.Collections.Specialized.NameValueCollection args = context.Request.Params;
string command = args["command"];
string reqid = args["reqid"];
if (string.IsNullOrEmpty(command))
command = "";
if (string.IsNullOrEmpty(reqid))
reqid = "";
byte[] buffer;
IC1WebReportService reportService;
switch (command)
{
case "dialog_template":
context.Response.ContentType = "text/x-html";
context.Response.Write(GetDialogTemplateContent((string)args["name"]));
context.Response.End();
break;
case "GetPageImagesMarkup":
context.Response.ContentType = "application/json";
reportService = C1.Web.UI.Controls.C1Report.ReportService.C1WebReportServiceHelper.MakeHelper((string)args["documentKey"]);
object answer = reportService.GetPageImagesMarkup((string)args["documentKey"], int.Parse(args["dpi"]), int.Parse(args["zoom"]), (int[])((System.Collections.ArrayList)ToArrayList(args["pageIndices"])).ToArray(typeof(int)), bool.Parse(args["getImagesOnly"]));
Hashtable result = new Hashtable();
result["reqid"] = reqid;
result["answer"] = answer;
/*
#if DEBUG
if (!string.IsNullOrEmpty(C1Report.__outputdebugstring))
{
result["__outputdebugstring"] = C1Report.__outputdebugstring;
C1Report.__outputdebugstring = "";
}
#endif
*/
//string s = C1.Web.UI.Utils.Json.JsonHelper.ObjectToString(result, this, true);
string s = C1.Web.UI.Utils.Json.JsonHelper.ObjectToString(result, null, true);
context.Response.Write(s);
context.Response.End();
break;
case "Export":
/*
Response.Buffer = false;
Response.AppendHeader("Content-Type", "octet-stream");
Response.AppendHeader("Content-Disposition", "attachment");
Response.Flush();
*/
string exportFormat = args["exportFormat"];
reportService = C1.Web.UI.Controls.C1Report.ReportService.C1WebReportServiceHelper.MakeHelper((string)args["documentKey"]);
string url = reportService.ExportToFile(args["documentKey"], exportFormat);
context.Response.ContentType = "text/html";
System.Text.StringBuilder htmlBuilder = new System.Text.StringBuilder();
htmlBuilder.AppendLine("<html>");
htmlBuilder.AppendLine("<header>");
htmlBuilder.AppendLine("<title>Download " + exportFormat + "</title>");
if (!url.StartsWith("error:"))
htmlBuilder.AppendLine("<meta http-equiv=\"REFRESH\" CONTENT=\"5; url=" + url + "\">");
htmlBuilder.AppendLine("</header>");
htmlBuilder.AppendLine("<body>");
if (!url.StartsWith("error:"))
{
htmlBuilder.AppendLine("<h1>");
htmlBuilder.AppendLine("Exported document download.");
htmlBuilder.AppendLine("</h1>");
htmlBuilder.AppendLine("<p>");
htmlBuilder.AppendLine("Your download should begin shortly. If your download does not start in approximately 10 seconds, you can ");
htmlBuilder.AppendLine("<a href=\"" + url + "\">");
htmlBuilder.AppendLine("click here");
htmlBuilder.AppendLine("</a>");
htmlBuilder.AppendLine(" to launch the download.</p>");
htmlBuilder.AppendLine("<div style=\"background-color:#cccccc;\">");
htmlBuilder.AppendLine("Download URL: " + "<a href=\"" + url + "\">" + url + "</a>");
htmlBuilder.AppendLine("<br />");
htmlBuilder.AppendLine("Export Format: " + exportFormat);
htmlBuilder.AppendLine("<br />");
htmlBuilder.AppendLine("Internal Document Key: " + args["documentKey"]);
htmlBuilder.AppendLine("</div>");
}
else
{
htmlBuilder.AppendLine("<h2 style=\"color:red;\">" + url + "</h2>");
}
htmlBuilder.AppendLine("</body>");
htmlBuilder.AppendLine("</html>");
context.Response.Write(htmlBuilder.ToString());
context.Response.End();
break;
case "":
default:
context.Response.Clear();
//image/png
context.Response.ContentType = "image/png";
reportService = C1.Web.UI.Controls.C1Report.ReportService.C1WebReportServiceHelper.MakeHelper((string)args["documentKey"]);
bool printTarget = false;
if (args["printTarget"] != null)
printTarget = bool.Parse(args["printTarget"]);
buffer = reportService.GetPageImage(args["documentKey"], int.Parse(args["dpi"]), int.Parse(args["zoom"]), int.Parse(args["pageIndex"]), printTarget);
context.Response.OutputStream.Write(buffer, 0, buffer.Length);
context.Response.End();
break;
}
// context.Response.Flush();
//context.Response.Write("Hello World");
}
string GetDialogTemplateContent(string dialogName)
{
string localPath = HttpContext.Current.Server.MapPath("~/C1ReportDialogs/" + dialogName + ".htm");
if (System.IO.File.Exists(localPath))
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(localPath))
{
string s = reader.ReadToEnd();
return s;
}
}
return C1ReportViewer.GetDialogTemplateContent(dialogName);
}
System.Collections.ArrayList ToArrayList(string s)
{
s = s.Trim(new char[] { '[', ']' });
string[] indicesStrArr = s.Split(',');
System.Collections.ArrayList arr = new System.Collections.ArrayList();
for (int i = 0; i < indicesStrArr.Length; i++)
{
arr.Add(int.Parse(indicesStrArr[i]));
}
return arr;
}
public bool IsReusable
{
get
{
return false;
}
}
#endregion
/*
application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json
*/
}