RFID会议签到系统总结(十四)――管控端业务模块的加载

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

从上面我们知道现在管控端不再是一个孤零零的应用程序,而是由一些模块组成的,这些模块可能会根据不同情况有各种的组合,这样程序中就不能把模块写死了,而是得动态加载,反射又要派上用场了。

本来想如一些应用一样把业务模块当成是一个个的插件,然后把相应程序集放入类似于Plugins的目录,程序启动时到相应目录去寻找相应程序集这样的机制来加载的。但考虑到业务模块不会很多,引用的程序集也不会很复杂,可以预见以后也不会增加很多,为了简便起见,现把所有的程序集都放在应用程序根目录下。虽然可能会发生版本冲突之类的问题,但对于一个相对简单的应用来讲应该是合适的。

 

这里的东西其实没什么新意,整个做法跟前面硬件访问是如出一辙的。首先所有可被管控端加载的业务模块要实现如下的接口:

ContractedBlock.gifExpandedBlockStart.gif业务模块接口
None.gif      public interface IService
None.gif
ExpandedBlockStart.gifContractedBlock.gif      
dot.gif{     
InBlock.gif
InBlock.gif             
string Name
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif             
dot.gif{
InBlock.gif
InBlock.gif                    
getset;
InBlock.gif
ExpandedSubBlockEnd.gif             }

InBlock.gif
InBlock.gif 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif             
/**//// 主应用窗体相关内容
InBlock.gif
InBlock.gif             ServiceContext Context
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif             
dot.gif{
InBlock.gif
InBlock.gif                    
getset;
InBlock.gif
ExpandedSubBlockEnd.gif             }

InBlock.gif
InBlock.gif 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif             
/**//// 加载菜单、工具栏
InBlock.gif
InBlock.gif             
void LoadCommand();
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif             
/**//// 初始化工作
InBlock.gif
InBlock.gif             
void Initialize();
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif             
/**//// 服务终止工作
InBlock.gif
InBlock.gif             
void Finalize();
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif             
/**//// 注册可以让HOST调用的方法
InBlock.gif
InBlock.gif             
void RegisterMethod(Hashtable methodDictionary);
InBlock.gif
ExpandedBlockEnd.gif      }

None.gif
None.gif


Context:这里主要就是存放各个业务模块加载时需要的主程序的菜单、工具栏。

LoadCommand:加载这个业务模块所具有的菜单、工具栏,具体做法下面几篇会讲到。

InitializeFinalize:加载模块时除菜单、工具栏外其他一些需要的工作可以在这里完成。比如签到控制模块,通讯端口的开启与关闭。

RegisterMothod:业务模块对于主程序来讲是不可知的,这里可以注册一些方法让主程序调用到它的方法。这是后来加的功能,没有设计好,用了一个Hashtable来存放各个模块的方法委托,好在用得上的地方不是很多。

 

再来看一下配置:

    <Services>

       <Service Order="1" Name="SignInService" Startup="BCSMService.SignInSrv.SignInRunner,SignInSrv" />

       <Service ...... />

       <Service ...... />

    </Services>

 

应用上面的配置加载,

ContractedBlock.gifExpandedBlockStart.gif模块加载
None.gif             public ServiceManager(BCSMServer.frmMain host)
None.gif
ExpandedBlockStart.gifContractedBlock.gif             
dot.gif{
InBlock.gif
InBlock.gif                    ServiceCfg svCfg 
= System.Configuration.ConfigurationSettings.GetConfig("Services"as ServiceCfg;
InBlock.gif
InBlock.gif                    list 
= new Services();
InBlock.gif
InBlock.gif                    
if (svCfg != null)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif
InBlock.gif                           Type svType;
InBlock.gif
InBlock.gif                           
object objService;
InBlock.gif
InBlock.gif                           BindingFlags bf 
= BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance;
InBlock.gif
InBlock.gif                           ServiceContext scontext 
= new ServiceContext();
InBlock.gif
InBlock.gif                           scontext.Owner 
= host;
InBlock.gif
InBlock.gif                           scontext.OwnerMenu 
= host.mnuMain;
InBlock.gif
InBlock.gif                           scontext.OwnerTool 
= host.tbarMain;
InBlock.gif
InBlock.gif                           scontext.OwnerPanel 
= host.pnlMain;
InBlock.gif
InBlock.gif                           scontext.OwnerPrgBar 
= host.PrgBar;
InBlock.gif
InBlock.gif                           scontext.OtherMethods 
= host.ServiceMethods;
InBlock.gif
InBlock.gif 
InBlock.gif
InBlock.gif                           
for (int i = 0;i < svCfg.SvList.Count;i++)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                           
dot.gif{
InBlock.gif
InBlock.gif                                  
try
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                  
dot.gif{
InBlock.gif
InBlock.gif                                         svType 
= Type.GetType(svCfg.SvList[i].StartupType);
InBlock.gif
InBlock.gif                                         objService 
= svType.InvokeMember(null,bf,null,null,null);
InBlock.gif
InBlock.gif                                         IService service 
= objService as IService;
InBlock.gif
InBlock.gif                                         
if (service != null)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                         
dot.gif{
InBlock.gif
InBlock.gif                                                service.Name 
= svCfg.SvList[i].Name;
InBlock.gif
InBlock.gif                                                service.Context 
=scontext;
InBlock.gif
InBlock.gif                                                service.RegisterMethod(scontext.OtherMethods);
InBlock.gif
InBlock.gif 
InBlock.gif
InBlock.gif                                                list.Add(service);
InBlock.gif
ExpandedSubBlockEnd.gif                                         }

InBlock.gif
ExpandedSubBlockEnd.gif                                  }

InBlock.gif
InBlock.gif                                  
catch(Exception e)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                  
dot.gif{
InBlock.gif
InBlock.gif                                         frmMain.logNet.Error(
"获取服务时出错--" + e.Message);                               
InBlock.gif
ExpandedSubBlockEnd.gif                                  }

InBlock.gif
ExpandedSubBlockEnd.gif                           }

InBlock.gif
ExpandedSubBlockEnd.gif                    }

InBlock.gif
ExpandedBlockEnd.gif             }

None.gif
None.gif


 

基本的架子就这样,细节方面以后再讲。

转载于:https://www.cnblogs.com/lichdr/archive/2007/07/10/812484.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值