/// <summary> /// 创建rdlc的Report /// </summary> /// <param name="documentName"></param> /// <returns></returns> public static string CreateMsReportFile(string documentName) { if (System.IO.File.Exists(documentName)) { return(documentName); } else { ResourceContent data = ResourceInfoHelper.ResolveResource(documentName, ResourceType.MsReport); if (data != null) { switch (data.Type) { case ResourceContentType.File: return(data.Content.ToString()); case ResourceContentType.Binary: string fileName = System.IO.Path.GetTempFileName(); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName, false)) { sw.Write(data); } return(fileName); default: throw new ArgumentException("Invalid Resource Content Type!"); } } else { throw new ArgumentException(string.Format("Can't find resouce of {0}!", documentName)); } } }
public static CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReportDocument(string documentName) { try { CrystalDecisions.CrystalReports.Engine.ReportDocument ret = Feng.Utils.ReflectionHelper.CreateInstanceFromName(documentName) as CrystalDecisions.CrystalReports.Engine.ReportDocument; if (ret != null) { return(ret); } } catch (Exception) { } ResourceContent res = ResourceInfoHelper.ResolveResource(documentName, ResourceType.Report); if (res != null) { switch (res.Type) { case ResourceContentType.File: { CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); reportDocument.Load(res.Content.ToString()); return(reportDocument); } case ResourceContentType.Binary: { byte[] data = (byte[])res.Content; string fileName = System.IO.Path.GetTempFileName(); using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create)) { fs.Write(data, 0, data.Length); } CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); reportDocument.Load(fileName); return(reportDocument); } default: throw new ArgumentException("Invalid Resource Content Type!"); } } else { throw new ArgumentException(string.Format("Can't find resouce of {0}!", documentName)); } }
public static System.Data.DataSet CreateDataset(string datasetName) { try { System.Data.DataSet ds = Feng.Utils.ReflectionHelper.CreateInstanceFromName(datasetName) as System.Data.DataSet; if (ds != null) { return(ds); } } catch (Exception) { } ResourceContent dataSetXmlSchema = ResourceInfoHelper.ResolveResource(datasetName, ResourceType.Dataset); if (dataSetXmlSchema != null) { switch (dataSetXmlSchema.Type) { case ResourceContentType.File: { System.Data.DataSet ds = new System.Data.DataSet(); using (System.IO.StreamReader sr = new System.IO.StreamReader(dataSetXmlSchema.Content.ToString())) { ds.ReadXmlSchema(sr); } return(ds); } case ResourceContentType.String: { System.Data.DataSet ds = new System.Data.DataSet(); using (System.IO.StringReader sr = new System.IO.StringReader(dataSetXmlSchema.Content.ToString())) { ds.ReadXmlSchema(sr); } return(ds); } default: throw new ArgumentException("Invalid Resource Content Type!"); } } else { throw new ArgumentException(string.Format("Can't find resouce of {0}!", datasetName)); } }
/// <summary> /// 执行Python。通过source和是否存在文件自动判别执行类型 /// 如果是文件(.py结尾) /// 首先在Script目录下寻找.py源文件名,再在数据库ResourceInfo中寻找 /// 再在Script目录下寻找单个.py编译成的同名Assembly。 /// 如果还找不到,则在工作目录下找"PythonScript.dll,执行对应方法。 /// 在.py文件中,执行的是execute方法(如果带当前窗口参数,参数是masterForm) /// 如果不是,则按照Statement执行。 /// </summary> /// <param name="source"></param> /// <param name="processParams"></param> /// <returns></returns> public static object TryExecutePython(string source, Dictionary <string, object> processParams) { try { if (source.EndsWith(".py", StringComparison.InvariantCulture)) { string filePath = ServiceProvider.GetService <IApplicationDirectory>().GetLocalResourcePath(source); if (System.IO.File.Exists(filePath)) { return(PythonHelper.ExecutePythonFile(filePath, processParams)); } else { ResourceContent pythonResource = ResourceInfoHelper.ResolveResource(source, ResourceType.PythonSource); if (pythonResource != null) { switch (pythonResource.Type) { case ResourceContentType.File: return(PythonHelper.ExecutePythonFile(pythonResource.Content.ToString(), processParams)); case ResourceContentType.String: return(PythonHelper.ExecutePythonStatement(pythonResource.Content.ToString(), processParams)); default: throw new NotSupportedException("Invalid Resource Content Type!"); } } else { string singleAssemblyPath = System.IO.Path.ChangeExtension(filePath, ".dll"); if (System.IO.File.Exists(singleAssemblyPath)) { return(PythonHelper.ExecutePythonAssembly(singleAssemblyPath, System.IO.Path.GetFileName(filePath), processParams)); } else { string combileAssemblyPath = System.IO.Path.Combine(ServiceProvider.GetService <IApplicationDirectory>().GetMainDirectory(), s_pythonCompiledAssembly); if (System.IO.File.Exists(combileAssemblyPath)) { return(PythonHelper.ExecutePythonAssembly(combileAssemblyPath, System.IO.Path.GetFileName(filePath), processParams)); } else { return(null); } } } } } else { if (source.Contains("result = ")) { return(PythonHelper.ExecutePythonStatement(source, processParams)); } else { return(PythonHelper.ExecutePythonExpression(source, processParams)); } } } catch (Exception ex) { throw new ArgumentException(string.Format("Python source {0} is invalid!", source), ex); } }