public static class CustomerConfigHelper
{
public static object _lockObject = new object();

private static string GetCustomConfigValue(string key)
{
string configFilePath = "~/Config/CustomConfig.config";
string configElementsName = "Add";
string configAttributeKeyName = "Key";
string configAttributeValueName = "Value";

return GetValue(key,configFilePath, configElementsName, configAttributeKeyName,configAttributeValueName);
}

private static string GetValue(string key,string configFilePath)
{
string configElementsName = "Add";
string configAttributeKeyName = "Key";
string configAttributeValueName = "Value";

return GetValue(key,configFilePath, configElementsName, configAttributeKeyName,configAttributeValueName);
}

private static string GetValue(string key, string configFilePath, string configElementsName, string configAttributeKeyName,string configAttributeValueName)
{
string _value = string.Empty;

string _path = HttpContext.Current.Server.MapPath(configFilePath);

XElement _element = XElement.Load(_path);
var _config = from config in _element.Elements(configElementsName) select config;

Dictionary<string, string> _dic = _config.ToDictionary(k => k.Attribute(configAttributeKeyName).Value, k => k.Attribute(configAttributeValueName).Value);

_dic.TryGetValue(key, out _value);
return _value;
}

/// <summary>
/// 获取自定义文件配置节点值:整形
/// </summary>
/// <param name="key">配置节点KEY</param>
/// <returns></returns>
public static int GetCustomConfigInt(string key)
{
return TypeHelper.ToInt(GetCustomConfigValue(key));
}
/// <summary>
/// 获取自定义文件配置节点值:整形
/// </summary>
/// <param name="key"></param>
/// <param name="configFilePath"></param>
/// <returns></returns>
public static int GetCustomConfigInt(string key, string configFilePath)
{
return TypeHelper.ToInt(GetValue(key, configFilePath));
}

/// <summary>
/// 获取自定义文件配置节点值:长整形
/// </summary>
/// <param name="key">配置节点KEY</param>
/// <returns></returns>
public static long GetCustomConfigLong(string key)
{
return TypeHelper.ToInt64(GetCustomConfigValue(key));
}
/// <summary>
/// 获取自定义文件配置节点值:长整形
/// </summary>
/// <param name="key"></param>
/// <param name="configFilePath"></param>
/// <returns></returns>
public static long GetCustomConfigLong(string key, string configFilePath)
{
return TypeHelper.ToInt64(GetValue(key, configFilePath));
}

/// <summary>
/// 获取自定义文件配置节点值:字符串
/// </summary>
/// <param name="key">配置节点KEY</param>
/// <returns></returns>
public static string GetCustomConfigString(string key)
{
return GetCustomConfigValue(key);
}
/// <summary>
/// 获取自定义文件配置节点值:字符串
/// </summary>
/// <param name="key"></param>
/// <param name="configFilePath"></param>
/// <returns></returns>
public static string GetCustomConfigString(string key, string configFilePath)
{
return GetValue(key, configFilePath);
}

}

<?xml version="1.0" encoding="utf-8" ?>
<customconfig>

<!--分页页码大小-->
<Add Key="PageSize" Value="10"></Add>
<!--图片路径-->
<Add Key="ImagesWebPath" Value="http://xxx.xx.xxx.xxx:9000"></Add>

</customconfig>

CustomerConfigHelper的更多相关文章

随机推荐

  1. 4201 TortoiseSVN常用配置

    在Windows下推荐使用乌龟(Tortoise)SVN客户端. TortoiseSVN 是 Subversion 版本控制系统的一个免费开源客户端,可以超越时间的管理文件和目录.文件保存在中央版本库 ...

  2. mac 无法连接android手机进行调试 解决方案

    第一步: 查看usb设备信息 在 终端输入:system_profiler SPUSBDataType     可以查看连接的usb设备的信息 比如我的usb信息如下(部分内容): Android: ...

  3. [转]在Ubuntu 下安装Redis 并使用init 脚本启动

    1. 下载安装:   cd /tmp wget http://redis.googlecode.com/files/redis-2.2.4.tar.gz tar -zxf redis-2.2.4.ta ...

  4. sed 4个功能

    [root@lanny test]# cat test.txt test liyao lanny 经典博文: http://oldboy.blog.51cto.com/2561410/949365 h ...

  5. jacob下载问题, Office word 此文件正由另一应用程序或用户使用的解决方法

    http://jingyan.baidu.com/article/75ab0bcbd6682fd6864db2db.html

  6. 通过HttpClient来调用Web Api接口~续~实体参数的传递

    并且我们知道了Post,Put方法只能有一个FromBody参数,再有多个参数时,上讲提到,需要将它封装成一个对象进行传递,而这讲主要围绕这个话题来说,接口层添加一个新类User_Info,用来进行数 ...

  7. python中class 的一行式构造器

    好处:避免类初始化时大量重复的赋值语句 用到了魔法__dict__ # 一行式构造器 class Test(): # 初始化 def __init__(self, a, b, c=2, d=3, e= ...

  8. [MetaHook] R_SparkShower

    By hzqst void R_SparkShower(float *pos) { TEMPENTITY *tent; tent = efx.CL_TempEntAllocNoModel(pos); ...

  9. 系统级IO实践学习记录

    代码分析 cp1.c 功能:复制文件. #include <stdio.h>#include <stdlib.h>#include <unistd.h>#inclu ...

  10. 20135220谈愈敏Blog6_进程的描述和创建

    进程的描述和创建 谈愈敏 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/USTC-1000029000 进程 ...