using System; using System.Reflection; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using System.Web; using QMAPP.Common.Web.Models; using QMAPP.Common.Web.Controllers; namespace QMAPP.Common.Web.Util { /// /// 程序管理工具 /// public class ProgramHelper { #region 获取查询模块对应ViewModel类型 /// /// 获取查询模块对应ViewModel类型 /// /// 程序名 /// ViewModel类型 public Type GetProgramVMType(string programName) { string prgListName = System.Web.HttpContext.Current.Server.MapPath(HttpRuntime.AppDomainAppVirtualPath) + "App_Data\\ProgramList.xml"; string viewModel = ""; try { XElement xel = XElement.Load(prgListName); var datas = from x in xel.Descendants("Program") select x; foreach (XElement d in datas) { if (d.Attribute("ProgramName").Value == programName) { viewModel = d.Attribute("ViewModel").Value; break; } } if (viewModel == "") { throw new Exception("未对该程序模块进行相应配置。"); } //提取程序集信息 datas = from x in xel.Descendants("AssemblyInfo") select x; string assemblyFile = ""; if (datas!=null) { foreach (XElement d in datas) { assemblyFile = d.Attribute("AssemblyFile").Value; } } Assembly asse = Assembly.LoadFile(QController.PhysicsRootPath + @"bin\" + assemblyFile); Type t = asse.GetType(viewModel); return t; } catch (Exception ex) { throw new Exception("未对该程序模块进行相应配置。"); } } #endregion #region 获取查询条件定义 /// /// 获取查询模块对应ViewModel类型 /// /// 程序名 /// ViewModel类型 public string GetProgramWhereList(string programName) { string prgListName = System.Web.HttpContext.Current.Server.MapPath(HttpRuntime.AppDomainAppVirtualPath) + "App_Data\\ProgramList.xml"; string whereList = ""; try { XElement xel = XElement.Load(prgListName); var datas = from x in xel.Descendants("Program") select x; foreach (XElement d in datas) { if (d.Attribute("ProgramName").Value == programName) { if (d.Attribute("WhereList") != null) whereList = d.Attribute("WhereList").Value; break; } } if (whereList == "") { throw new Exception("未对该程序模块进行相应配置。"); } return whereList; } catch (Exception ex) { throw new Exception("未对该程序模块进行相应配置。"); } } #endregion } }