public class ConfigHelper
{
public static ScriptsHelper Scripts
{
get { return new ScriptsHelper(); }
}
public static ParametersHelper Parameters
{
get { return new ParametersHelper(); }
}
}
public class ScriptsHelper
{
string fileName = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, @"Scripts.xml");
public PerScript this[string name]
{
get
{
string value = Tools.ExecuteXPathInFile(fileName, string.Format(@"/Scripts/Script[@name='{0}']/text()", name.Trim()));
string connection = Tools.ExecuteXPathInFile(fileName, string.Format(@"/Scripts/Script[@name='{0}']/@connectionName", name.Trim()));
PerScript script = new PerScript(value, connection);
return script;
}
} public class PerScript
{
public PerScript(string value, string connection)
{
m_Value = value;
m_Connection = connection;
} string m_Value;
public string Value { get { return m_Value; } } string m_Connection;
public string Connection { get { return m_Connection; } }
}
} public class ParametersHelper
{
string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConstValue.SERVICE_PARAMETER_FILE);
public PerKeyValue this[string name]
{
get
{
string keyValueStr = Tools.ExecuteXPathInFile(fileName, string.Format(@"/KeyValues/KeyValue[@name='{0}']", name.Trim()));
if (keyValueStr != null)
{
PerKeyValue returnObj = new PerKeyValue(name, keyValueStr);
return returnObj;
}
else
{
return null;
}
}
} public class PerKeyValue
{
public PerKeyValue(string name, string keyValueStr)
{
m_KeyValueStr = keyValueStr;
m_Name = name;
m_Value = Tools.ExecuteXPathInString(keyValueStr, @"/KeyValue/text()");
} string m_KeyValueStr; private string m_Name;
public string Name { get { return m_Name; } } public PerKeyValueAttributes Attributes
{
get
{
string[] temp = m_KeyValueStr.GetSubString(@"(?<=\<KeyValue\s+).+.(?=/?\>)");
if (temp != null && temp.Length > 0)
return new PerKeyValueAttributes(temp[0]);
else
return null;
}
} string m_Value;
public string Value { get { return m_Value; } } public List<PerKeyValue> KeyValus
{
get
{
List<PerKeyValue> list = null;
XmlDocument doc = new XmlDocument();
doc.LoadXml(m_KeyValueStr);
XmlNodeList nodes = doc.SelectNodes("/KeyValue/KeyValue");
if (nodes != null && nodes.Count > 0)
{
list = new List<PerKeyValue>();
foreach (XmlNode item in nodes)
{
list.Add(new PerKeyValue(item.Attributes["name"].InnerText, item.OuterXml));
}
}
return list;
}
} public PerKeyValue this[string name]
{
get
{
string keyValueStr = Tools.ExecuteXPathInString(m_KeyValueStr, string.Format(@"/KeyValue/KeyValue[@name='{0}']", name.Trim()));
if (keyValueStr != null)
return new PerKeyValue(name, keyValueStr);
else
return null;
}
}
} public class PerKeyValueAttributes
{
public PerKeyValueAttributes(string attributes)
{
m_Attributes = attributes;
} string m_Attributes = string.Empty; public string this[string name]
{
get
{
string[] results = m_Attributes.GetSubString(string.Format(@"(?<={0}\s*="").+", name));
if (results != null && results.Length > 0)
{
return results[0].ReplaceString(@""".*", string.Empty);
}
else
return null;
}
}
}
}

  

KeyValue Config的更多相关文章

  1. Web读取指定的config文件的内容

    需求: 什么时候会用到动态改变Web.config内的值? 在Web.config定义了一个全局设置值A,因为程序运行中满足了某个条件,要将A的值改变 Web.config中定义: <appSe ...

  2. WinForm读取指定的config文件的内容

    config文件的使用 一.缘起 最近做项目开始使用C#,因为以前一直使用的是C++,因此面向对象思想方面的知识还是比较全面的,反而是因没有经过完整.系统的.Net方面知识的系统学习,经常被一些在C# ...

  3. winform 配置文件增删改查

    winform 配置文件是  App.config webform   的配置文件 是web.config 其实基本操作都一样    设置个配置文件  全局文件 访问者个配置文件  对这个配置文件增删 ...

  4. ConfigParser_读取配置文件信息

    ConfigParse简介 ConfigParser 在python中是用来解析配置文件的内置模块,直接导入使用 import configparser 使用该模块可以对配置文件进行增.读.改.删操作 ...

  5. Java连接Redis (key-value存储系统)

    Redis简介: redis是一个性能非常优秀的内存数据库,通过key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表). ...

  6. 高性能文件缓存key-value存储—Memcached

    1.高性能文件缓存key-value存储—Redis 2.ASP.NET HttpRuntime.Cache缓存类使用总结 备注:三篇博文结合阅读,简单理解并且使用,如果想深入学习,请多参考文章中给出 ...

  7. ini,config文件的读取修改

    修改ini配置文件 // 声明INI文件的写操作函数 WritePrivateProfileString() [System.Runtime.InteropServices.DllImport(&qu ...

  8. C++[类设计] ini配置文件读写类config

      //in Config.h #pragma once #include <windows.h> #include <shlwapi.h> #pragma comment(l ...

  9. 浅尝key-value数据库(三)——MongoDB的分布式

    浅尝key-value数据库(三)——MongoDB的分布式 测试了单机MongoDB的随机读和写入性能,这一节来讲一讲MongoDB的分布式. MongoDB的分布式分成两种,一种是Replicat ...

随机推荐

  1. Sqlte数据库

    1. 收缩数据库. 指令:VACUUM

  2. svg―Raphael.js Library(一)

    Raphael是一个用于在网页中绘制矢量图形的Javascript库,它使用SVG W3C推荐标准和VML作为创建图形的基础,可以通过JavaScript操作DOM来轻松创建出各种复杂的柱状图.饼图. ...

  3. Windows下msysGit使用及相关配置

    Windows下msysGit使用 目前我们git通过ssh进行通信,所以需要你也安装ssh以及将ssh key发给我,省得每次都需要输入用户名和密码 1.创建工程目录 windows下进入msysG ...

  4. WPF 定时写入文本

    public static void Start() { ThreadStart start = new ThreadStart(ThreadAction); Thread th = new Thre ...

  5. 关于 Visual Studio 调试 Global 的一点总结

    在开发 MVC 的项目中遇到了些问题,想通过调戏查看找问题的原因,发现无法调试 Global 中的 Application_Start 方法,在网上找遍了也没有相应的解决办法,在经过了很多次尝试之后仍 ...

  6. 在线程池使用Callable和Runnable的区别以及如何关闭线程

    一.区别总结: Callable定义的方法是call,而Runnable定义的方法是run. Callable的call方法可以有返回值,而Runnable的run方法不能有返回值,这是核心区别. C ...

  7. 常用SQL语句备忘录

    1.---表中有重复记录用SQL语句查询出来 select * from Recharge where RechargeSerial in (select RechargeSerial from Re ...

  8. Apache2.4中开通HTTP基本认证

    Apache2.4中开通HTTP基本认证,需要在Apache的配置文件中增加如下代码 WSGIPassAuthorization On 否则则无法认证

  9. 自动SPF生成工具

    到openspf网站去自动生成一下,地址是http://old.openspf.org/wizard.html.详细解释见下图关于spf的详细语法请看http://www.openspf.org/SP ...

  10. 设置zookeeper jvm内存

    看了你的问题, 我还特意的查看了ZooKeeper的启动脚本代码.ZooKeeper启动脚本没有加任何参数,也就是使用jvm默认的. 如果想要加大ZooKeeper的JVM使用内存.可以在更改{ZK_ ...