Configuration Management Application Block (cmab)使用方法

博客展示了一个名为 StorePage 的函数代码,该函数用于存储网页相关信息。它能获取文档标题、链接和选中文本,并通过 window.open 方法打开指定页面传递这些信息,最后让新窗口获得焦点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

function StorePage() { d=document; t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():''); void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes')); keyit.focus(); }
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>


<think>好的,我现在需要解决用户的问题:“M1Cba字符串升序排列”。首先,我要理解用户的需求。这里的“M1Cba”可能是一个示例字符串,用户想知道如何将其按升序排列。接下来,我需要考虑字符串中的字符类型,包括大写字母、小写字母和数字,因为不同的字符在ASCII码中的顺序不同,这会影响排序结果。 首先,我应该明确升序排列的具体规则。通常,字符的排序是基于它们的ASCII码值。ASCII码中,数字('0'-'9')的码值小于大写字母('A'-'Z'),而大写字母又小于小写字母('a'-'z')。所以,如果直接对字符串中的每个字符按ASCII码排序,结果可能会是数字、大写字母、小写字母这样的顺序。 接下来,我需要处理具体的字符串“M1Cba”。分解这个字符串,字符依次是:'M'(大写)、'1'(数字)、'C'(大写)、'b'(小写)、'a'(小写)。将这些字符转换为ASCII码值: - 'M' → 77 - '1' → 49 - 'C' → 67 - 'b' → 98 - 'a' → 97 按升序排列这些码值会得到顺序:49('1')、67('C')、77('M')、97('a')、98('b'),对应的字符串就是“1CMab”。 用户可能期望的是另一种排序方式,例如将所有字母视为同一种形式,比如不区分大小写,或者先字母后数字。但根据常规的ASCII排序规则,结果应该是“1CMab”。因此,我需要确认用户是否希望严格按照ASCII码排序,还是有其他特定要求。如果用户没有特别说明,通常默认就是ASCII顺序。 此外,我需要考虑是否存在其他可能的解释。例如,是否将字母转换为统一的大小写再进行排序?如果用户希望字母部分按字母表顺序排列,不考虑大小写,并且数字排在字母之后,结果会不同。但按照常规的编程语言排序方法,默认是ASCII顺序,所以应该以这个为基础回答。 最后,我需要将这个过程清晰地解释给用户,说明排序的依据和步骤,并提供示例结果,确保用户理解。如果有其他可能的排序方式,也应简要提及,以覆盖用户可能的潜在需求。</think>我们将对字符串 "M1Cba" 进行字符升序排列,按照ASCII码值从小到大排列: 原字符串分解: $$ M \ (77),\ 1 \ (49),\ C \ (67),\ b \ (98),\ a \ (97) $$ ASCII码值排序步骤: 1. 将每个字符转换为ASCII码 2. 按数值从小到大排序 3. 将数值还原为字符 排序过程: $$ 49 \ (1) \rightarrow 67 \ (C) \rightarrow 77 \ (M) \rightarrow 97 \ (a) \rightarrow 98 \ (b) $$ 最终升序排列结果为: $$ 1CMab $$ 补充说明: - 数字字符(1)的ASCII码值最小 - 大写字母(C/M)的码值小于小写字母(a/b) - 这是标准的ASCII排序规则,如需要字母大小写统一排序,需额外处理
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值