/// <summary> /// 利用处理器信息封装制造对象 /// </summary> /// <param name="useCommandPacker"></param> /// <returns></returns> private object CreatObjByHandlerInfo(HandlerInfoPacker useCommandPacker) { //加载目标程序集 var loadedAssembly = AssemblyLoadUtility.LoadAssembly(useCommandPacker.StrUseAssemblePath); //获取目标类 var useType = loadedAssembly.GetType(useCommandPacker.StrUseClassFullName); //调用无参方法创建对象 var tempCommandObj = Activator.CreateInstance(useType); return(tempCommandObj); }
/// <summary> /// 扩展机制扩展入口 /// </summary> /// <param name="commandData"></param> /// <param name="message"></param> /// <param name="elements"></param> /// <param name="useGuid"></param> /// <param name="useAssemblyLocation"></param> /// <param name="useClassFullName"></param> /// <returns></returns> public Result ExecuteByAppendValue(ExternalCommandData commandData, ref string message, ElementSet elements , string useGuid, string useAssemblyLocation, string useClassFullName) { //检查版本号 if (string.IsNullOrWhiteSpace(AssemblyLoadUtility.m_versionNum)) { AssemblyLoadUtility.m_versionNum = commandData.Application.Application.VersionNumber; } //检查命令是否被创建 if (!m_useCMDDic.ContainsKey(useGuid)) { HandlerInfoPacker tempUsePakcer = new HandlerInfoPacker(); tempUsePakcer.StrUseAddinId = useGuid; tempUsePakcer.StrUseAssemblePath = useAssemblyLocation; tempUsePakcer.StrUseClassFullName = useClassFullName; m_useCMDDic.Add(useGuid, tempUsePakcer); } //由id执行命令 return(InvokeById(commandData, ref message, elements, useGuid)); }
/// <summary> /// 准备类封装列表 /// </summary> /// <param name="useFileName"></param> /// <returns></returns> private List <HandlerInfoPacker> PrepareData(string useFileName) { List <HandlerInfoPacker> lstTempPacker = new List <HandlerInfoPacker>(); //加载配置文件 XmlDocument useXML = new XmlDocument(); useXML.Load(useFileName); //添加要删除文件 XmlNode root = useXML.DocumentElement; bool bIfDelete = false; bool.TryParse(root.Attributes[IFDELETEFILE].Value, out bIfDelete); if (bIfDelete) { m_lstDeleteFiles.Add(useFileName); } //收集处理器信息 foreach (XmlNode eachId in root.ChildNodes) { HandlerInfoPacker cmdPacker = new HandlerInfoPacker(); cmdPacker.StrUseAddinId = eachId.InnerText; cmdPacker.StrUseAssemblePath = eachId.Attributes[ASSEMBLEPATH].Value; cmdPacker.StrUseClassFullName = eachId.Attributes[CLASSFULLNAME].Value; //若文件不存在则跳过 if (!File.Exists(cmdPacker.StrUseAssemblePath)) { continue; } lstTempPacker.Add(cmdPacker); } return(lstTempPacker); }