ModuleManagerWord格式.docx
- 文档编号:18163520
- 上传时间:2022-12-13
- 格式:DOCX
- 页数:13
- 大小:16.92KB
ModuleManagerWord格式.docx
《ModuleManagerWord格式.docx》由会员分享,可在线阅读,更多相关《ModuleManagerWord格式.docx(13页珍藏版)》请在冰豆网上搜索。
**/
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceHHTech.CSMMSS.Framework
{
publicenumModuleEventType
{
Added,
Removed,
Init,
Exit,
Start,
Stop,
}
///<
summary>
///模块管理器
/summary>
publicclassModuleManager:
ObjectBase,IModuleManager
publiceventModuleChangeProcModuleChanged;
publicModuleManager()
this.LoggerList=newList<
ILog>
();
///IModule是否实现了某个接口
typeparamname="
T"
>
<
/typeparam>
paramname="
m"
/param>
returns>
/returns>
boolIsImplementInterface<
T>
(IModulem)
Typet=typeof(T);
return(m.GetType().GetInterface(t.Name)!
=null);
///向管理器中添加模块
publicboolAdd(IModulem)
returnAdd(m,ModuleType.mtProper);
mt"
publicboolAdd(IModulem,ModuleTypemt)
if(m==null)
returnfalse;
if(this.moduleDict.ContainsKey(m.Name))
this.moduleDict[m.Name]=m;
if(mt==ModuleType.mtCommunal)monModuleList.Add(m);
else
this.moduleList.Add(m);
m.Manager=this;
if(this.ModuleChanged!
=null)
this.ModuleChanged(m,ModuleEventType.Added);
//日志接口
if(IsImplementInterface<
(m))
this.LoggerList.Add((ILog)m);
if(this.AlarmProces==null)
IAlarmProcess>
this.AlarmProces=(IAlarmProcess)m;
//配置接口
if(this.CfgManager==null)
IConfigManager>
this.CfgManager=(IConfigManager)m;
returntrue;
///从模块管理器中删除模块
publicboolRemove(IModulem)
m.Manager=null;
if(this.moduleDict.Remove(m.Name))
if(this.moduleList.Contains(m))this.moduleList.Remove(m);
if(monModuleList.Contains(m))monModuleList.Remove(m);
this.ModuleChanged(m,ModuleEventType.Removed);
this.LoggerList.Remove((ILog)m);
///从模块管理器中获取指定模块名称的模块
moduleName"
publicIModuleGetModule(stringmoduleName)
if(this.moduleDict.ContainsKey(moduleName))
returnthis.moduleDict[moduleName];
returnnull;
/////<
/////执行一命令
模块名<
paraNode"
参数<
resultNode"
返回结果<
是否执行成功<
//publicboolExcuteCommand(stringmoduleName,NodeparaNode,NoderesultNode)
//{
//if(this.moduleDict.ContainsKey(moduleName))
//returnthis.moduleDict[moduleName].ExcuteCommand(paraNode,resultNode);
//else
//returnfalse;
//}
publicList<
GetInterfaceFromModules<
()
returnGetInterfaceFromModules<
(true);
///从管理器所管理的所有模块里获得实现了某类具体接口的模块列表
(boolisFindInRefModuleList)
List<
list=newList<
foreach(IModuleiminthis.moduleList)
if(im.GetType().GetInterface(t.Name)!
if(im.IsInterfaceAvailable(t))
list.Add((T)im);
if(isFindInRefModuleList)
foreach(IModuleiminmonModuleList)
returnlist;
GetForbiddenInterfaceFromModules<
if(!
im.IsInterfaceAvailable(t))
publicTGetFirstInterfaceFromModules<
returnGetFirstInterfaceFromModules<
///从管理器所管理的所有模块里获得第一个实现了某类具体接口的模块
return(T)im;
returndefault(T);
///初始化所有模块
publicboolInitAllModules()
foreach(IModuleminthis.moduleList)
(misILog))
m.Init();
this.timerManager.Init();
///启动所有模块
publicboolStartAllModules()
(misILog))m.Start();
///停止所有模块
publicboolStopAllModules()
m.Stop();
///执行应用程序清理操作
publicvoidExitAllModules()
m.Exit();
this.timerManager.Close();
///注册定时器
timerName"
timerProc"
interval"
publicobjectRegisterTimer(stringtimerName,EventHandlertimerProc,intinterval)
returnthis.timerManager.Add(timerName,timerProc,interval);
///注销定时器
publicboolUnRegisterTimer(objecttimerObj)
returnthis.timerManager.Remove(timerObj);
///获得所有的模块列表
IModule>
GetAllModuleList()
mlist=newList<
mlist.Add(im);
returnmlist;
///获得所有模块名称列表
string>
GetAllModuleNames()
mlist.Add(im.Name);
publicvoidWriteLog(LogTypetype,LogLevellevel,stringlogMsg)
foreach(ILogloginthis.LoggerList)
log.WriteLine(type,level,"
ModuleManager"
logMsg);
///<
///模块字典,用来加快查找速度。
privatereadonlyDictionary<
string,IModule>
moduleDict=
newDictionary<
///模块链表,保证模块添加的顺序。
privatereadonlyList<
moduleList=newList<
///本模块管理器引用的模块列表。
commonModuleList=newList<
///定时管理器
privatereadonlyTimerManagertimerManager=newTimerManager();
///模块管理器所管理的具有日志接口的模块列表。
LoggerList{get;
privateset;
///配置管理接口,向各个模块提供配置信息。
publicIConfigManagerCfgManager{get;
set;
////addby雷风雷
///报警信息模块
publicIAlarmProcessAlarmProces{get;
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ModuleManager