Configuration Management Application Block (cmab)使用方法

由于博客内容为空,无法提取关键信息生成摘要。
 
cmab的使用方法

Cmab使用方法

1. 新建一个WINform项目 testa
2. 引用Microsoft.ApplicationBlocks.ConfigurationManagement.dllMicrosoft.ApplicationBlocks.ConfigurationManagement.Interfaces.dll两个类库。
3. 在程序里面导入命名空间 using Microsoft.ApplicationBlocks.ConfigurationManagement;
4. 在解决方案管理器里的项目上单击鼠标右键,“添加-》添加新项-》应用程序配置文件”,把新添加的配置文件命名为App.Config 单击打开添加配置文件。
当添加完成后就在配置文件中添加如下代码:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
  <section name="applicationConfigurationManagement" type="Microsoft.ApplicationBlocks.ConfigurationManagement.ConfigurationManagerSectionHandler,Microsoft.ApplicationBlocks.ConfigurationManagement, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
  <section name="OtherConfigFile" type="testa.CustomSectionHandler,testa, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
 </configSections>
 <applicationConfigurationManagement defaultSection="OtherConfigFile">
  <configSection name="OtherConfigFile">
   <configProvider assembly="Microsoft.ApplicationBlocks.ConfigurationManagement,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"
    type="Microsoft.ApplicationBlocks.ConfigurationManagement.Storage.XmlFileStorage" signed="false"
    refreshOnChange="true" encrypted="false" path="../../otherConfigFile.config" />
   <protectionProvider assembly="Microsoft.ApplicationBlocks.ConfigurationManagement,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"
         type="Microsoft.ApplicationBlocks.ConfigurationManagement.DataProtection.BCLDataProtection"
         hashKey="MyXuEd6f+go=" symmetricKey="VToaqZjp8C27V90oSmT/CF+afvRGClc9" initializationVector="ou95G2/WziI="/>   
   
  </configSection>
 </applicationConfigurationManagement>
</configuration>

<configuration><section>项是.net框架定义的元素,详见MSDN (ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpgenref/html/gngrfsectionelement.htm)
applicationConfigurationManagement 是CMAB的配置项
configSection 指定程序读取的配置项的名称
configProvider 提供要使用到CMAB的组件的名称,使用什么方式来读写配置文件,自定义配置文件
   路径和是否加密等信息。
protectionProvider 提供加密的组件名称


5. 添加完配置文件后在程序中再添加一个新的XML配置文件,文件名为OtherConfigFile,然后在此文件中添加如下代码。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <OtherConfigFile>
    <CustomConfigurationData xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <name>tiger</name>
      <age>30</age>
    </CustomConfigurationData>
  </OtherConfigFile>
</configuration>

此段XML配置文件是自定义的配置文件其中configuration、OtherConfigFile、CustomConfigurationData是固定的XML标识。
包括在CustomConfigurationData里面的nameage两个元素为自定义元素。


6. 新建一个名为CustomConfigurationData.cs的类,此类为序列化的类
在类中定义以下两个属性,这两个属性分别为姓名和年龄
  public string name
  {
   get{ return _name; }
   set{ _name = value; }
  } string _name;

  public string age;
  {
   get{ return _age; }
   set{ _age = value; }
  } string _age;


7. 新建一个名为CustomSectionHandler.cs的类,此类是用来控制读取和写入配置文件的,它实现了IconfigurationSectionHandlerIconfigurationSectionHandlerWriter两个接口。里面提供的CREATE方法是用来读取配置文件数据的,Serialize是用来写入配置文件数据的。(这两个类加载到程序的命名空间下面)

[ComVisible(false)]
 public class CustomSectionHandler
  : IConfigurationSectionHandler, IConfigurationSectionHandlerWriter
 {
  XmlSerializer xs = new XmlSerializer( typeof(CustomConfigurationData) );

  public object Create( object parent, object hmm, XmlNode configSection )
  {
   object tmpObj = null;
   tmpObj = xs.Deserialize( new StringReader( configSection.OuterXml ) );
   return (CustomConfigurationData)tmpObj;
  }

  public XmlNode Serialize( object value )
  {
            try
            {
                StringWriter sw = new StringWriter( System.Globalization.CultureInfo.CurrentUICulture );
                xs.Serialize( sw, value );
                XmlDocument doc = new XmlDocument();
                doc.LoadXml( sw.ToString() );
                return doc.ChildNodes[1];
            }
            catch( Exception e )
            {
                throw new ConfigurationException( "此配置项不能被序列化!", e );
            }
  }
 }

8. 在窗体上添加两个文本框、两个lable和两个按钮
 在两个lable的text上配别填写“姓名”和“年龄”
 两个文本框分别命名为txtNametxtAge
 把button1name改为btnReadtext属性改为“读取”,button2name属性改为btnWrite
   text属性改为“写入”。
9. 在btnRead的单击事件里面添加如下代码
 CustomConfigurationData cclass = (CustomConfigurationData)ConfigurationManager.Read("OtherConfigFile" );
   txtName.Text = cclass.name;
   txtAge.Text = cclass.age;

