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. 数字转换为壹仟贰佰叁拾肆的Java方法

    网银转帐时, 填写金额后下方出现的汉字金额, 这是Java下的实现. public static String toRMB(double money) { char[] s1 = {'零', '壹', ...

  2. MySQL数据备份小结

    一 MySQL备份恢复总结: 1,备份所有库 2,分库备份 3,备份某库中的某表 4,备份某库中的多个表 5,分表备份 6,只备份表结构 7,只备份数据 二 MySQL备份恢复参数总结: -A 备份所 ...

  3. cookie+memcached实现单点登陆

    10年的时候在iteye的第一篇文章记录了一下当时怎么实现我们系统的单点登陆.不过那个时候文章写的不好,思路也很浮躁,很难看懂,在csdn的第一篇技术博客打算重新温顾一下当时实现单点登陆的思路.先来看 ...

  4. Androd Studio layout页面布局无法预览

    Could not initialize class android.support.v7.internal.widget.ActionBarOverlayLayout 导致无法看到布局页面,解决方法 ...

  5. PostgreSQL: 一种用于生成随机字符串的方法

    create or replace function random_string(integer) returns text as $body$ select array_to_string(arra ...

  6. Linux第二次学习笔记

    #Linux第二次实验(第三周) 学习目标 熟悉Linux系统下的开发环境 熟悉vi的基本操作 熟悉gcc编译器的基本原理 熟练使用gcc编译器的常用选项 熟练使用gdb调试技术 熟悉makefile ...

  7. POJ2289-Jamie's Contact Groups-二分图多重匹配-ISAP

    注意POJ数组越界可能返回TLE!!! 网络流的maxn大小要注意 其他没什么了 裸二分答案+isap乱搞 不过复杂度没搞懂 V=1e3 E = 1e5 那ISAP的O(V^2E)怎么算都不行啊 /* ...

  8. 20145208 实验二 Java面向对象程序设计

    20145208 实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验步 ...

  9. 发布HTML5 RTS游戏-古代战争

    古代战争 游戏介绍 "古代战争"是一个2.5D即时战略游戏,使用了帝国时代2的素材,并参考了它的游戏设计和玩法. 游戏基于YEngine2D引擎开发,具备生产.建造.资源采集.战斗 ...

  10. 详解SpringMVC中Controller的方法中参数的工作原理[附带源码分析]

    目录 前言 现象 源码分析 HandlerMethodArgumentResolver与HandlerMethodReturnValueHandler接口介绍 HandlerMethodArgumen ...