///配置文件自定管理類///開發(fā)者:歐元寒玟///開發(fā)時間:" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

CWF框架之ConfigManager,讓“config”為您服務(wù)

系統(tǒng) 2151 0

這個框架用來解決自己的配置問題,為整個CWF框架的底層服務(wù)構(gòu)架,他為上面的數(shù)據(jù)持久和緩存或者其它服務(wù)提供配置信息.

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Xml;
namespace CWF.ConfigManager
{
??? /// <summary>
??? /// 配置文件自定管理類
??? /// 開發(fā)者:歐元寒玟
??? /// 開發(fā)時間:2010.02.05
??? /// 最后修改時間:2010.02.05
??? /// </summary>
??? public class ConfigManagerHander:IConfigurationSectionHandler??
??? {
??????? #region IConfigurationSectionHandler 成員
??????? /// <summary>
??????? /// 實現(xiàn)接口的方法處理xml入口
??????? /// </summary>
??????? /// <param name="parent"></param>
??????? /// <param name="configContext"></param>
??????? /// <param name="section"></param>
??????? /// <returns></returns>
??????? public object Create(object parent, object configContext, System.Xml.XmlNode section)
??????? {
??????????? return new ConfigManager(section);
??????? }

??????? #endregion
??? }
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Reflection ;
namespace CWF.ConfigManager
{
??? /// <summary>
??? /// 實現(xiàn)配置文件處理的主要類
??? /// 開發(fā)者:歐元寒玟
??? /// 開發(fā)時間:2010.02.05
??? /// 最后修改時間:2010.02.05
??? /// </summary>
??? public? class ConfigManager
??? {
??????? /// <summary>
??????? /// 配置文件根節(jié)點
??????? /// </summary>
??????? private XmlNode section;
??????? /// <summary>
??????? /// 實例化
??????? /// </summary>
??????? /// <param name="Section"></param>
??????? public ConfigManager(XmlNode Section)
??????? {
??????????? section = Section;
??????? }
??????? /// <summary>
??????? /// 獲取類工廠
??????? /// </summary>
??????? /// <returns></returns>
??????? public ClassFactory getFactory()
??????? {
??????????? XmlNode factory = section.SelectSingleNode("http://classFactory");
??????????? return new ClassFactory(factory);
??????? }
??????? /// <summary>
??????? /// 獲取Windows服務(wù)
??????? /// </summary>
??????? /// <returns></returns>
??????? public WinServiceConfig getWinService()
??????? {
??????????? XmlNode ServiceNode = section.SelectSingleNode("http://windowsSercice");
??????????? return new WinServiceConfig(ServiceNode);
??????? }
??????? /// <summary>
??????? /// 獲取緩存對象類
??????? /// </summary>
??????? /// <returns></returns>
??????? public CacheConfig getCacheConfig()
??????? {
??????????? XmlNode ServiceNode = section.SelectSingleNode("http://cacheService");
??????????? return new CacheConfig(ServiceNode);
??????? }
??? }

??? /// <summary>
??? /// 類工廠服務(wù)
??? /// </summary>
??? public class ClassFactory
??? {
??????? private XmlNode node;
??????? /// <summary>
??????? /// 實例化
??????? /// </summary>
??????? /// <param name="factoryNode"></param>
??????? public ClassFactory(XmlNode factoryNode)
??????? {
??????????? node = factoryNode;
??????? }
??????? /// <summary>
??????? /// 獲取類
??????? /// </summary>
??????? /// <param name="className">類名</param>
??????? /// <returns>object</returns>
??????? public object getClass(string className)
??????? {
??????????? XmlNode classNode = node.SelectSingleNode("http://class[@name='"+className+"']");
??????????? object classObject = null;
??????????? if(classNode !=null)
??????????? {
??????????????? string StrType= classNode.Attributes["type"].Value;
??????????????? string url = null;
??????????????? Type type = Type.GetType(StrType);
??????????????? if (classNode.Attributes["url"] != null && classNode.Attributes["url"].Value != "")
??????????????? {
??????????????????? url = classNode.Attributes["url"].Value;
??????????????????? try
??????????????????? {
??????????????????????? classObject = Activator.GetObject(type, url);
??????????????????? }
??????????????????? catch
??????????????????? {
??????????????????? }
??????????????? }
??????????????? else
??????????????? {
??????????????????? try
??????????????????? {
??????????????????????? classObject = Activator.CreateInstance(type, null);
??????????????????? }
??????????????????? catch
??????????????????? {
??????????????????? }
??????????????? }
??????????? }
??????????? return classObject;
??????? }
??????? /// <summary>
??????? /// 獲取一個類工廠組的所有實例
??????? /// </summary>
??????? /// <param name="GroupName">組名</param>
??????? /// <returns></returns>
??????? public List<object> getClassGroup(string GroupName)
??????? {
??????????? XmlNode GroupNode = node.SelectSingleNode("http://classGroup[@name='" + GroupName + "']");
??????????? List<object> list = new List<object>();
??????????? for (int i = 0; i < GroupNode.ChildNodes.Count; i++)
??????????? {
??????????????? if (GroupNode.ChildNodes[i].Attributes["type"].Value != "")
??????????????? {
??????????????????? Type type = Type.GetType(GroupNode.ChildNodes[i].Attributes["type"].Value);
??????????????????? list.Add(Activator.CreateInstance(type,null));
??????????????? }
??????????? }
??????????? return list;
??????? }
??? }

??? /// <summary>
??? /// Windows Services服務(wù)
??? /// </summary>
??? public class WinServiceConfig
??? {
??????? private XmlNode RootNode;
??????? public WinServiceConfig(XmlNode ServiceNode)
??????? {
??????????? RootNode = ServiceNode;
??????? }
??????? /// <summary>
??????? /// 獲取所有服務(wù)的列表
??????? /// </summary>
??????? /// <returns></returns>
??????? public List<object> getIServers()
??????? {
??????????? List<object> objServerList=new List<object>();
??????????? foreach (XmlNode node in RootNode.SelectNodes("service"))
??????????? {
??????????????? if (node != null && node.Attributes["type"] != null && node.Attributes["type"].Value != "")
??????????????? {
??????????????? Type type=Type.GetType(node.Attributes["type"].Value);
??????????????? IServerObj obj = new IServerObj(Activator.CreateInstance(type, null), node.Attributes["type"].Value, node.Attributes["type"].Value, node.Attributes["type"].Value);
??????????????? objServerList.Add(obj);
??????????????? }
??????????? }
??????????? return objServerList;
??????? }
??? }
??? /// <summary>
??? /// windows服務(wù)接口的結(jié)構(gòu)類
??? /// </summary>
??? public class IServerObj
??? {
??????? private object service;
??????? private string domain;
??????? private string username;
??????? private string userpwd;
??????? public IServerObj(object _service, string _domain,string _username, string _userpwd)
??????? {
??????????? service = _service;
??????????? domain = _domain;
??????????? username = _username;
??????????? userpwd = _userpwd;
??????? }
??????? /// <summary>
??????? /// 服務(wù)對象
??????? /// </summary>
??????? public object Service
??????? {
??????????? get {return service; }
??????? }
??????? /// <summary>
??????? /// 服務(wù)域
??????? /// </summary>
??????? public string Domain
??????? {
??????????? get { return domain; }
??????? }
??????? /// <summary>
??????? /// 安全帳號
??????? /// </summary>
??????? public string Username
??????? {
??????????? get { return username; }
??????? }
??????? /// <summary>
??????? /// 安全密碼
??????? /// </summary>
??????? public string Userpwd
??????? {
??????????? get { return userpwd; }
??????? }
??? }

??? /// <summary>
??? /// 緩存服務(wù)
??? /// </summary>
??? public class CacheConfig
??? {
??????? private XmlNode node;
??????? private object cacheObj = null;
??????? public CacheConfig(XmlNode xml)
??????? {
??????????? node = xml;
??????? }
??????? /// <summary>
??????? /// 獲取緩存對象
??????? /// </summary>
??????? /// <param name="CacheName">緩存名稱</param>
??????? /// <returns></returns>
??????? public object getCache(string CacheName)
??????? {
??????????? if (node != null && node.HasChildNodes)
??????????? {
??????????????? XmlNode nodech = node.SelectSingleNode("http://cache[@name='" + CacheName + "']");
??????????????? string typestr = nodech.Attributes["type"].Value;
??????????????? Type type = Type.GetType(typestr);
??????????????? cacheObj = Activator.CreateInstance(type, null);
??????????? }
??????????? return cacheObj;
??????? }
??? }
}

通過這樣的配置后我們需要的額外信息就可以直接通過這個類找配置文件要了.

CWF框架之ConfigManager,讓“config”為您服務(wù)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲成a人在线播放www | 亚洲综合五月天 | 国产大学生一级毛片绿象 | 九九热这里都是精品 | 国产精品视频偷伦精品视频 | xxx中国www免费| 久久影视在线观看 | 久青草香蕉精品视频在线 | 欧美特欧美特级一片 | 久久精品中文字幕不卡一二区 | 夜夜摸视频网 | 欧美一级级a在线观看 | 亚洲狠狠婷婷综合久久久图片 | 国产精品大片天天看片 | xxxx日本免费高清视频 | 狠狠色综合网 | 亚洲网站视频 | 亚洲精品香蕉一区二区 | 黄色毛片免费观看 | 久久久久久综合一区中文字幕 | 俄罗斯老妇性欧美毛茸茸孕交 | 成 人 黄 色视频免费播放 | 在线 中文字幕 日韩 欧美 | 国产成人毛片视频不卡在线 | 北岛玲日韩精品一区二区三区 | 麻豆国产精品高中生视频 | 国产成人a在一区线观看高清 | 亚洲一区二区在线免费观看 | 国产在线视频一区 | 国产在线成人a | 国产视频久久久 | 国产精品亚洲一区二区三区正片 | 一级成人a免费视频 | 久久精品无码一区二区三区 | 欧美在线香蕉在线现视频 | 久热re在线视频精品免费 | 日韩精品午夜视频一区二区三区 | 欧美a视频| 91色在线视频 | 欧美人成人亚洲专区中文字幕 | 国产区成人综合色在线 |