Rickie is back .... 人生·工作的结果=思维方式×热情×能力

今天比昨天更好,明天比今天更好,为此,不屈不挠地工作、勤勤恳恳地经营、孜孜不倦地修炼,我们人生的目的和价值就是这样确确实实地存在着。

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  397 随笔 :: 3 文章 :: 1310 评论 :: 129 引用

2005年2月9日 #


kock.JPG恭贺各位鸡年好运,新年快乐,万事如意!!!
posted @ 2005-02-09 15:49 Rickie 阅读(635) 评论(3) 编辑

Enterprise Library: Configuration Application Block应用向导篇

Part 2

Written by: Rickie Lee (rickieleemail#yahoo.com)

My blog: www.cnblogs.com/rickie


Enterprise Library: Configuration Application Block应用向导篇, Part 1

Configuration Application Block应用向导

这里演示Configuration Application Block内建支持的XML File Storage ProviderXML Serializer Transformer,来读写XML配置数据。应用程序需要添加对Microsoft.Practices.EnterpriseLibrary.Configuration.dll引用,同时在代码添加如下语句:

using Microsoft.Practices.EnterpriseLibrary.Configuration;

 

Demo程序界面如下:
Enterprise_ConfigurationApplicationBlock_Demo.JPG

1)使用Configuration Console工具编写配置文件

如下图所示,添加Configuration Application Block,并同时添加Configuration Section,命名为ProxySettings,另外添加Configuration Application Block内置的XML File Storage ProviderXML Serializer Transformer,并设置Xml File Storage ProviderFileName属性。具体操作可以参考Enterprise Library: Configuration Application Block文档。

Enterprise_CAB_ConfigurationConsole.JPG

如下是App.config配置文件,该配置文件仅仅包含一些元数据。

<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <configSections>

    <section name="enterpriselibrary.configurationSettings" type="Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManagerSectionHandler, Microsoft.Practices.EnterpriseLibrary.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />

  </configSections>

  <enterpriselibrary.configurationSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" applicationName="Application" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration">

  <configurationSections>

    <configurationSection name="ProxySettings" encrypt="false">

      <storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="ProxySettingsConfiguration.config" />

      <dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">

        <includeTypes />

      </dataTransformer>

    </configurationSection>

  </configurationSections>

  <keyAlgorithmStorageProvider xsi:nil="true" />

  <includeTypes />

</enterpriselibrary.configurationSettings>

</configuration>

 

2)定义配置类

对应每一个应用程序,你需要定义应用程序访问的配置数据内存表示,也就是定义表示配置信息的类。根据配置数据的类型,表示形式可以是简单的字符串或Storage Provider返回的DataSet类型。另外一种选择是,配置数据可以以应用程序定义的复杂对象形式表示。有多种方法读写配置数据,每一种方法将影响数据的内存表示。

一种方法是使用Configuration Application Block内置的XmlSerializerTransformerXmlFileStorageProvider来读写配置数据。

如下定义配置类,作为XML配置文件的内存表示:

       public class ProxySettingsData

       {

              #region Private Members

              private string proxyServer;

              private int port;

              #endregion

 

              #region Public Accessors

              public string ProxyServer

              {

                     get { return proxyServer;}

                     set { proxyServer = value;}

              }

              public int Port

              {

                     get { return port;}

                     set { port = value;}

              }

              #endregion

 

              public ProxySettingsData()

              {

                     //

                     // TODO: Add constructor logic here

                     //

              }

 

              public override string ToString()

              {

                     StringBuilder sb = new StringBuilder();

                     sb.AppendFormat("Proxy Server = {0}; Port = {1}", proxyServer, port.ToString());

 

                     return sb.ToString();

              }

       }

 

To be continued. - Part 3 待续.
***

Enterprise Library: Configuration Application Block应用向导篇, Part 3


***

作者:Rickie Lee (rickieleemail#yahoo.com)

本文参考Enterprise Library, Configuration Application Block文档。

 

References:

1. Enterprise Library, Configuration Application Block

2. Rickie, Microsoft patterns & practices Enterprise Library January 2005 [中文稿], http://www.cnblogs.com/rickie/archive/2005/01/30/99443.html

3. Rickie, Enterprise Library released! http://www.cnblogs.com/rickie/archive/2005/01/29/99106.html

posted @ 2005-02-09 15:43 Rickie 阅读(3637) 评论(2) 编辑

Enterprise Library: Configuration Application Block应用向导篇 

Part 1

Written by: Rickie Lee (rickieleemail#yahoo.com)

My blog: www.cnblogs.com/rickie

几乎每一个应用程序都需要一些配置信息,这些信息可以是简单的数据库连接信息,或者复杂的多块多层次用户信息。如何以及在哪里存储应用程序配置数据是程序员经常面临的问题,典型的方案包括如下选择:

l         使用配置文件,如XML文件或Windows .ini文件。

l         使用Windows注册表。

l         使用数据库,如Microsoft SQL Server

 

Configuration Application Block设计达到如下的目标:

l         为读写配置数据提供简单的接口。

l         隔离应用程序和配置数据的物理存储位置(Storage Location)。

l         提供扩展模型,允许定制存储位置和配置信息的Runtime显示。

 

Configuration Application Block支持对可配置的存储位置进行读写操作。对于特定的存储位置,需要配置Application Block使用对应的Storage Provider,该Storage Provider知道如何读写该Storage Location的数据。

应用程序传递和接受的对象必须是Storage Provider所了解的,这里也许需要或不需要Transformer(转换器)。例如,如果应用程序使用Storage Provider从数据库读取信息和以DataSet类型返回,Application Block则不需配置任何transformerDataSet可以被Storage Provider读取。

另外一种情况是,Application Block使用transformer接受Storage Provider返回的对象,并转换为应用程序希望的特定对象类型。例如,transformer可以将Storage Provider返回DataSet对象转换为应用程序所使用的hashtable类型。如下图所示:

Enterprise_ConfigurationApplicationBlock1.JPG

这里,演示Configuration Application Block内置支持的XML配置,Storage ProviderXmlFileStorageProvider支持读写XML配置文件,它接受并返回XmlNode类型对象。TransformerXmlSerializerTransformer序列化对象为XmlNode类型和反序列化XmlNode对象为合适的类型。如下图描述了整个过程:
Enterprise_ConfigurationApplicationBlock2.JPG

应用程序包含有配置数据的可序列化对象,为了将对象中包含的数据写入配置文件中,Application Block首先使用XmlSerializerTransformer序列化数据为XmlNode对象。然后,Application Block传送XmlNode对象到XmlFileStorageProviderXmlFileStorageProvider负责将数据写入XML文件。为了读取配置数据,XmlFileStorageProviderXML文件读取数据,并返回XmlNode对象。Application Block接着传递XmlNode对象到XmlSerializerTransformerTransformer反序列化数据并返回给Application BlockApplication Block最终返回给应用程序。


To be continued. - Part 2 待续.
*** Updated ***

Enterprise Library: Configuration Application Block应用向导篇, Part 2
Enterprise Library: Configuration Application Block应用向导篇, Part 3


***

作者:Rickie Lee (rickieleemail#yahoo.com)

本文参考Enterprise Library, Configuration Application Block文档。


References:

1. Enterprise Library, Configuration Application Block

2. Rickie, Microsoft patterns & practices Enterprise Library January 2005 [中文稿], http://www.cnblogs.com/rickie/archive/2005/01/30/99443.html

3. Rickie, Enterprise Library released! http://www.cnblogs.com/rickie/archive/2005/01/29/99106.html

posted @ 2005-02-09 12:02 Rickie 阅读(4735) 评论(3) 编辑