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(@"(?<=\)"); 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 Parameters { get { List list = new List (); 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; } } } } } 配置文件示例:
9N 9X 9R B2B Order waiting for approval Hold By RuleSet API Hold S.O 7084500 99-993-001 00-999-157 ^(DISCOUNT FOR COMBO #){1}\d{1,10}$|^(DISCOUNT FOR COMBO #){1}\d{1,10}( GIFT){1}$|^(DISCOUNT FOR AUTOADD #){1}\d{1,10}$