当前位置:编程学习 > asp >>

.NET应用加载容器KGlue

当在更新应用的时候是否碰到以下烦琐的工作[停址服务-更新服务-启动服务];的确由于文件被程序占用所以在更新文件的时候必须把程序停止,更新完成后又手动启动.而KGlue就是为了解决以上问题而出现的,它的主要作用是使用appDomain来加载运行每个配置的应用;监控相关应用文件变化自动对应用进行卸载和重启动的服务功能.简单而言在更新应用的时候直接替换文件后,KGlue就会对程序进行重新加载.

使用配置
KGlue可以配置多应用程序,应用程序可以存放在KGlue能访问的任意目录下.只需要简单地在配置文件中添加相关应用目录即可.

  <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="appSection" type="KGlue.AppSection, KGlue"/>
  </configSections>
  <appSection xmlns="urn:KGlue">
     <items>
      <add name="test" path="test" args="henry fan"/>
      <add name="tcpserver" path="tcp" />
      <add name="config" path="config" />
      <add name="chatroom" path="websocket_chatroom"/>
    </items>
  </appSection>
</configuration>
以上配置文件描述了4个应用,path是应用对应的目录,如果不指定全路径则是KGlue运行目录下的子目录,args参数是启动应用所需要的参数,可以为空值.KGlue会根据每个配置分别启用新的appdomain来运行它们.

应用加载规则
KGlue支持加载DLL或代码(cs,vb),所以在发布的时候只需要提供DLL或代码文件即可.由于应用启动需要一个规则定义,所以相应的类实现KGlue.IAppAdapter即可以;KGlue会遍历配置目录下的所有DLL或代码文件在域创建后实例化所有IAppAdapter对类并调用.

 
  public class Class1:KGlue.IAppAdapter
{
    public void Start(string[] args)
    {
        Console.WriteLine(args.Length);
        foreach (string item in args)
        {
            Console.WriteLine(item);
        }
 
    }
 
    public string Name
    {
        get { return "Class1"; }
    }
 
    public void Stop()
    {
         
    }
}
以上是一个简单的应用,把启动参数输出.把应该文件保存到相应的目录(别忘在把KGlue.dll也放到该目录下)下并配置一下KGlue的配置文件.

 
 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="appSection" type="KGlue.AppSection, KGlue"/>
  </configSections>
  <appSection xmlns="urn:KGlue">
     <items>
      <add name="test" path="d:\test" args="henry fan"/>
    </items>
  </appSection>
</configuration>

补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,