CustomerConfigHelper
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的更多相关文章
随机推荐
- 【C#】【Thread】上下文同步域SynchronizationAttribute
上下文同步:使用SynchronizationAttribute为ContextBoundObject对象创建一个简单的自动的同步. 这种同步方式仅用于实例化的方法和域的同步.所有在同一个上下文域的对 ...
- raid知识
1,raid形象理解(饮水机模型) http://dingyichao.blog.51cto.com/442449/698762 2,raid利用率 3,raid详细理解 raid0 raid ...
- js 中的算法题,那些经常看到的
js中遇到的算法题不是很多,可以说基本遇不到.但面试的时候,尤其是一些大公司,总是会出这样那样的算法题,考察一个程序员的逻辑思维能力.如下: 1.回文. 回文是指把相同的词汇或句子,在下文中调换位置或 ...
- 微信公众平台开发之微信access_token如何有效长期保存
随着微信使用越来越广泛,微信公众平台开放了许多接口以提供更多个性化的服务,包括自定义菜单接口.客服接口.获取用户信息接口.用户分组接口.群发接口等,开发者在调用这些接口时,都需要传入一个相同的参数ac ...
- [Android] 【视频】黑马安卓62、66期等教程+源码
下载地址:http://fu83.cn/thread-58-1-1.html
- 《JavaScript高级程序设计》chapter 1: javascript 简介
1.2.2 文档对象模型 DHTML的出现让开发人员无需重新加载页面就可以修改其外观了. 1.2.3 浏览器对象模型(BOM) BOM真正与众不同的地方在于他作为javascript实 ...
- [CareerCup] 8.6 Jigsaw Puzzle 拼图游戏
8.6 Implement a jigsaw puzzle. Design the data structures and explain an algorithm to solve the puzz ...
- LeetCode 笔记26 Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- Qt opencv程序运行异常
搭建了两次qt opencv vs ,经常出现程序运行异常.找了几个原因如下: 1.opencv的路径未配置或配置有误. 2.qt中pro文件包含不正确. 3.测试opencv程序不正确.如视频或图片 ...
- 一个简单js select插件
现在,通过一个select插件,来介绍一下js插件的构建过程. 1.先上效果图 2.目录构建 (1)这个select插件,我给它起名交hongselect,所以呢,首先建个hongselect的文件夹 ...