/// <summary> /// 注册一个新模块 /// </summary> /// <param name="name">模块名</param> /// <param name="filePath">需要注册的文件名</param> /// <param name="description">描述信息</param> /// <param name="moduleType">模块类型</param> /// <param name="groupTitle">组名</param> /// <param name="logObj">日志对象</param> /// <param name="windowContainer">窗口容器</param> /// <returns></returns> public static List <FormInfo> RegisterExe(String name, String filePath, String description, ModuleTypeEnum moduleType, String groupTitle, IOutput logObj, IWindowContainer windowContainer) { try { if (ExistName(name)) { throw new Exception($"存在重复的模块名:{name}"); } if (ExistPath(filePath)) { throw new Exception($"存在重复的模块加载:{filePath}"); } var moduleInfo = new ModuleInfo() { Name = name, ModulePath = filePath, ModuleType = moduleType, Description = description, GroupTitle = groupTitle }; var result = LoadExeModule(moduleInfo, groupTitle, logObj, windowContainer); // 添加到数据库 var dal = new ModuleInfoDAL(); dal.Insert(moduleInfo); return(result); } catch (Exception e1) { throw e1; } }
/// <summary> /// 删除模块 /// </summary> /// <param name="deleteModuleList">待删除的模块列表</param> public static void DeleteModule(List <AssemblyInfo> deleteModuleList) { lock (lockObj) { moduleInfos.RemoveAll(tmp1 => deleteModuleList.Any(tmp2 => tmp2 == tmp1)); foreach (var item in deleteModuleList) { var dal = new ModuleInfoDAL(); dal.Delete(item.ModuleInfo.Name); } } }
/// <summary> /// 初始化 /// </summary> public static void Init(IOutput logObj, IWindowContainer windowContainer) { var dal = new ModuleInfoDAL(); var moduleList = dal.FindAll(); foreach (var item in moduleList) { try { if (item.ModuleType == ModuleTypeEnum.DllModule) { LoadDllModule(item, logObj, windowContainer); } else if (item.ModuleType == ModuleTypeEnum.ExeModule) { LoadExeModule(item, item.GroupTitle, logObj, windowContainer); } } catch (Exception e1) { logObj.PrintLine($"模块加载出错 ModuleName:{item.Name} ModulePath:{item.ModulePath} Message:{e1.Message}"); } } }