zoukankan      html  css  js  c++  java
  • 常用的工具类7-配置类

    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);
    }

    }

  • 相关阅读:
    Wazuh配置电子邮件警报(SMTP)
    kafka 分区重新分配脚本
    shell并发及控制并发数
    python2和python3使用pyhive
    k8s1.17安装gitlab
    nginx ssl证书 BEGIN PRIVATE KEY 转换为BEGIN RSA PRIVATE KEY
    Datax:阿里云hbase数据导入到自建hbase集群
    python3连接impala(centos7)
    Effective Java2读书笔记-类和接口(五)
    Effective Java2读书笔记-类和接口(四)
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/5605536.html
Copyright © 2011-2022 走看看