Cmab使用方法
1.新建一个WINform项目 testa。
2.引用Microsoft.ApplicationBlocks.ConfigurationManagement.dll和Microsoft.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里面的name、age两个元素为自定义元素。
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的类,此类是用来控制读取和写入配置文件的,它实现了IconfigurationSectionHandler和IconfigurationSectionHandlerWriter两个接口。里面提供的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上配别填写“姓名”和“年龄”
两个文本框分别命名为txtName和txtAge。
把button1的name改为btnRead,text属性改为“读取”,button2的name属性改为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>
相关推荐
结合聚类与CMAB的群智感知车联网任务分配方法.docx
linux
银行秒杀系统 第十三服创比赛项目
单页登录源码 login登录页源码 html源码
理性力学 陈至达.pdf
JAVA在线考试管理系统(源代码+论文+开题报告+外文翻译+英文文献+答辩PPT)
加州房价预测是一个经典的机器学习案例,旨在通过给定的一些特征来预测加州地区房屋的中位数价格。这个案例通常使用监督学习算法来解决: 其中包括以下步骤: 数据收集:收集加州地区的房屋数据,包括房屋的各种特征,如房屋的位置、面积、卧室数量、人口密度等。 数据预处理:对收集到的数据进行清洗和处理,包括处理缺失值、异常值和重复值,进行特征选择和特征缩放等。 特征工程:根据问题的背景和数据的特点,进行特征工程,提取更有意义和相关性的特征。例如,可以通过计算每个区域的人均收入、房屋间距离海洋的距离等特征。 模型选择:选择适合解决这个问题的机器学习模型。常用的模型包括线性回归、决策树、支持向量机、神经网络等。 模型训练:使用训练数据对选定的模型进行训练,通过调整模型参数来最小化预测误差。 模型评估:使用测试数据对训练好的模型进行评估,常用的评估指标包括均方误差和决定系数等。 模型优化:根据评估结果,对模型进行优化,可以尝试调整模型参数、增加更多的特征、尝试其他算法等。 模型应用:使用优化后的模型进行加州房价的预测,可以输入新的特征数据,得到预测的房价。
web单页html主页老款 旧风格 管理页源码
旅游大数据HTML模板源码 大数据大屏展示源码 VUE
moood UI KitAdobeXD源码下载设计素材UI设计
生物信息学课程学习笔记第四版2022版
在校时,参加的创新创业比赛的项目,我负责前端Vue模块
AProject_Inner_Responsive_TemplatesAdobeXD源码下载设计素材UI设计
基于STM32的智能台灯 项目概述 该智能台灯能够实时监测环境光照强度,并根据环境亮度调整LED灯的亮度,亦可通过面板对台灯进行手动控制,从而实现智能护眼和节能的目的。 功能描述 1.环境感知功能:实时监测环境光照强度 2.信息显示功能:显示亮度等提示信息 3.面板控制功能:模式和光照等级切换 4.远程控制功能:远程开关LED灯 中断级调度任务 1.面板控制任务 2.环境感知任务 3.远程控制任务
HTML4-Desktop-App模板官网落地页APP主页产品宣传页源码 landing静态页面
自己学习机器学习算法过程中写的一些代码,由于换了个方向,暂时没法继续手写实现下去了。
名称 范围 默认参数 系统 ①低功耗系统 ②非低功耗系统 ① 功耗 不广播状态 1uA 广播状态200ms 0.14mA 广播配置 广播间隔时间: 间隔广播(20ms-2000ms) 200ms 广播数据: 设备名称 “Sensor” 制造商数据: FF 前两字节公司ID FFC1 A数据(uint16_t) 1001 B数据(uint16_t) 2001 C数据(uint16_t) 3001 D数据(uint16_t) 4001 E数据(uint16_t) 5001 F数据(uint16_t) 6001 G数据(uint16_t) 7001
因为在我们刷题的过程中,一定可以刷到一些难度很高却十分简单的题,俗话说就是“占着毛肯不拉屎”的水题,下面我就分享几个,因为虽然简单,但难度标准高,所以可以增加等级,刷题量,排名。那是多好的事啊,所以如果你有oj账号,那直接去用。没有没关系,你可以注册一个oj账号,那还等什么,赶紧行动吧!!!!!!!!!
AEM-CoreComponents-UI-KitAdobeXD源码下载设计素材UI设计
电子密码锁使用说明(1).doc