<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Enterprise Library Step By Step系列(二):配置應用程序塊——進階篇

       在前一篇文章中,講述了配置應用程序塊的最簡單的介紹,在本篇文章中我主要介紹一下配置應用程序塊的響應配置變更通知,保護配置信息(加密配置信息),面向高級人員的擴展機制,配置數(shù)據(jù)的緩存等幾個方面。在剖析篇中我會去分析配置應用程序塊的底層設計及類設計。

      一.響應配置變更通知:

      Configuration Application Block提供了一個事件機制,當存儲的配置變更時通知應用程序 ,使用步驟:

      1)創(chuàng)建一個EverntHandler

       1/// <summary>
       2        /// 創(chuàng)建EventHanler
       3        /// </summary>
       4        /// <param name="sender"></param>
       5        /// <param name="args"></param>

       6        private void OnConfigurationChanged(object sender, ConfigurationChangedEventArgs args)
       7        {
       8            Cursor = System.Windows.Forms.Cursors.WaitCursor;
       9
      10            EditorFontData configData = ConfigurationManager.GetConfiguration("EditorSettings"as EditorFontData;
      11
      12            StringBuilder results = new StringBuilder();            
      13            results.Append("Configuration changes in storage were detected. Updating configuration.");
      14            results.Append(Environment.NewLine);
      15            results.Append("New configuration settings:");
      16            results.Append(Environment.NewLine);
      17            results.Append('\t');
      18            results.Append(configData.ToString());
      19            results.Append(Environment.NewLine);
      20
      21            Cursor = System.Windows.Forms.Cursors.Arrow;      
      22        }

      2)注冊事件

      1///注冊事件
      2        ConfigurationManager.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged); 

      二.配置數(shù)據(jù)的緩存:

      Configuration Application Block在設計時提供了對配置數(shù)據(jù)的緩存,在讀取XML數(shù)據(jù)后,再次讀取它首先會判斷緩存是否為空,如果不為空,它會直接從緩存中讀取數(shù)據(jù)(在剖析篇中會有詳細的介紹)。

      顯式的清除掉緩存用下面這句代碼即可:

      1///清除緩存數(shù)據(jù)
      2         ConfigurationManager.ClearSingletonSectionCache();

      三.面向高級人員的擴展機制:

      1 除了用XML文件可以存儲數(shù)據(jù)外,還可以創(chuàng)建自己的存儲方式,像SQL Server Database,注冊表存儲等,這時就需要我們自己創(chuàng)建StorageProvider。創(chuàng)建自定義的Storage Provider,需要注意以下幾點:

      1)要讀取和寫入數(shù)據(jù),需要繼承于StorageProvider類和分別實現(xiàn)IStorageProviderReaderIstorageProviderWriter接口:

      1public class XmlFileStorageProvider : StorageProvider, IStorageProviderWriter
      2        {
      3            //……
      4        }

      2)如果實現(xiàn)了IConfigurationProvider接口,則方法Initialize()就不能為空,也必須實現(xiàn):

      1public override void Initialize(ConfigurationView configurationView)
      2        {
      3            //……
      4        }

      3)實現(xiàn)Read()Write()方法,記住一定要返回類型為object,否則Transformer將無法使用:

      1public override object Read()
      2        {
      3            //……
      4        }

      5
      6        public void Write(object value)
      7        {
      8            //……
      9        }

      2.創(chuàng)建自定義的Transformer

      如果我們創(chuàng)建的自定義的Storage Provider不能后支持XMLNode,這時候我們需要創(chuàng)建自己的Transformer,需要注意以下幾點:

      1)自定義的Transformer如果實現(xiàn)了Itransformer接口;則必須實現(xiàn)方法Serialize()Deserialize();

      2)自定義的Transformer如果實現(xiàn)了IConfigurationProvider接口,則方法Initialize()就不能為空,也必須實現(xiàn);

      下面給出一個SoapSerializerTransformer的例子程序(先聲名一下,這個例子程序不是我寫的,而是Dario Fruk先生^_^):

       1namespace idroot.Framework.Configuration
       2{
       3    using System;
       4    using System.Configuration;
       5    using System.IO;
       6    using System.Runtime.Serialization.Formatters.Soap;
       7    using System.Text;
       8    using System.Xml;
       9
      10    using Microsoft.Practices.EnterpriseLibrary.Common;
      11    using Microsoft.Practices.EnterpriseLibrary.Configuration;
      12
      13    /// <summary>
      14    /// SoapSerializerTransformer is a custom Serialization Transformer for Microsft Enterprise Library 1.0.
      15    /// </summary>

      16    public class SoapSerializerTransformer : TransformerProvider
      17    
      18        public override void Initialize(ConfigurationView configurationView)
      19        {
      20            // Do nothing. This implementation does not require any additional configuration data because SoapFormatter reflects types 
      21            // during serialization.
      22        }

      23
      24        public override object Serialize(object value)
      25        {
      26            SoapFormatter soapFormatter = new SoapFormatter();
      27            StringBuilder stringBuilder = new StringBuilder();
      28            XmlDocument doc = new XmlDocument();
      29
      30            stringBuilder.Append("<soapSerializerSection>");
      31
      32            string serializedObject = "";
      33            using (MemoryStream stream = new MemoryStream())
      34            {
      35                soapFormatter.Serialize(stream, value);
      36                byte[] buffer = stream.GetBuffer();
      37                // quick fix for 0-byte padding
      38                serializedObject = ASCIIEncoding.ASCII.GetString(buffer).Replace('\0'' ').Trim();
      39            }

      40            stringBuilder.Append(serializedObject);
      41
      42            stringBuilder.Append("</soapSerializerSection>");
      43            doc.LoadXml(stringBuilder.ToString());
      44
      45            return doc.DocumentElement;
      46        }

      47
      48        public override object Deserialize(object section)
      49        {
      50            ArgumentValidation.CheckForNullReference(section, "section");
      51            ArgumentValidation.CheckExpectedType(section, typeof(XmlNode));
      52
      53            XmlNode sectionNode = (XmlNode)section;
      54
      55            XmlNode serializedObjectNode = sectionNode.SelectSingleNode("//soapSerializerSection");
      56            if (serializedObjectNode == null)
      57            {
      58                throw new ConfigurationException("The required element '<soapSerializationSection>' missing in the specified Xml configuration file.");
      59            }

      60
      61            SoapFormatter soapFormatter = new SoapFormatter();
      62            try
      63            {
      64                object obj = null;
      65                using (MemoryStream stream = new MemoryStream())
      66                {
      67                    using (StreamWriter sw = new StreamWriter(stream, Encoding.ASCII))
      68                    {
      69                        sw.Write(serializedObjectNode.InnerXml);
      70                        sw.Flush();
      71                        // rewind stream to the begining or deserialization will throw Exception.
      72                        sw.BaseStream.Seek(0, SeekOrigin.Begin); 
      73                        obj = soapFormatter.Deserialize(stream);
      74                    }

      75                }

      76                return obj;
      77            }

      78            catch (InvalidOperationException e)
      79            {
      80                string message = e.Message;
      81                if (null != e.InnerException)
      82                {
      83                    message = String.Concat(message, " ", e.InnerException.Message);
      84                }

      85                throw new ConfigurationException(message, e);
      86            }

      87        }

      88    }

      89}
       

      3.使用其它的Providers

             SQL Server Provider:使用數(shù)據(jù)庫SQL Server Provider

             Registry Provider:使用注冊表Provider

      四.保護配置信息:

      配置信息直接放在了XML文件里面是不安全,我們可以用加密應用程序塊對其進行加密,其實對于所有的應用程序塊的配置信息都可以進行加密,我們到加密應用程序塊時再詳細討論:)

      進階篇就寫到這里了,后面繼續(xù)剖析篇,在剖析篇里我會從配置應用程序塊的底層設計,到類設計等作一些介紹(個人理解^_^

      posted @ 2005-10-15 12:21  TerryLee  閱讀(16158)  評論(13)    收藏  舉報
      主站蜘蛛池模板: 久久综合色之久久综合色| 男女性杂交内射女bbwxz| 无码日韩做暖暖大全免费不卡| 日韩熟妇中文色在线视频| 国产亚洲情侣一区二区无| 狠狠色狠狠色综合日日不卡| 青青国产揄拍视频| 四虎国产精品永久地址99| 蜜桃在线一区二区三区| 亚洲欧洲一区二区精品| 国产农村乱人伦精品视频| 精品国产精品中文字幕| 巨胸不知火舞露双奶头无遮挡| 黄色亚洲一区二区在线观看| 天天爽夜夜爱| 乱中年女人伦av三区| 国产精品青草久久久久福利99 | 欧美人成精品网站播放| 国产乱人伦AV在线麻豆A| 浦北县| 四虎成人精品在永久免费| www久久只有这里有精品| 性色欲情网站| 久久人妻精品大屁股一区| 九九热在线视频中文字幕| 国产精品毛片av999999| 成人嫩草研究院久久久精品| 久久热这里这里只有精品| 国产精品久久久天天影视香蕉 | 国产综合亚洲区在线观看| 亚洲成人av综合一区| 精品国产三级在线观看| 国产偷国产偷亚洲综合av| 亚洲国产午夜理论片不卡| 蜜桃视频在线观看网站免费| bt天堂新版中文在线| 国产视频一区二区三区四区视频| 又黄又硬又湿又刺激视频免费| 屏山县| 日韩毛片在线视频x| 国产成人a在线观看视频免费 |