Websharp使用说明(6)

类别:.NET开发 点击:0 评论:0 推荐:

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

本文地址:http://com.8s8s.com/it/it45130.htm