Websharp使用說明(6)

Websharp應用系統的配置

1、  緩存的配置

Websharp使用了微軟的Cached Application Block來緩存數據,因此,下面的緩存信息必須在應用程序中添加。關於Cached Application Block,可以參見微軟的相關文檔。

<configuration>

     <configSections>

         <section name="CacheManagerSettings" type="Microsoft.ApplicationBlocks.Cache.CacheConfigurationHandler,Microsoft.ApplicationBlocks.Cache" />

         <section name="WebsharpExpirationPolicy" type="Websharp.Service.WebsharpCofigurationHandler,Websharp" />

     </configSections>

     <CacheManagerSettings>

         <!-- DATA PROTECTION SETTINGS

         Use DataProtectionInfo to set the assembly and class which implement

         the dataprotection interfaces for the cache.

         -->

         <DataProtectionInfo AssemblyName="Microsoft.ApplicationBlocks.Cache"

                                 ClassName="Microsoft.ApplicationBlocks.Cache.DataProtection.DefaultDataProtection"

                                 ValidationKey="Oci44OQ9C3xAdQ3/BMHpksPfzeTezLkXen/ahQ8T7nVk/KMgAFnssQJr00KUNhRso+MpLVwAinGep6i14X9M+A=="

                                 Validation="SHA1"/>                                                    

        

         <!-- STORAGE SETTINGS

         Use StorageInfo to set the assembly and class which implement

         the storage interfaces for the cache.

        

         Modes: InProc, OutProc

         -->

         <StorageInfo AssemblyName="Microsoft.ApplicationBlocks.Cache" ClassName="Microsoft.ApplicationBlocks.Cache.Storages.SingletonCacheStorage" Mode="InProc" Validated="true" Encrypted="true" RemotingUrl="tcp://localhost:8282/CacheService" />

         <!--StorageInfo AssemblyName="Microsoft.ApplicationBlocks.Cache" ClassName="Microsoft.ApplicationBlocks.Cache.Storages.SqlServerCacheStorage" Mode="InProc" ConnectionString="user id=sa;password=msljkdv1;Network=DBMSSOCN;DATABASE=cacheab;SERVER=msljksrv02" Encrypted="true" Validated="true" ApplicationName="Sports" RemotingUrl="tcp://localhost:8282/CacheService" /-->

         <!--<StorageInfo AssemblyName="Microsoft.ApplicationBlocks.Cache" ClassName="Microsoft.ApplicationBlocks.Cache.Storages.MmfCacheStorage" Mode="InProc" BasePath="c:/mmfcache/" Encrypted="true" Validated="true" MmfDictionarySize="1048576" RemotingUrl="tcp://localhost:8282/CacheService"/>-->

 

         <!--

              MmfDictionarySize - It is the size (in bytes) of the dictionary object (in MmfCacheStorage) used to store the references of cache items.

         -->

        

         <!-- SCAVENGING SETTINGS

              Use the ScavengingAlgorithm to set a class that will be executed when

              scavenging is performed.

         -->

        

         <ScavengingInfo AssemblyName="Microsoft.ApplicationBlocks.Cache" ClassName="Microsoft.ApplicationBlocks.Cache.Scavenging.LruScavenging" MemoryPollingPeriod="60" UtilizationForScavenging="80" MaximumSize="5"/>

         <!-- EXPIRATION SETTINGS

              Use the ExpirationCheckInterval to change the interval to check for

              cache items expiration. The value attribute is represented in seconds.

         -->

         <ExpirationInfo Interval="1" />

     </CacheManagerSettings>

     <WebsharpExpirationPolicy>

         <ExpirationPolicy ExpirationCheckInterval="60" AssemblyName="Microsoft.ApplicationBlocks.Cache" ClassName="Microsoft.ApplicationBlocks.Cache.ExpirationsImplementations.SlidingTime" />

     </WebsharpExpirationPolicy>

</configuration>

 

2、  系統持久化配置信息

配置PersistenceProperty,對於Web應用系統,可以在Global.asax中配置,對於Windows應用程序,可以在程序初始化時設置。

下面是設置的一個例子:

PersistenceProperty pp=new PersistenceProperty();

pp.ConnectionString="server=127.0.0.1;uid=sa;pwd=;database=logisticsDemo;";//數據庫連接字符串

pp.DatabaseType=DatabaseType.MSSQLServer;    //數據庫類型

pp.MapFileLocation=@"WebsharpTestLib,WebsharpTestLib.xml"; //XML定義文件的路徑

pp.MapFileLocationTye=MapFileLocationType.Assembly;        //XML文件路徑的類型

pp.UserID="sa";                 //數據庫用戶名,必須與數據庫連接字符串中的用戶名一致

pp.Password="";                 //數據庫用戶密碼,必須與數據庫連接字符串中的用戶密碼一致

ApplicationConfiguration.DefaultPersistenceProperty=pp;  //設置應用程序的默認配置屬性

配置信息的說明如下:

1)  數據庫連接字符串、用戶名和密碼的設置按照常規設置

2)  MapFileLocationTye指明XML映射文件的路徑類型,可以有三種類型:

a)         AbsolutePath:採用絕對路徑的形式,在這種情況下,MapFileLocation設置成絕對路徑的形式,如:“d:/apppath/xml”。

b)        VirtualPath:對於Web應用程序,可以設置爲虛擬路徑的形式,如“/MyWebApp/EntityDefinitions/”。

c)        Assembly:XML文件作爲資源文件被編譯。採用這種形式,需要將XML文件的生成操作屬性設置成“嵌入的資源”,這種情況下,MapFileLocation的格式爲:“AssemblyName,NameSpace”。例如,XML文件位於WebsharpTestLib項目的xml文件夾下面,MapFileLocation可以設置爲:WebsharpTestLib,WebsharpTestLib.xml

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章