14c2e16dab0da88fed5b006241b69c898cf8cc15
FAQ/LoadReportSet.md
| ... | ... | @@ -11,44 +11,65 @@ This method controls how the CurrentReportSet object is loaded into the applicat |
| 11 | 11 | ###DatabaseAdHocConfig Mode |
| 12 | 12 | |
| 13 | 13 | ```csharp |
| 14 | - // Method called after reportSet was loaded |
|
| 15 | - public override Izenda.AdHoc.ReportSet LoadReportSet(string reportName) { |
|
| 16 | - /* BEGIN Database Mode Code Sample */ |
|
| 17 | - string sql = string.Format("SELECT Xml FROM {0} WHERE Name = '{1}'", AdHocSettings.SavedReportsTable, reportName); |
|
| 18 | - object oXml = Izenda.AdHoc.AdHocContext.Driver.GetScalar(sql); |
|
| 19 | - if (oXml != DBNull.Value && oXml != null) { |
|
| 20 | - Izenda.AdHoc.ReportSet reportSet = new Izenda.AdHoc.ReportSet(); |
|
| 21 | - reportSet.ReadXml(oXml.ToString()); |
|
| 22 | - return reportSet; |
|
| 14 | + public override ReportSet LoadReportSet(string reportName) |
|
| 15 | + { |
|
| 16 | + try |
|
| 17 | + { |
|
| 18 | + string connectionString = @"Persist Security Info=False;Initial Catalog=Northwind;Data Source=LESHA-PC\SQL2012;User ID=dataLogin;Password=dataPassword;Integrated Security=false;"; |
|
| 19 | + string sql = string.Format("SELECT Xml FROM {0} WHERE Name = '{1}'", AdHocSettings.SavedReportsTable, reportName); |
|
| 20 | + using (System.Data.IDbConnection connection = new System.Data.SqlClient.SqlConnection(connectionString)) |
|
| 21 | + { |
|
| 22 | + connection.Open(); |
|
| 23 | + using (System.Data.IDbCommand command = connection.CreateCommand()) |
|
| 24 | + { |
|
| 25 | + command.CommandText = sql; |
|
| 26 | + using (System.Data.IDataReader reader = command.ExecuteReader()) |
|
| 27 | + { |
|
| 28 | + if (reader.Read()) |
|
| 29 | + { |
|
| 30 | + ReportSet reportSet = new ReportSet(); |
|
| 31 | + reportSet.ReadXml(reader["Xml"].ToString()); |
|
| 32 | + reportSet.OwnerTenantID = new string[] { "_global_" }; |
|
| 33 | + return reportSet; |
|
| 34 | + } |
|
| 35 | + else |
|
| 36 | + return null; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + catch |
|
| 42 | + { |
|
| 23 | 43 | } |
| 24 | 44 | return null; |
| 25 | 45 | } |
| 26 | - /* END Database Mode Code Sample */ |
|
| 27 | 46 | ``` |
| 28 | 47 | |
| 29 | 48 | ###FileSystemAdHocConfig Mode |
| 30 | 49 | |
| 31 | 50 | ```csharp |
| 32 | - // Method called after reportSet was loaded |
|
| 33 | - public override Izenda.AdHoc.ReportSet LoadReportSet(string reportName) { |
|
| 34 | - /* BEGIN Filesystem Mode Code Sample */ |
|
| 35 | - string fileName = GetFileName(reportName); |
|
| 36 | - if (fileName == null) |
|
| 51 | + public override ReportSet LoadReportSet(string reportName) |
|
| 52 | + { |
|
| 53 | + string fileName = System.IO.Path.GetFullPath(System.IO.Path.Combine(ReportPath, reportName + ".xml")); |
|
| 54 | + if (!fileName.StartsWith(ReportPath, StringComparison.InvariantCultureIgnoreCase)) |
|
| 37 | 55 | return null; |
| 38 | - |
|
| 39 | - FileInfo file = new FileInfo(fileName); |
|
| 56 | + System.IO.FileInfo file = new System.IO.FileInfo(fileName); |
|
| 40 | 57 | if (!file.Exists) |
| 41 | 58 | return null; |
| 42 | - |
|
| 43 | - StreamReader reader = file.OpenText(); |
|
| 59 | + System.IO.StreamReader reader = file.OpenText(); |
|
| 44 | 60 | string xml = reader.ReadToEnd(); |
| 45 | 61 | reader.Close(); |
| 46 | - |
|
| 47 | 62 | ReportSet reportSet = new ReportSet(); |
| 48 | - reportSet.ReadXml(xml); |
|
| 63 | + try |
|
| 64 | + { |
|
| 65 | + reportSet.ReadXml(xml); |
|
| 66 | + } |
|
| 67 | + catch |
|
| 68 | + { |
|
| 69 | + return null; |
|
| 70 | + } |
|
| 71 | + reportSet.OwnerTenantID = new string[] { "_global_" }; |
|
| 49 | 72 | return reportSet; |
| 50 | - |
|
| 51 | - /* END Filesystem Mode Code Sample */ |
|
| 52 | 73 | } |
| 53 | 74 | ``` |
| 54 | 75 | |
| ... | ... | @@ -58,40 +79,59 @@ This method controls how the CurrentReportSet object is loaded into the applicat |
| 58 | 79 | |
| 59 | 80 | ```visualbasic |
| 60 | 81 | Public Overrides Function LoadReportSet(reportName As String) As ReportSet |
| 61 | - 'BEGIN Database Mode Code Sample |
|
| 62 | - Dim sql As String = String.Format("SELECT Xml FROM {0} WHERE Name = '{1}'", AdHocSettings.SavedReportsTable, reportName) |
|
| 63 | - Dim oXml As Object = Izenda.AdHoc.AdHocContext.Driver.GetScalar(sql) |
|
| 64 | - If oXml IsNot DBNull.Value AndAlso oXml IsNot Nothing Then |
|
| 65 | - Dim ReportSet As ReportSet = New Izenda.AdHoc.ReportSet() |
|
| 66 | - ReportSet.ReadXml(oXml.ToString()) |
|
| 67 | - Return ReportSet |
|
| 68 | - End If |
|
| 82 | + Try |
|
| 83 | + Dim connectionString As String = "Persist Security Info=False;Initial Catalog=Northwind;Data Source=LESHA-PC\SQL2012;User ID=dataLogin;Password=dataPassword;Integrated Security=false;" |
|
| 84 | + Dim sql As String = String.Format("SELECT Xml FROM {0} WHERE Name = '{1}'", AdHocSettings.SavedReportsTable, reportName) |
|
| 85 | + Using connection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString) |
|
| 86 | + connection.Open() |
|
| 87 | + Using command As System.Data.IDbCommand = connection.CreateCommand() |
|
| 88 | + command.CommandText = sql |
|
| 89 | + Using reader As System.Data.IDataReader = command.ExecuteReader() |
|
| 90 | + If reader.Read() Then |
|
| 91 | + Dim reportSet As ReportSet = New ReportSet |
|
| 92 | + reportSet.ReadXml(reader("Xml").ToString()) |
|
| 93 | + Dim owners(0) As String |
|
| 94 | + owners(0) = "_global_" |
|
| 95 | + reportSet.OwnerTenantID = owners |
|
| 96 | + Return reportSet |
|
| 97 | + Else |
|
| 98 | + Return Nothing |
|
| 99 | + End If |
|
| 100 | + End Using |
|
| 101 | + End Using |
|
| 102 | + End Using |
|
| 103 | + Catch ex As Exception |
|
| 104 | + End Try |
|
| 69 | 105 | Return Nothing |
| 70 | - 'END Database Mode Code Sample |
|
| 71 | -End Function |
|
| 106 | + End Function |
|
| 72 | 107 | ``` |
| 73 | 108 | |
| 74 | 109 | ###FileSystemAdHocConfig Mode |
| 75 | 110 | |
| 76 | 111 | ```visualbasic |
| 77 | 112 | Public Overrides Function LoadReportSet(reportName As String) As ReportSet |
| 78 | - ' BEGIN Filesystem Mode Code Sample |
|
| 79 | - Dim fileName As String = GetFileName(reportName) 'your method to get |
|
| 80 | - If fileName = Nothing Then Return Nothing |
|
| 81 | - |
|
| 82 | - Dim file As FileInfo = New FileInfo(fileName) |
|
| 83 | - If Not file.Exists Then Return Nothing |
|
| 84 | - |
|
| 85 | - Dim reader As StreamReader = file.OpenText() |
|
| 113 | + Dim fileName As String = System.IO.Path.GetFullPath(System.IO.Path.Combine(ReportPath, reportName + ".xml")) |
|
| 114 | + If Not (fileName.StartsWith(ReportPath, StringComparison.InvariantCultureIgnoreCase)) Then |
|
| 115 | + Return Nothing |
|
| 116 | + End If |
|
| 117 | + Dim file As System.IO.FileInfo = New System.IO.FileInfo(fileName) |
|
| 118 | + If Not (file.Exists) Then |
|
| 119 | + Return Nothing |
|
| 120 | + End If |
|
| 121 | + Dim reader As System.IO.StreamReader = file.OpenText() |
|
| 86 | 122 | Dim xml As String = reader.ReadToEnd() |
| 87 | 123 | reader.Close() |
| 88 | - |
|
| 89 | - Dim reportSet As New ReportSet() |
|
| 90 | - reportSet.ReadXml(xml) |
|
| 124 | + Dim reportSet As ReportSet = New ReportSet() |
|
| 125 | + Try |
|
| 126 | + reportSet.ReadXml(xml) |
|
| 127 | + Catch ex As Exception |
|
| 128 | + Return Nothing |
|
| 129 | + End Try |
|
| 130 | + Dim owners(0) As String |
|
| 131 | + owners(0) = "_global_" |
|
| 132 | + reportSet.OwnerTenantID = owners |
|
| 91 | 133 | Return reportSet |
| 92 | - |
|
| 93 | - ' END Filesystem Mode Code Sample |
|
| 94 | -End Function |
|
| 134 | + End Function |
|
| 95 | 135 | ``` |
| 96 | 136 | |
| 97 | 137 | ##Logging Loading Exceptions |