Commit 64b5867884ee17abc5d7a33ba9adb1779a1a094b
1 parent
ef01ad2f
- egy-két felesleges lokális változó deklaráció törlése
Showing
3 changed files
with
66 additions
and
58 deletions
Show diff stats
Vrh.OneReport/Enums.cs
| ... | ... | @@ -20,11 +20,6 @@ namespace Vrh.OneReport |
| 20 | 20 | /// <summary> |
| 21 | 21 | /// IENumerable adattibpust visszaadó plugin |
| 22 | 22 | /// </summary> |
| 23 | - Plugin, | |
| 24 | - | |
| 25 | - /// <summary> | |
| 26 | - /// IENumerable adattibpust visszaadó plugin | |
| 27 | - /// </summary> | |
| 28 | 23 | DataPlugin, |
| 29 | 24 | |
| 30 | 25 | /// <summary> | ... | ... |
Vrh.OneReport/ReportService.cs
| ... | ... | @@ -764,30 +764,16 @@ namespace Vrh.OneReport |
| 764 | 764 | if (parameters != null && !parameters.AllKeys.Contains("SQLTEXT")) { parameters.Add("SQLTEXT", dataset.Command);} |
| 765 | 765 | break; |
| 766 | 766 | case DatasetTypes.SQLTextPlugin: |
| 767 | - if (dataset.Plugin != null) | |
| 768 | - { | |
| 769 | - dataset.Command = dataset.Plugin.GetSqlText(dataset.PluginViewName, dataset.ConnectionString, dataset.PluginAssemblyXml, dataset.DatasetXml, parameters); | |
| 770 | - } | |
| 771 | - else if (dataset.GetMethod != null) | |
| 772 | - { | |
| 773 | - dataset.Command = (string)dataset.GetMethod.Invoke(dataset.Plugin, new object[] { dataset.PluginViewName, dataset.ConnectionString, dataset.PluginAssemblyXml, dataset.DatasetXml, parameters }); | |
| 774 | - } | |
| 767 | + if (dataset.Plugin == null || dataset.GetMethod == null) { throw new Exception((dataset.Plugin == null?"Plugin object is null! ":"") + (dataset.GetMethod == null ? "Method object is null!" : "")); } | |
| 768 | + dataset.Command = (string)dataset.GetMethod.Invoke(dataset.Plugin, new object[] { dataset.PluginViewName, dataset.ConnectionString, dataset.PluginAssemblyXml, dataset.DatasetXml, parameters }); | |
| 775 | 769 | if (parameters == null) { } |
| 776 | 770 | else if (parameters.AllKeys.Contains("SQLTEXT")) { parameters["SQLTEXT"]=dataset.Command; } |
| 777 | 771 | else { parameters.Add("SQLTEXT", dataset.Command); } |
| 778 | 772 | newReportDataSource = new ReportDataSource(dataset.Name, LoadDataTable(dataset.Type, dataset.ConnectionString, dataset.Command)); |
| 779 | 773 | break; |
| 780 | 774 | case DatasetTypes.DataPlugin: |
| 781 | - IEnumerable<object> resultdata = null; | |
| 782 | - if (dataset.Plugin != null) | |
| 783 | - { | |
| 784 | - resultdata = (IEnumerable<object>)dataset.Plugin.GetData(dataset.PluginViewName, dataset.ConnectionString, dataset.PluginAssemblyXml, dataset.DatasetXml,parameters); | |
| 785 | - } | |
| 786 | - else if (dataset.GetMethod != null) | |
| 787 | - { | |
| 788 | - resultdata = (IEnumerable<object>)dataset.GetMethod.Invoke(dataset.Plugin, new object[] { dataset.PluginViewName, dataset.ConnectionString, dataset.PluginAssemblyXml, dataset.DatasetXml,parameters }); | |
| 789 | - } | |
| 790 | - var returndataList = resultdata.ToList(); | |
| 775 | + if (dataset.Plugin == null || dataset.GetMethod == null) { throw new Exception((dataset.Plugin == null ? "Plugin object is null! " : "") + (dataset.GetMethod == null ? "Method object is null!" : "")); } | |
| 776 | + var returndataList = ((IEnumerable<object>)dataset.GetMethod.Invoke(dataset.Plugin, new object[] { dataset.PluginViewName, dataset.ConnectionString, dataset.PluginAssemblyXml, dataset.DatasetXml, parameters })); //.ToList(); | |
| 791 | 777 | newReportDataSource = new ReportDataSource(dataset.Name, returndataList); |
| 792 | 778 | break; |
| 793 | 779 | default: break;//ide nem jöhet, mert már korábban kibukna |
| ... | ... | @@ -837,9 +823,7 @@ namespace Vrh.OneReport |
| 837 | 823 | ReportService.ExportSQLText(dataset.ConnectionString, dataset.Command, dataset.ExportFile, this.Report.Timeout.SqlQuery, allformat: this.Report.Formats.AllFormats); |
| 838 | 824 | break; |
| 839 | 825 | case DatasetTypes.DataPlugin: |
| 840 | - IEnumerable<object> resultdata = (IEnumerable<object>)(dataset.Plugin != null | |
| 841 | - ? dataset.Plugin.GetData(dataset.PluginViewName, dataset.ConnectionString, dataset.PluginAssemblyXml, dataset.DatasetXml, this.Report.Parameters) | |
| 842 | - : dataset.GetMethod.Invoke(dataset.Plugin, new object[] { dataset.PluginViewName, dataset.ConnectionString, dataset.PluginAssemblyXml, dataset.DatasetXml, this.Report.Parameters })); | |
| 826 | + var resultdata = (IEnumerable<object>)dataset.GetMethod.Invoke(dataset.Plugin, new object[] { dataset.PluginViewName, dataset.ConnectionString, dataset.PluginAssemblyXml, dataset.DatasetXml, this.Report.Parameters }); | |
| 843 | 827 | //TODO: ezt meg kell csinálni!!!! |
| 844 | 828 | ReportService.ExportSQLData(dataset.ConnectionString, resultdata, dataset.ExportFile, this.Report.Timeout.SqlQuery, allformat: this.Report.Formats.AllFormats); |
| 845 | 829 | break; | ... | ... |
Vrh.OneReport/XmlProcessing/Dataset.cs
| ... | ... | @@ -107,9 +107,14 @@ namespace Vrh.OneReport |
| 107 | 107 | public XElement DatasetXml { get; set; } |
| 108 | 108 | |
| 109 | 109 | /// <summary> |
| 110 | + /// DatasetTypes: SQL, Plugin, DataPlugin, SQLTextPlugin, | |
| 111 | + /// </summary> | |
| 112 | + public DatasetTypes DatasetType { get; set; } | |
| 113 | + | |
| 114 | + /// <summary> | |
| 110 | 115 | /// A riport adatait előállító plugin kerül ide bele |
| 111 | 116 | /// </summary> |
| 112 | - public IOneReport Plugin { get; set; } | |
| 117 | + public object Plugin { get; set; } | |
| 113 | 118 | |
| 114 | 119 | /// <summary> |
| 115 | 120 | /// A plugin-ban levő meghívandó metódus leírója |
| ... | ... | @@ -125,23 +130,22 @@ namespace Vrh.OneReport |
| 125 | 130 | /// <param name="reportid">A riport id-ja; exception üzenetben kerül CSAK felhasználásra</param> |
| 126 | 131 | /// <param name="datasetxelement">A "Dataset" elem.</param> |
| 127 | 132 | /// /// <param name="datasourcelist">Alapértelmezett adatok a plugin típusú működéshez</param> |
| 128 | - /// <param name="defaultconnectionstring">az alapértelmezett kapcsolat leíró arra az esetre, ha a datasetxml-ben nincs megadva</param> | |
| 129 | - public Dataset(string reportid,XElement datasetxelement,List<PluginDescriptor> datasourcelist,string defaultconnectionstring) | |
| 133 | + /// <param name="defaultconnectionstringstorename">az alapértelmezett kapcsolat leíró arra az esetre, ha a datasetxml-ben nincs megadva</param> | |
| 134 | + public Dataset(string reportid,XElement datasetxelement,List<PluginDescriptor> datasourcelist,string defaultconnectionstringstorename) | |
| 130 | 135 | { |
| 131 | 136 | if (datasetxelement != null) |
| 132 | 137 | { |
| 133 | 138 | this.Name = GetValue(AttributeNames.NAME, datasetxelement, "", true, true); |
| 134 | - var plugintype = GetEnumValue(datasetxelement.Attribute(AttributeNames.TYPE), DatasetTypes.DataPlugin); | |
| 135 | - IOneReport plugin; MethodInfo sqlgetmethod; | |
| 136 | - switch (plugintype) | |
| 139 | + this.DatasetType = GetEnumValue(datasetxelement.Attribute(AttributeNames.TYPE), DatasetTypes.DataPlugin); | |
| 140 | + switch (this.DatasetType) | |
| 137 | 141 | { |
| 138 | 142 | default: throw new ApplicationException($"Unknown Dataset type! Type:{this.Type}. Report Id:{reportid}."); |
| 139 | 143 | case DatasetTypes.SQL: |
| 140 | 144 | { |
| 141 | 145 | this.Type = DatasetTypes.SQL; |
| 142 | 146 | var connectionstringstorename = GetValue(AttributeNames.CONNECTIONSTRING, datasetxelement, (string)null); |
| 143 | - if (string.IsNullOrWhiteSpace(connectionstringstorename)) { connectionstringstorename = defaultconnectionstring;} | |
| 144 | - this.ConnectionString = ConnectionStringStore.Get(connectionstringstorename); | |
| 147 | + if (string.IsNullOrWhiteSpace(connectionstringstorename)) { connectionstringstorename = defaultconnectionstringstorename;} | |
| 148 | + this.ConnectionString = ConnectionStringStore.GetSQL(connectionstringstorename); | |
| 145 | 149 | this.Command = GetValue(datasetxelement, "", true, true); |
| 146 | 150 | break; |
| 147 | 151 | } |
| ... | ... | @@ -160,8 +164,7 @@ namespace Vrh.OneReport |
| 160 | 164 | this.PluginMethodName = plugindescriptor.PluginMethodName; |
| 161 | 165 | this.PluginViewName = GetValue(AttributeNames.PLUGINVIEWNAME, datasetxelement, (string)null); |
| 162 | 166 | if (string.IsNullOrWhiteSpace(this.PluginViewName)) { this.PluginViewName = this.Name; } |
| 163 | - LoadPlugin(this.PluginAssemblyPath, this.PluginTypeFullName, this.PluginMethodName, out plugin, out sqlgetmethod); | |
| 164 | - this.Plugin = plugin; | |
| 167 | + this.Plugin = GetPlugin(this.DatasetType, this.PluginAssemblyPath, this.PluginTypeFullName, this.PluginMethodName, new object[] { this.ConnectionString }, out MethodInfo sqlgetmethod); | |
| 165 | 168 | this.GetMethod = sqlgetmethod; |
| 166 | 169 | this.DatasetXml = datasetxelement; |
| 167 | 170 | break; |
| ... | ... | @@ -169,39 +172,65 @@ namespace Vrh.OneReport |
| 169 | 172 | } |
| 170 | 173 | } |
| 171 | 174 | } |
| 172 | - private void LoadPlugin(string assemblypath, string plugintypename, string pluginmethodname, out IOneReport plugin, out MethodInfo getsqlmethod) | |
| 175 | + private object GetPlugin(DatasetTypes datasettype, string assemblypath, string plugintypename, string pluginmethodname, object[] plugintypeconstructorparameters, out MethodInfo getmethod) | |
| 173 | 176 | { |
| 174 | 177 | try |
| 175 | 178 | { |
| 176 | - plugin = null; | |
| 177 | - getsqlmethod = null; | |
| 179 | + object plugin = null; | |
| 180 | + getmethod = null; | |
| 178 | 181 | //Assembly asm = Assembly.LoadFile(assemblypath); |
| 179 | 182 | Assembly asm = Assembly.LoadFrom(assemblypath); |
| 180 | - if (!string.IsNullOrWhiteSpace(plugintypename)) | |
| 181 | - { | |
| 182 | - System.Type type = asm.GetExportedTypes().FirstOrDefault(x => x.FullName == plugintypename && x.IsAssignableFrom(x)); | |
| 183 | - if (type == null) { throw new ApplicationException(""); } | |
| 184 | - if (string.IsNullOrWhiteSpace(pluginmethodname)) { pluginmethodname = nameof(IOneReport.GetSqlText); } | |
| 185 | - getsqlmethod = type.GetMethod(pluginmethodname); | |
| 186 | - if (getsqlmethod == null) { throw new ApplicationException(""); } | |
| 187 | - plugin = null; | |
| 188 | - } | |
| 189 | - else | |
| 190 | - { | |
| 191 | - plugintypename = typeof(IOneReport).FullName; | |
| 192 | - pluginmethodname = nameof(IOneReport.GetSqlText); | |
| 193 | - System.Type type = asm.GetExportedTypes().FirstOrDefault(x => typeof(IOneReport).IsAssignableFrom(x)); | |
| 194 | - if (type == null) { throw new ApplicationException(""); } | |
| 195 | - getsqlmethod = null; | |
| 196 | - plugin = (IOneReport)Activator.CreateInstance(type); | |
| 197 | - } | |
| 183 | + if (string.IsNullOrWhiteSpace(plugintypename)) plugintypename = typeof(IOneReport).FullName; | |
| 184 | + if (string.IsNullOrWhiteSpace(pluginmethodname)) pluginmethodname = datasettype == DatasetTypes.DataPlugin ? nameof(IOneReport.GetData) : datasettype == DatasetTypes.SQLTextPlugin ? nameof(IOneReport.GetSqlText) : null; | |
| 185 | + | |
| 186 | + var ptype = asm.GetExportedTypes().FirstOrDefault(x => x.FullName == plugintypename && x.IsAssignableFrom(x)); | |
| 187 | + if (ptype == null) { throw new ApplicationException("Type not found!"); } | |
| 188 | + plugin = Activator.CreateInstance(ptype, plugintypeconstructorparameters); | |
| 189 | + if (plugin == null) { throw new ApplicationException("Type constructor failed!"); } | |
| 190 | + getmethod = ptype.GetMethod(pluginmethodname); | |
| 191 | + if (getmethod == null) { throw new ApplicationException("Method not found!"); } | |
| 192 | + return plugin; | |
| 198 | 193 | } |
| 199 | 194 | catch (Exception ex) |
| 200 | 195 | { |
| 201 | 196 | if (string.IsNullOrWhiteSpace(pluginmethodname)) { pluginmethodname = nameof(IOneReport.GetSqlText); } |
| 202 | - throw new ApplicationException($"The implementation of the referred interface or method in the assembly, or the assembly (DLL) itself was not found! Assembly='{this.PluginAssemblyPath}', type='{plugintypename}',method='{pluginmethodname}'", ex); | |
| 197 | + throw new ApplicationException($"ERROR Not found!!! the implementation of the referred interface or method in the assembly! Assembly='{this.PluginAssemblyPath}', type='{plugintypename}',method='{pluginmethodname}'", ex); | |
| 198 | + return null; | |
| 203 | 199 | } |
| 204 | 200 | } |
| 201 | + //private void LoadPluginBAK(string assemblypath, string plugintypename, string pluginmethodname, out IOneReport plugin, out MethodInfo getsqlmethod) | |
| 202 | + //{ | |
| 203 | + // try | |
| 204 | + // { | |
| 205 | + // plugin = null; | |
| 206 | + // getsqlmethod = null; | |
| 207 | + // //Assembly asm = Assembly.LoadFile(assemblypath); | |
| 208 | + // Assembly asm = Assembly.LoadFrom(assemblypath); | |
| 209 | + // if (!string.IsNullOrWhiteSpace(plugintypename)) | |
| 210 | + // { | |
| 211 | + // System.Type type = asm.GetExportedTypes().FirstOrDefault(x => x.FullName == plugintypename && x.IsAssignableFrom(x)); | |
| 212 | + // if (type == null) { throw new ApplicationException(""); } | |
| 213 | + // plugin = (IOneReport)Activator.CreateInstance(type); | |
| 214 | + // if (string.IsNullOrWhiteSpace(pluginmethodname)) { pluginmethodname = nameof(IOneReport.GetSqlText); } | |
| 215 | + // getsqlmethod = type.GetMethod(pluginmethodname); | |
| 216 | + // if (getsqlmethod == null) { throw new ApplicationException(""); } | |
| 217 | + // } | |
| 218 | + // else | |
| 219 | + // { | |
| 220 | + // plugintypename = typeof(IOneReport).FullName; | |
| 221 | + // pluginmethodname = nameof(IOneReport.GetSqlText); | |
| 222 | + // System.Type type = asm.GetExportedTypes().FirstOrDefault(x => typeof(IOneReport).IsAssignableFrom(x)); | |
| 223 | + // if (type == null) { throw new ApplicationException(""); } | |
| 224 | + // getsqlmethod = null; | |
| 225 | + // plugin = (IOneReport)Activator.CreateInstance(type); | |
| 226 | + // } | |
| 227 | + // } | |
| 228 | + // catch (Exception ex) | |
| 229 | + // { | |
| 230 | + // if (string.IsNullOrWhiteSpace(pluginmethodname)) { pluginmethodname = nameof(IOneReport.GetSqlText); } | |
| 231 | + // throw new ApplicationException($"The implementation of the referred interface or method in the assembly, or the assembly (DLL) itself was not found! Assembly='{this.PluginAssemblyPath}', type='{plugintypename}',method='{pluginmethodname}'", ex); | |
| 232 | + // } | |
| 233 | + //} | |
| 205 | 234 | #endregion Constructor |
| 206 | 235 | } |
| 207 | 236 | } | ... | ... |