ModuleManager.docx

上传人:b****4 文档编号:5191694 上传时间:2022-12-13 格式:DOCX 页数:13 大小:16.92KB
下载 相关 举报
ModuleManager.docx_第1页
第1页 / 共13页
ModuleManager.docx_第2页
第2页 / 共13页
ModuleManager.docx_第3页
第3页 / 共13页
ModuleManager.docx_第4页
第4页 / 共13页
ModuleManager.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

ModuleManager.docx

《ModuleManager.docx》由会员分享,可在线阅读,更多相关《ModuleManager.docx(13页珍藏版)》请在冰豆网上搜索。

ModuleManager.docx

ModuleManager

ModuleManager.cs

/*

*Copyright(C)2010河南辉煌科技股份有限公司

*Allrightsreserved

*

*文件摘要:

定义CSM系统的模块模型

*

*当前版本:

1.0

*编写日期:

2010-09-14

*设计:

CSM&MSS框架设计组

*作者:

张鲲鹏

*

*修改记录:

2010-12-7雷风雷添加报警信息模块对象

*修改记录:

2010-12-13赵海东修改模块管理为公共及特有模块

**/

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

namespaceHHTech.CSMMSS.Framework

{

publicenumModuleEventType

{

Added,

Removed,

Init,

Exit,

Start,

Stop,

}

///

///模块管理器

///

publicclassModuleManager:

ObjectBase,IModuleManager

{

publiceventModuleChangeProcModuleChanged;

publicModuleManager()

{

this.LoggerList=newList();

}

///

///IModule是否实现了某个接口

///

///

///

///

boolIsImplementInterface(IModulem)

{

Typet=typeof(T);

return(m.GetType().GetInterface(t.Name)!

=null);

}

///

///向管理器中添加模块

///

///

///

publicboolAdd(IModulem)

{

returnAdd(m,ModuleType.mtProper);

}

///

///向管理器中添加模块

///

///

///

///

publicboolAdd(IModulem,ModuleTypemt)

{

if(m==null)

returnfalse;

if(this.moduleDict.ContainsKey(m.Name))

returnfalse;

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)

{

if(IsImplementInterface(m))

this.AlarmProces=(IAlarmProcess)m;

}

//配置接口

if(this.CfgManager==null)

{

if(IsImplementInterface(m))

this.CfgManager=(IConfigManager)m;

}

returntrue;

}

///

///从模块管理器中删除模块

///

///

///

publicboolRemove(IModulem)

{

if(m==null)

returnfalse;

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);

if(this.ModuleChanged!

=null)

this.ModuleChanged(m,ModuleEventType.Removed);

if(IsImplementInterface(m))

this.LoggerList.Remove((ILog)m);

returntrue;

}

returnfalse;

}

///

///从模块管理器中获取指定模块名称的模块

///

///

///

publicIModuleGetModule(stringmoduleName)

{

if(this.moduleDict.ContainsKey(moduleName))

returnthis.moduleDict[moduleName];

else

returnnull;

}

/////

/////执行一命令

/////

/////模块名

/////参数

/////返回结果

/////是否执行成功

//publicboolExcuteCommand(stringmoduleName,NodeparaNode,NoderesultNode)

//{

//if(this.moduleDict.ContainsKey(moduleName))

//returnthis.moduleDict[moduleName].ExcuteCommand(paraNode,resultNode);

//else

//returnfalse;

//}

publicListGetInterfaceFromModules()

{

returnGetInterfaceFromModules(true);

}

///

///从管理器所管理的所有模块里获得实现了某类具体接口的模块列表

///

///

///

publicListGetInterfaceFromModules(boolisFindInRefModuleList)

{

Listlist=newList();

Typet=typeof(T);

foreach(IModuleiminthis.moduleList)

{

if(im.GetType().GetInterface(t.Name)!

=null)

{

if(im.IsInterfaceAvailable(t))

{

list.Add((T)im);

}

}

}

if(isFindInRefModuleList)

{

foreach(IModuleiminmonModuleList)

{

if(im.GetType().GetInterface(t.Name)!

=null)

{

if(im.IsInterfaceAvailable(t))

{

list.Add((T)im);

}

}

}

}

returnlist;

}

