码迷,mamicode.com
首页 > 其他好文 > 详细

Parameter配置文件获取

时间:2014-09-27 18:05:10      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:des   blog   io   os   ar   for   文件   sp   div   

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(@"(?<=\<Parameter\s+).+.(?=/?\>)");
                        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>

  

  

Parameter配置文件获取

标签:des   blog   io   os   ar   for   文件   sp   div   

原文地址:http://www.cnblogs.com/Wolfmanlq/p/3996518.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!