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. Android 源码获取-----在Windows环境下通过Git得到Android源代码

    在学习Android的过程中,深入其源代码研究对我们来说是非常重要的,这里将介绍如何通过在Windows环境下使用Git来得到我们的Android源代码. 1.首先确保你电脑上安装了Git,这个通过  ...

  2. Modbus通讯协议学习 - 串口调试

    概述 我们在做任何事情之前都需要获取很多 调试步骤: 1:485转换器连接硬件 2:485转换器上的USB接口连接电脑. 3:打开设备管理器 ->查看端口 4:打开串口调试工具,在串口配置的地方 ...

  3. ubuntu系统中的VMware 安装win7 Ghost镜像的几个坑

    1.ghost镜像安装时要先分区 2.分区后要激活 3.VM(虚拟机安装win7 提示 :units specified don't exist, SHSUCDX can't install)解决方法 ...

  4. Cubieboard2裸机开发之(四)定时器操作

    前言 在Cubieboard2裸机开发之(三)里用到了一个延时函数delay,它的延时时间是不精确的,因此为了能够精确延时,就需要定时器的配合.定时器可以精确延时的一个重要原因是它的计时时钟(或者说频 ...

  5. iOS开发备忘录:自定义UINavigationBar背景图片和Back按钮

    iOS项目,根据设计图,有时需要自定义UIView的UINavigationBar的背景.可以切出来一张1像素左右的背景图片,来充当UINavigationBar的背景. 可以利用Navigation ...

  6. android自定义TabView实现圆角列表

    看到很多应用的设置界面都有圆角效果的列表,类似下面的 下面说说我的实现原理:继承LinearLayout,然后设置一个自定义的TabAdapter,类似于listview,添加一个setAdapter ...

  7. java之final关键字

    final关键字(可以读不可以写.只读) 1.final的变量的值不能够被改变 ①.final的成员变量 ②.final的局部变量(形参) //意思是“实参”一旦传进我的方法里面,就不允许改变 2.f ...

  8. Centos用yum升级mysql到(5.5.37)

    原文:http://www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel/ 1. Change ...

  9. ubuntu 安装bochs

    //首先官网下载bochs源码wget http://bochs.sourceforge.net/svn-snapshot/bochs-20150503.tar.gz//然后解压 tar vxzf b ...

  10. libevent源码深度剖析

    原文地址: http://blog.csdn.net/sparkliang/article/details/4957667 第一章 1,前言 Libevent是一个轻量级的开源高性能网络库,使用者众多 ...