///

///从管理器所管理的所有模块里获得实现了某类具体接口的模块列表

///

///

///

publicListGetForbiddenInterfaceFromModules()

{

Listlist=newList();

Typet=typeof(T);

foreach(IModuleiminthis.moduleList)

{

if(im.GetType().GetInterface(t.Name)!

=null)

{

if(!

im.IsInterfaceAvailable(t))

{

list.Add((T)im);

}

}

}

foreach(IModuleiminmonModuleList)

{

if(im.GetType().GetInterface(t.Name)!

=null)

{

if(!

im.IsInterfaceAvailable(t))

{

list.Add((T)im);

}

}

}

returnlist;

}

publicTGetFirstInterfaceFromModules()

{

returnGetFirstInterfaceFromModules(true);

}

///

///从管理器所管理的所有模块里获得第一个实现了某类具体接口的模块

///

///

///

publicTGetFirstInterfaceFromModules(boolisFindInRefModuleList)

{

Typet=typeof(T);

foreach(IModuleiminthis.moduleList)

{

if(im.GetType().GetInterface(t.Name)!

=null)

{

if(im.IsInterfaceAvailable(t))

{

return(T)im;

}

}

}

if(isFindInRefModuleList)

{

foreach(IModuleiminmonModuleList)

{

if(im.GetType().GetInterface(t.Name)!

=null)

{

if(im.IsInterfaceAvailable(t))

{

return(T)im;

}

}

}

}

returndefault(T);

}

 

///

///初始化所有模块

///

///

publicboolInitAllModules()

{

foreach(IModuleminthis.moduleList)

{

if(!

(misILog))

m.Init();

}

this.timerManager.Init();

returntrue;

}

///

///启动所有模块

///

///

publicboolStartAllModules()

{

foreach(IModuleminthis.moduleList)

{

if(!

(misILog))m.Start();

}

returntrue;

}

///

///停止所有模块

///

///

publicboolStopAllModules()

{

foreach(IModuleminthis.moduleList)

{

m.Stop();

}

returntrue;

}

///

///执行应用程序清理操作

///

publicvoidExitAllModules()

{

foreach(IModuleminthis.moduleList)

{

m.Exit();

}

this.timerManager.Close();

}

///

///注册定时器

///

///

///

///

///

publicobjectRegisterTimer(stringtimerName,EventHandlertimerProc,intinterval)

{

returnthis.timerManager.Add(timerName,timerProc,interval);

}

///

///注销定时器

///

///

///

publicboolUnRegisterTimer(objecttimerObj)

{

returnthis.timerManager.Remove(timerObj);

}

///

///获得所有的模块列表

///

///

publicListGetAllModuleList()

{

Listmlist=newList();

foreach(IModuleiminthis.moduleList)

mlist.Add(im);

foreach(IModuleiminmonModuleList)

mlist.Add(im);

returnmlist;

}

///

///获得所有模块名称列表

///

///

publicListGetAllModuleNames()

{

Listmlist=newList();

foreach(IModuleiminthis.moduleList)

mlist.Add(im.Name);

foreach(IModuleiminmonModuleList)

mlist.Add(im.Name);

returnmlist;

}

publicvoidWriteLog(LogTypetype,LogLevellevel,stringlogMsg)

{

foreach(ILogloginthis.LoggerList)

{

log.WriteLine(type,level,"ModuleManager",logMsg);

}

}

///

///模块字典,用来加快查找速度。

///

privatereadonlyDictionarymoduleDict=

newDictionary();

///

///模块链表,保证模块添加的顺序。

///

privatereadonlyListmoduleList=newList();

///

///本模块管理器引用的模块列表。

///

privatereadonlyListcommonModuleList=newList();

///

///定时管理器

///

privatereadonlyTimerManagertimerManager=newTimerManager();

///

///模块管理器所管理的具有日志接口的模块列表。

///

publicListLoggerList{get;privateset;}

///

///配置管理接口,向各个模块提供配置信息。

///

publicIConfigManagerCfgManager{get;set;}

////addby雷风雷

///

///报警信息模块

///

publicIAlarmProcessAlarmProces{get;set;}

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 其它模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1