zoukankan      html  css  js  c++  java
  • Parameter配置文件获取

    public class ConfigInfo
        {
            public static ParametersHelper Parameters
            {
                get { return new ParametersHelper(); }
            }
    
            public class ParametersHelper
            {
                string fileName = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,JobConstValue.BUSINESS_CONFIG_FILE);
                public PerParameter this[string name]
                {
                    get
                    {
                        string parameterStr = Utility.ExecuteXPathInFile(fileName, string.Format(@"/Parameters/Parameter[@name='{0}']", name.Trim()));
                        if (parameterStr != null)
                        {
                            PerParameter returnObj = new PerParameter(name, parameterStr);
                            return returnObj;
                        }
                        else
                        {
                            return null;
                        }
                    }
                }
    
                public class PerParameter
                {
                    public PerParameter(string name, string parameterStr)
                    {
                        m_ParameterStr = parameterStr;
                        m_Name = name;
                        m_Value = Utility.ExecuteXPathInString(parameterStr, @"/Parameter/text()");
                    }
    
                    string m_ParameterStr;
    
                    private string m_Name;
                    public string Name { get { return m_Name; } }
    
                    public PerParameterAttributes Attributes
                    {
                        get
                        {
                            string[] temp = m_ParameterStr.GetSubString(@"(?<=<Parameters+).+.(?=/?>)");
                            if (temp != null && temp.Length > 0)
                                return new PerParameterAttributes(temp[0]);
                            else
                                return null;
                        }
                    }
    
                    string m_Value;
                    public string Value { get { return m_Value; } }
    
                    public List<PerParameter> Parameters
                    {
                        get
                        {
                            List<PerParameter> list = new List<PerParameter>();
                            XmlDocument doc = new XmlDocument();
                            doc.LoadXml(m_ParameterStr);
                            XmlNodeList nodes = doc.SelectNodes("/Parameter/Parameter");
                            if (nodes != null && nodes.Count > 0)
                            {
                                foreach (XmlNode item in nodes)
                                {
                                    list.Add(new PerParameter(item.Attributes["name"].InnerText, item.OuterXml));
                                }
                            }
                            return list;
                        }
                    }
    
                    public PerParameter this[string name]
                    {
                        get
                        {
                            string parameterStr = Utility.ExecuteXPathInString(m_ParameterStr, string.Format(@"/Parameter/Parameter[@name='{0}']", name.Trim()));
                            if (parameterStr != null)
                                return new PerParameter(name, parameterStr);
                            else
                                return null;
                        }
                    }
                }
    
                public class PerParameterAttributes
                {
                    public PerParameterAttributes(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;
                        }
                    }
                }
            }
        }
    

    配置文件示例:

    <?xml version="1.0"?>
    <Parameters>
      <Parameter name="WarehouseNumber">
        <Parameter name="USA">9N</Parameter>
        <Parameter name="USB">9X</Parameter>
        <Parameter name="RoseWill">9R</Parameter>
      </Parameter>
      <Parameter name="HoldReason">
        <Parameter name="B2BHoldReason">B2B Order waiting for approval</Parameter>
        <Parameter name="APIHoldReason">Hold By RuleSet API</Parameter>
        <Parameter name="HoldReasonForSO">Hold S.O</Parameter>
      </Parameter>
      <Parameter name="TestAccount">
        <Parameter name="Account">7084500</Parameter>
      </Parameter>
    
      <Parameter name="SpecialItems">
        <Parameter name="UPSLabelItem">99-993-001</Parameter>
        <Parameter name="GiftCardItem">00-999-157</Parameter>
      </Parameter>
    
      <Parameter name="DiscountAllocationRegex">
        <Parameter name="RegexValue">^(DISCOUNT FOR COMBO #){1}d{1,10}$|^(DISCOUNT FOR COMBO #){1}d{1,10}( GIFT){1}$|^(DISCOUNT FOR AUTOADD #){1}d{1,10}$</Parameter>
      </Parameter>
    
    </Parameters>
    

      

      

  • 相关阅读:
    引入C/C++动态库
    Linux新手常用命令
    使用Dotfunsctor
    C#上传数据到HTTP,HTTPS 代码示例
    C#多个泛型约束问题
    创建DataTable与DataGridView进行绑定
    递归迭代vector三种方法实现二路归并排序
    区间贪心算法
    递归和非递归实现二叉树的遍历
    C语言实现全排列和回溯法总结
  • 原文地址:https://www.cnblogs.com/Wolfmanlq/p/3996518.html
Copyright © 2011-2022 走看看