10.在btnWrite的单击事件里添加如下代码
CustomConfigurationData cf = new CustomConfigurationData();
   cf.name = txtName.Text.Trim();
   cf.age = txtAge.Text.Trim();
   ConfigurationManager.Write("OtherConfigFile",cf);

完成上述步骤后运行程序就可以对配置文件进行读写操作了。

如果把配置文件的 encrypted 设置为true的话,就可以实现加密了

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
  <section name="applicationConfigurationManagement" type="Microsoft.ApplicationBlocks.ConfigurationManagement.ConfigurationManagerSectionHandler,Microsoft.ApplicationBlocks.ConfigurationManagement, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
  <section name="OtherConfigFile" type="testa.CustomSectionHandler,testa, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
 </configSections>
 <applicationConfigurationManagement defaultSection="UnencryptedXml">
  <configSection name="OtherConfigFile">
   <configCache enabled="true" refresh="1 * * * *" />
   <configProvider assembly="Microsoft.ApplicationBlocks.ConfigurationManagement,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"
    type="Microsoft.ApplicationBlocks.ConfigurationManagement.Storage.XmlFileStorage" signed="false"
    refreshOnChange="true" encrypted="true" path="../../otherConfigFile.config" />
   <protectionProvider assembly="Microsoft.ApplicationBlocks.ConfigurationManagement,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"
         type="Microsoft.ApplicationBlocks.ConfigurationManagement.DataProtection.BCLDataProtection"
         hashKey="MyXuEd6f+go=" symmetricKey="VToaqZjp8C27V90oSmT/CF+afvRGClc9" initializationVector="ou95G2/WziI="/>
    
   
  </configSection>
 </applicationConfigurationManagement>
</configuration>
5. 添加完配置文件后在程序中再添加一个新的XML配置文件,文件名为OtherConfigFile,然后在此文件中添加如下代码。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <OtherConfigFile>
    <CustomConfigurationData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <name>tiger</name>
      <age>30</age>
    </CustomConfigurationData>
  </OtherConfigFile>
</configuration>


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
  <section name="applicationConfigurationManagement" type="Microsoft.ApplicationBlocks.ConfigurationManagement.ConfigurationManagerSectionHandler,Microsoft.ApplicationBlocks.ConfigurationManagement, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
  <section name="OtherConfigFile" type="testa.CustomSectionHandler,testa, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
 </configSections>
 <applicationConfigurationManagement defaultSection="UnencryptedXml">
  <configSection name="OtherConfigFile">
   <configCache enabled="true" refresh="1 * * * *" />
   <configProvider assembly="Microsoft.ApplicationBlocks.ConfigurationManagement,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"
    type="Microsoft.ApplicationBlocks.ConfigurationManagement.Storage.XmlFileStorage" signed="false"
    refreshOnChange="true" encrypted="true" path="../../otherConfigFile.config" />
   <protectionProvider assembly="Microsoft.ApplicationBlocks.ConfigurationManagement,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"
         type="Microsoft.ApplicationBlocks.ConfigurationManagement.DataProtection.BCLDataProtection"
         hashKey="MyXuEd6f+go=" symmetricKey="VToaqZjp8C27V90oSmT/CF+afvRGClc9" initializationVector="ou95G2/WziI="/>
    
   
  </configSection>
 </applicationConfigurationManagement>
</configuration>
5. 添加完配置文件后在程序中再添加一个新的XML配置文件,文件名为OtherConfigFile,然后在此文件中添加如下代码。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <OtherConfigFile>
    <CustomConfigurationData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <name>tiger</name>
      <age>30</age>
    </CustomConfigurationData>
  </OtherConfigFile>
</configuration>


内容概要:本文系统阐述了智能物流路径规划的技术体系与实践应用,涵盖其发展背景、核心问题建模、关键算法、多目标与动态环境处理、系统架构及典型应用场景。文章以车辆路径问题(VRP)及其变体为核心数学模型,介绍了从Dijkstra、A*等单智能体算法到多车VRP的元启发式求解方法(如遗传算法、蚁群算法、大规模邻域搜索),并深入探讨了多目标优化(成本、时间、碳排放)与动态环境(实时订单、交通变化)下的自适应规划策略。结合城市配送、干线运输、场内物流等案例,展示了路径规划在提升效率、降低成本方面的实际价值,并分析了当前面临的复杂性、不确定性等挑战,展望了AI融合、数字孪生、车路协同等未来趋势。; 适合人群:具备一定物流、运筹学或计算机基础,从事智能交通、物流调度、算法研发等相关工作的技术人员与管理人员,工作年限1-5年为宜。; 使用场景及目标:①理解智能物流路径规划的整体技术架构与核心算法原理;②掌握VRP建模方法与多目标、动态环境下路径优化的实现策略;③为物流系统设计、算法选型与系统优化提供理论依据与实践参考; 阅读建议:建议结合文中案例与数学模型,重点理解算法选择与实际业务场景的匹配逻辑,关注动态规划与多目标优化的工程实现难点,可配合仿真工具或开源求解器进行实践验证。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值