API/AdHocConfig.md
... ...
@@ -0,0 +1,492 @@
1
+#AdHocConfig
2
+
3
+[[_TOC_]]
4
+
5
+##About
6
+
7
+The AdHocConfig class is where Izenda Reports will perform all of its initialization and configuration. You can also override various methods used by the base class in order to control various aspects of the reporting application. At a minimum, you will probably need to override the ConfigureSettings() and PostLogin() methods. This will work for most cases, but we will provide a template with a full list of overridden methods below. This code should be placed in the Global.asax file of your web site.
8
+
9
+##C♯ Example
10
+
11
+```csharp
12
+[Serializable]
13
+//The main reporting class, usually declared in global.asax. This can inherit FileSystemAdHocConfig or DatabaseAdHocConfig
14
+public class CustomAdHocConfig : Izenda.AdHoc.FileSystemAdHocConfig
15
+{
16
+ //Initializing these settings in a static context is a best practice for Izenda to run smoothly. This method will need to be called on your reporting pages or from Session_Start().
17
+ public static void InitializeReporting()
18
+ {
19
+ AdHocSettings.LicenseKey = "INSERT_LICENSE_KEY_HERE";
20
+ AdHocSettings.SqlServerConnectionString = "INSERT_CONNECTION_STRING_HERE";
21
+ AdHocSettings.GenerateThumbnails = True;
22
+ AdHocSettings.DashboardViewer = "Dashboards.aspx";
23
+ AdHocSettings.ShowSimpleModeViewer = True;
24
+ AdHocSettings.IdentifiersRegex = "^.*[iI][Dd]$";
25
+ AdHocSettings.TabsCssUrl = "Resources/css/tabs.css";
26
+ AdHocSettings.ReportCssUrl = "Resources/css/Report.css";
27
+ AdHocSettings.ShowBetweenDateCalendar = True;
28
+ AdHocSettings.AdHocConfig = New CustomAdHocConfig();
29
+ HttpContext.Current.Session("ReportingInitialized") = True;
30
+
31
+ }
32
+ // Store all global code here that applies to all users.
33
+ public override void ConfigureSettings()
34
+ {
35
+ AdHocSettings.AllowOverwritingReports = true;
36
+ AdHocSettings.AllowDeletingReports = true;
37
+ }
38
+
39
+ // AdHocSettings.AdHocConfig.PostLogin() must be called from
40
+ // your application's login page after the user is authenticated
41
+ // Place ALL user-specific or role-specific code here
42
+ public override void PostLogin()
43
+ {
44
+ //Pass User Credentials
45
+ AdHocSettings.CurrentUserName = HttpContext.Current.Session["UserName"] as string;
46
+ AdHocSettings.CurrentUserIsAdmin = true;
47
+ AdHocSettings.VisibleDataSources = new string[] { "Orders", "Employees", "AdminData" };
48
+
49
+ //Filters results for data sources containing ClientID
50
+ AdHocSettings.HiddenFilters["ClientID"] = HttpContext.Current.Session["ClientID"] as string;
51
+
52
+ //Multi-Role Scenario - Apply specific limitations to certain roles
53
+ string role = HttpContext.Current.Session["Role"] as string;
54
+ if (!role.Equals("Administrator"))
55
+ {
56
+ // Limit user to the orders table
57
+ AdHocSettings.VisibleDataSources = new string[] { "Orders" };
58
+ // Prevent the user from seeing private reports and overwriting shared reports
59
+ // Disable access to settings button.
60
+ AdHocSettings.CurrentUserIsAdmin = false;
61
+ // Hide reports saved to certain categories
62
+ AdHocSettings.ShowSettingsButton = false;
63
+ AdHocSettings.HiddenCategories = new string[] { "Admin Reports", "Sensitive Reports" };
64
+ }
65
+ }
66
+
67
+ // Gets a list of ReportInfo objects for all loadable reports stored.
68
+ public override ReportInfo[] FilteredListReports()
69
+ {
70
+ ReportInfo[] reports = ListReports();
71
+ ArrayList result = new ArrayList();
72
+
73
+ foreach (ReportInfo info in reports)
74
+ {
75
+ if (info.Category == "Hidden reports")
76
+ continue;
77
+ ReportSet reportSet = LoadFilteredReportSet(info.Name);
78
+ if (reportSet != null && reportSet.CanBeLoaded)
79
+ result.Add(info);
80
+ }
81
+ return (ReportInfo[])result.ToArray(typeof(ReportInfo));
82
+ }
83
+
84
+ // Gets a list of ReportInfo for all loadable reports stored in the storage.
85
+ public override System.Collections.Generic.Dictionary FilteredListReportsDictionary()
86
+ {
87
+ ReportInfo[] reports = ListReports();
88
+ Array.Sort(reports);
89
+ Dictionary result = new Dictionary();
90
+
91
+ foreach (ReportInfo info in reports)
92
+ {
93
+ if (info.Category == "Hidden reports")
94
+ continue;
95
+ ReportSet reportSet = LoadFilteredReportSet(info.Name);
96
+ if (reportSet != null && reportSet.CanBeLoaded)
97
+ result.Add(info, reportSet);
98
+ }
99
+ return result;
100
+ }
101
+
102
+ // Convert report full name into report GUID
103
+ public override string GetReportIDByName(string fullReportName)
104
+ {
105
+ if (fullReportName == "report_1")
106
+ return base.GetReportIDByName("report_2");
107
+ else
108
+ return base.GetReportIDByName(fullReportName);
109
+ }
110
+
111
+// Convert report GUID into report full name
112
+public override string GetReportNameById(string id)
113
+{
114
+ if (id == "report_1")
115
+ return base.GetReportNameById("report_2");
116
+ else
117
+ return base.GetReportNameById(id);
118
+}
119
+
120
+// Method called after ReportSet was executed
121
+public override void PostExecuteReportSet(ReportSet reportSet)
122
+{
123
+ reportSet.WriteXml();
124
+}
125
+
126
+// Method called after reportSet was loaded
127
+public override void PostLoadReportSet(string name, ReportSet reportSet)
128
+{
129
+ base.PostLoadReportSet(name, reportSet);
130
+}
131
+
132
+public override void PreLoadReportSet(string name)
133
+{
134
+ base.PreLoadReportSet(name);
135
+}
136
+
137
+// Overrides the method of saving report in .rdl format
138
+public override void SaveReportRDL(string reportName)
139
+{
140
+ // Get file path
141
+ string rdlFilePath = "C:\\Reports\\RDL\\" + reportName + ".rdl";
142
+
143
+ // Build rdl content
144
+ StringBuilder builder = new StringBuilder();
145
+
146
+ XmlTextWriter writer = new XmlTextWriter(new StringWriter(builder));
147
+ Izenda.AdHoc.AdHocContext.CurrentReportSet.WriteRdl(writer);
148
+ writer.Flush();
149
+ // Write content to file
150
+ File.WriteAllText( rdlFilePath, builder.ToString());
151
+}
152
+
153
+// Returns a list of reports to the reprt viewr and all report list dropdowns
154
+public override ReportInfo[] ListReports()
155
+{
156
+ return new ReportInfo[] { new ReportInfo("report 1"), new ReportInfo("report 2") };
157
+}
158
+
159
+// Runs after report export to allow archiving
160
+public override void ArchiveReportOutput(ReportSet reportSet,
161
+ string[] emails,
162
+ string extension,
163
+ byte[] data)
164
+{
165
+// save to archive
166
+ using (BinaryWriter bw = new BinaryWriter(File.Open(reportSet.ReportName + "_sent", FileMode.Create)))
167
+ bw.Write(data);
168
+}
169
+
170
+// This method overrides the default behavor of the Equals(...)
171
+// operators in the filters tab and report viewer.
172
+// If using Equals(...) with stored procedures, this is required.
173
+public override string[] ProcessEqualsSelectList(Column column)
174
+{
175
+ if (column.Name == "ParameterField")
176
+ return new string[] { "Value1", "Value2", "Value3" };
177
+ return base.ProcessEqualsSelectList(column);
178
+}
179
+
180
+// Control what operators are availabile for each field type in the Filters tab or report viewer
181
+public override string[] GetOperatorList(SqlType type, bool isStoredProcedureUsed)
182
+public override string[] GetOperatorList(SqlType type, bool isStoredProcedureUsed)
183
+{
184
+ string[] result = base.GetOperatorList(type, isStoredProcedureUsed);
185
+ string[] cutResult = new string[result.Length / 2];
186
+ Array.Copy(result, cutResult, result.Length / 2);
187
+ return cutResult;
188
+}
189
+
190
+// Executes whenever an existing report is loaded or executed
191
+public override ReportSet LoadReportSet(string reportName)
192
+{
193
+ ReportSet rs = new ReportSet();
194
+ using (StreamReader sr = new StreamReader(reportName + ".xml"))
195
+ rs.ReadXml(sr.ReadToEnd());
196
+ return rs;
197
+}
198
+
199
+public override void SaveReportSet(string reportName, ReportSet reportSet)
200
+{
201
+ using (StreamWriter sw = new StreamWriter(reportName + ".xml"))
202
+ sw.Write(reportSet.WriteXml());
203
+}
204
+
205
+public override void DeleteReportSet(string reportName)
206
+{
207
+ File.Delete(reportName + ".xml");
208
+}
209
+
210
+// Create new types of charts or customize existing styles
211
+public override void CustomizeChart(object chart, Hashtable properties)
212
+{
213
+ if (!properties.ContainsKey("NoAA"))
214
+ return;
215
+ if ((bool)properties["NoAA"])
216
+ ((Dundas.Charting.WebControl.Chart)chart).AntiAliasing = Dundas.Charting.WebControl.AntiAliasing.None;
217
+}
218
+
219
+// Create new types of charts or customize existing styles
220
+public override void CustomizeChart(object chart)
221
+{
222
+ ((Dundas.Charting.WebControl.Chart)chart).AntiAliasing = Dundas.Charting.WebControl.AntiAliasing.None;
223
+}
224
+
225
+// Process exeptions in a custom manner
226
+public override Control ProcessFriendlyException(Exception exception)
227
+{
228
+ return new LiteralControl("exception occurred " + exception.Message);
229
+}
230
+
231
+// Add additional style elememnts to the guage
232
+public override System.Drawing.Image CustomizeGuage(double value,
233
+ double min,
234
+ double max,
235
+ string name,
236
+ System.Drawing.Image GuageImage)
237
+{
238
+ GuageImage.Save("rendered_gauge.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
239
+ return GuageImage;
240
+}
241
+
242
+// Dynamically modify the report before execution.
243
+public override void PreExecuteReportSet(ReportSet reportSet)
244
+{
245
+ reportSet.Footer = DateTime.Now.ToString();
246
+}
247
+
248
+// Dynamically modify the results after they come back
249
+// from the database and before they are rendered
250
+public override void ProcessDataSet(DataSet ds, string reportPart)
251
+{
252
+ if (reportPart == "Chart")
253
+ ds.Tables[0].Rows[0][0] = "modified_data";
254
+}
255
+
256
+}
257
+```
258
+
259
+##VB.NET Example
260
+
261
+```visualbasic
262
+
263
+<Serializable()> Public Class CustomAdHocConfig
264
+ Inherits FileSystemAdHocConfig
265
+ Public Shared Sub InitializeReporting()
266
+ 'Check to see if we've already initialized.
267
+ If (HttpContext.Current.Session Is Nothing OrElse (Not (HttpContext.Current.Session("ReportingInitialized") Is Nothing))) Then
268
+ Return
269
+ End If
270
+ 'Initialize System
271
+ AdHocSettings.LicenseKey = "INSERT_LICENSE_KEY_HERE"
272
+ AdHocSettings.SqlServerConnectionString = "INSERT_CONNECTION_STRING_HERE"
273
+ AdHocSettings.GenerateThumbnails = True
274
+ AdHocSettings.DashboardViewer = "Dashboards.aspx"
275
+ AdHocSettings.ShowSimpleModeViewer = True
276
+ AdHocSettings.IdentifiersRegex = "^.*[iI][Dd]$"
277
+ AdHocSettings.TabsCssUrl = "Resources/css/tabs.css"
278
+ AdHocSettings.ReportCssUrl = "Resources/css/Report.css"
279
+ AdHocSettings.ShowBetweenDateCalendar = True
280
+ AdHocSettings.AdHocConfig = New CustomAdHocConfig()
281
+ HttpContext.Current.Session("ReportingInitialized") = True
282
+ End Sub
283
+
284
+'Store all global code here that applies to all users.
285
+ Public Overrides Sub ConfigureSettings()
286
+ AdHocSettings.AllowOverwritingReports = True
287
+ AdHocSettings.AllowDeletingReports = True
288
+ End Sub
289
+
290
+ 'AdHocSettings.AdHocConfig.PostLogin() must be called from
291
+ 'your application's login page after the user is authenticated
292
+ 'Place ALL user-specific or role-specific code here
293
+ Public Overrides Sub PostLogin()
294
+ 'Pass User Credentials
295
+ AdHocSettings.CurrentUserName = HttpContext.Current.Session("UserName").ToString()
296
+ AdHocSettings.CurrentUserIsAdmin = True
297
+ AdHocSettings.VisibleDataSources = New String() {"Orders", "Employees", "AdminData"}
298
+ 'Filters results for data sources containing ClientID
299
+ AdHocSettings.HiddenFilters("ClientID") = HttpContext.Current.Session("ClientID").ToString()
300
+ 'Multi-Role Scenario - Apply specific limitations to certain roles
301
+ Dim role As String = HttpContext.Current.Session("Role").ToString()
302
+ If Not role.Equals("Administrator") Then
303
+ 'Limit user to the orders table
304
+ AdHocSettings.VisibleDataSources = New String() {"Orders"}
305
+ 'Prevent the user from seeing private reports and overwriting shared reports
306
+ 'Disable access to settings button.
307
+ AdHocSettings.CurrentUserIsAdmin = False
308
+ 'Hide reports saved to certain categories
309
+ AdHocSettings.ShowSettingsButton = False
310
+ AdHocSettings.HiddenCategories = New String() {"Admin Reports", "Sensitive Reports"}
311
+ End If
312
+ End Sub
313
+
314
+ 'Gets a list of ReportInfo objects for all loadable reports stored.
315
+ Public Overrides Function FilteredListReports() As ReportInfo()
316
+ Dim reports As ReportInfo() = ListReports()
317
+ Dim result As New List(Of ReportInfo)
318
+
319
+ For Each info As ReportInfo In reports
320
+ If Not info.Category = "Hidden reports" Then
321
+ Dim reportSet As ReportSet = LoadFilteredReportSet(info.Name)
322
+ If reportSet IsNot Nothing AndAlso reportSet.CanBeLoaded Then
323
+ result.Add(info)
324
+ End If
325
+ End If
326
+ Next
327
+ Return result.ToArray()
328
+ End Function
329
+
330
+ 'Gets a list of ReportInfo for all loadable reports stored in the storage.
331
+ Public Overrides Function FilteredListReportsDictionary() As Dictionary(Of ReportInfo, ReportSet)
332
+ Dim reports As ReportInfo() = ListReports()
333
+ Array.Sort(reports)
334
+ Dim result As Dictionary(Of ReportInfo, ReportSet) = New Dictionary(Of ReportInfo, ReportSet)
335
+
336
+ For Each info As ReportInfo In reports
337
+ If Not (info.Category = "Hidden reports") Then
338
+ Dim reportSet As ReportSet = LoadFilteredReportSet(info.Name)
339
+ If reportSet IsNot Nothing AndAlso reportSet.CanBeLoaded Then
340
+ result.Add(info, reportSet)
341
+ End If
342
+ End If
343
+ Next
344
+ Return result
345
+ End Function
346
+
347
+ 'Convert report full name into report GUID
348
+ Public Overrides Function GetReportIDByName(fullReportName As String) As String
349
+ If (fullReportName = "report_1") Then
350
+ Return MyBase.GetReportIDByName("report_2")
351
+ Else
352
+ Return MyBase.GetReportIDByName(fullReportName)
353
+ End If
354
+ End Function
355
+
356
+ 'Convert report GUID into report full name
357
+ Public Overrides Function GetReportNameById(id As String) As String
358
+ If (id = "report_1") Then
359
+ Return MyBase.GetReportNameById("report_2")
360
+ Else
361
+ Return MyBase.GetReportNameById(id)
362
+ End If
363
+ End Function
364
+
365
+ 'Method called after ReportSet was executed
366
+ Public Overrides Sub PostExecuteReportSet(reportSet As ReportSet)
367
+ reportSet.WriteXml()
368
+ End Sub
369
+
370
+ 'Method called after reportSet was loaded
371
+ Public Overrides Sub PostLoadReportSet(name As String, reportSet As ReportSet)
372
+
373
+ MyBase.PostLoadReportSet(name, reportSet)
374
+ End Sub
375
+
376
+ Public Overrides Sub PreLoadReportSet(name As String)
377
+ MyBase.PreLoadReportSet(name)
378
+ End Sub
379
+
380
+ 'Overrides the method of saving report in .rdl format
381
+ Public Overrides Sub SaveReportRDL(reportName As String)
382
+
383
+ 'Get file path
384
+ Dim rdlFilePath As String = "C:\\Reports\\RDL\\" + reportName + ".rdl"
385
+
386
+ 'Build rdl content
387
+ Dim builder As New StringBuilder()
388
+
389
+ Dim writer As New XmlTextWriter((New StringWriter(builder)))
390
+ Izenda.AdHoc.AdHocContext.CurrentReportSet.WriteRdl(writer)
391
+ writer.Flush()
392
+ 'Write content to file
393
+ File.WriteAllText(rdlFilePath, builder.ToString())
394
+ End Sub
395
+
396
+ 'Returns a list of reports to the reprt viewr and all report list dropdowns
397
+ Public Overrides Function ListReports() As ReportInfo()
398
+ Return New ReportInfo() {New ReportInfo("report 1"), New ReportInfo("report 2")}
399
+ End Function
400
+
401
+ 'Runs after report export to allow archiving
402
+ Public Overrides Sub ArchiveReportOutput(reportSet As ReportSet, _
403
+ emails As String(), _
404
+ extension As String, _
405
+ data As Byte())
406
+ 'save to archive
407
+ Using bw As New BinaryWriter(File.Open(reportSet.ReportName + "_sent", FileMode.Create))
408
+ bw.Write(data)
409
+ End Using
410
+ End Sub
411
+
412
+ 'This method overrides the default behavor of the Equals(...)
413
+ 'operators in the filters tab and report viewer.
414
+ 'If using Equals(...) with stored procedures, this is required.
415
+ Public Overrides Function ProcessEqualsSelectList(column As Column) As String()
416
+ If column.Name = "ParameterField" Then
417
+ Return New String() {"Value1", "Value2", "Value3"}
418
+ End If
419
+ Return MyBase.ProcessEqualsSelectList(column)
420
+ End Function
421
+
422
+ 'Control what operators are availabile for each field type in the Filters tab or report viewer
423
+ Public Overrides Function GetOperatorList(type As SqlType, isStoredProcedureUsed As Boolean) As String()
424
+ Dim result As String() = MyBase.GetOperatorList(type, isStoredProcedureUsed)
425
+ Dim cutResult(result.Length / 2) As String
426
+ Array.Copy(result, cutResult, CLng(result.Length / 2))
427
+ Return cutResult
428
+ End Function
429
+
430
+ 'Executes whenever an existing report is loaded or executed
431
+ Public Overrides Function LoadReportSet(reportName As String) As ReportSet
432
+ Dim rs As New ReportSet()
433
+ Using sr As New StreamReader(reportName + ".xml")
434
+ rs.ReadXml(sr.ReadToEnd())
435
+ End Using
436
+ Return rs
437
+ End Function
438
+
439
+ Public Overrides Sub SaveReportSet(reportName As String, reportSet As ReportSet)
440
+ Using sw As New StreamWriter(reportName + ".xml")
441
+ sw.Write(reportSet.WriteXml())
442
+ End Using
443
+ End Sub
444
+
445
+ Public Overrides Sub DeleteReportSet(reportName As String)
446
+ File.Delete(reportName + ".xml")
447
+ End Sub
448
+
449
+ 'Create new types of charts or customize existing styles
450
+ Public Overrides Sub CustomizeChart(chart As Object, properties As Hashtable)
451
+ If Not properties.ContainsKey("NoAA") Then
452
+ Return
453
+ End If
454
+ If CBool(properties("NoAA")) Then
455
+ DirectCast(chart, Dundas.Charting.WebControl.Chart).AntiAliasing = Dundas.Charting.WebControl.AntiAliasing.None
456
+ End If
457
+ End Sub
458
+
459
+ 'Create new types of charts or customize existing styles
460
+ Public Overrides Sub CustomizeChart(chart As Object)
461
+ DirectCast(chart, Dundas.Charting.WebControl.Chart).AntiAliasing = Dundas.Charting.WebControl.AntiAliasing.None
462
+ End Sub
463
+
464
+ 'Process exeptions in a custom manner
465
+ Public Overrides Function ProcessFriendlyException(exception As Exception) As Control
466
+ Return New LiteralControl("exception occurred " + exception.Message)
467
+ End Function
468
+
469
+ 'Add additional style elememnts to the guage
470
+ Public Overrides Function CustomizeGuage(value As Double, _
471
+ min As Double, _
472
+ max As Double, _
473
+ name As String, _
474
+ GuageImage As System.Drawing.Image) As System.Drawing.Image
475
+ GuageImage.Save("rendered_gauge.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
476
+ Return GuageImage
477
+ End Function
478
+
479
+ 'Dynamically modify the report before execution.
480
+ Public Overrides Sub PreExecuteReportSet(reportSet As ReportSet)
481
+ reportSet.Footer = DateTime.Now.ToString()
482
+ End Sub
483
+
484
+ 'Dynamically modify the results after they come back
485
+ 'from the database and before they are rendered
486
+ Public Overrides Sub ProcessDataSet(ds As DataSet, reportPart As String)
487
+ If reportPart = "Chart" Then
488
+ ds.Tables(0).Rows(0)(0) = "modified_data"
489
+ End If
490
+ End Sub
491
+End Class
492
+```
... ...
\ No newline at end of file