• Parameter Config


    public class ConfigInfo
        {
            public static ScriptsHelper Scripts
            {
                get { return new ScriptsHelper(); }
            }
            public static ParametersHelper Parameters
            {
                get { return new ParametersHelper(); }
            }
        }
    
        public class ScriptsHelper
        {
            string fileName = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, @"ConfigsScripts.xml");
            public PerScript this[string name]
            {
                get
                {
                    string value = Tools.ExecuteXPathInFile(fileName, string.Format(@"/Scripts/Script[@name='{0}']/text()", name.Trim()));
                    string connection = Tools.ExecuteXPathInFile(fileName, string.Format(@"/Scripts/Script[@name='{0}']/@connectionName", name.Trim()));
                    PerScript script = new PerScript(value, connection);
                    return script;
                }
            }
    
            public class PerScript
            {
                public PerScript(string value, string connection)
                {
                    m_Value = value;
                    m_Connection = connection;
                }
    
                string m_Value;
                public string Value { get { return m_Value; } }
    
                string m_Connection;
                public string Connection { get { return m_Connection; } }
            }
        }
    
        public class ParametersHelper
        {
            string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, JobConstValue.SERVICE_PARAMETER_FILE);
            public PerKeyValue this[string name]
            {
                get
                {
                    string keyValueStr = Tools.ExecuteXPathInFile(fileName, string.Format(@"/KeyValues/KeyValue[@name='{0}']", name.Trim()));
                    if (keyValueStr != null)
                    {
                        PerKeyValue returnObj = new PerKeyValue(name, keyValueStr);
                        return returnObj;
                    }
                    else
                    {
                        return null;
                    }
                }
            }
    
            public class PerKeyValue
            {
                public PerKeyValue(string name, string keyValueStr)
                {
                    m_KeyValueStr = keyValueStr;
                    m_Name = name;
                    m_Value = Tools.ExecuteXPathInString(keyValueStr, @"/KeyValue/text()");
                }
    
                string m_KeyValueStr;
    
                private string m_Name;
                public string Name { get { return m_Name; } }
    
                public PerKeyValueAttributes Attributes
                {
                    get
                    {
                        string[] temp = m_KeyValueStr.GetSubString(@"(?<=<KeyValues+).+.(?=/?>)");
                        if (temp != null && temp.Length > 0)
                            return new PerKeyValueAttributes(temp[0]);
                        else
                            return null;
                    }
                }
    
                string m_Value;
                public string Value { get { return m_Value; } }
    
                public List<PerKeyValue> KeyValus
                {
                    get
                    {
                        List<PerKeyValue> list = null;
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(m_KeyValueStr);
                        XmlNodeList nodes = doc.SelectNodes("/KeyValue/KeyValue");
                        if (nodes != null && nodes.Count > 0)
                        {
                            list = new List<PerKeyValue>();
                            foreach (XmlNode item in nodes)
                            {
                                list.Add(new PerKeyValue(item.Attributes["name"].InnerText, item.OuterXml));
                            }
                        }
                        return list;
                    }
                }
    
                public PerKeyValue this[string name]
                {
                    get
                    {
                        string keyValueStr = Tools.ExecuteXPathInString(m_KeyValueStr, string.Format(@"/KeyValue/KeyValue[@name='{0}']", name.Trim()));
                        if (keyValueStr != null)
                            return new PerKeyValue(name, keyValueStr);
                        else
                            return null;
                    }
                }
            }
    
            public class PerKeyValueAttributes
            {
                public PerKeyValueAttributes(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;
                    }
                }
            }
        }
  • 相关阅读:
    python习题-用交集方式产生随机密码
    python习题-产生8位随机密码要包含大小写及数字
    python习题-替换敏感词
    python习题-注册用户程序
    Python习题-登录
    Python习题-统计日志中访问次数超过限制的IP
    PyCharm配置过程记录
    jmeter 多压力机并发测试过程
    Jmete基础使用
    Linux 中直接 I/O 机制的介绍
  • 原文地址:https://www.cnblogs.com/Wolfmanlq/p/4183412.html
Copyright © 2020-2023  润新知