欢迎大家光临【无师自通-教程网】您的到来是我们的荣幸。本站提供photoshop教程,ps教程,flash教程,cad教程,网页制作教程,excel教程,asp教程,vb教程,3d教程,c语言教程,html教程,coreldraw教程,dreamweaver教程,java教程,3dmax教程 等各种教程为主题的内容和服务,相信您会在这里找到您所需要的东东。无师自通伴您一生-谢谢您的光临!!
网站地图 设为首页
简繁切换 加入收藏
栏目待定 留言本站
您现在的位置: 无师自通-教程网 >> WEB开发 >> ASP.NET教程 >> .NET Framework >> 教程正文

  没有公告

教程: ASP.NET教程-.NET Framework-Websharp使用说明 更多...
教程: ASP.NET教程-.NET Framework-Websharp使用说明

trans.Rollback();

}

finally

{

pm.Close();

}

对象的查询

Websharp提供了对对象查询的功能,这个功能通过Query接口提供。Query接口的定义可以见:附1:Websharp主要接口定义——Query

可以通过下面的办法来使用Query接口:

PersistenceManager pm=PersistenceManagerFactory.Instance().CreatePersistenceManager(pp);

Query q=pm.NewQuery("Product");

q.Filter="ProductID='P001'";

q.Open();

EntityData entity=q.QueryData();

dataGrid1.DataSource=entity;

q.Close();

pm.Close();

Websharp也提供了直接操纵数据库的数据访问接口——DataAccess,这个接口对ADO.Net进行了一些封装,可以使程序员更加容易的使用ADO.Net的功能,并且能够屏蔽不同数据库之间的差别。这个接口的定义可以见:附1:Websharp主要接口定义——DataAccess

能够通过PersistenceManager的NewDataAccess方法来初始化一个DataAccess对象,然后调用相应的办法来执行需要的功能。

业务逻辑的处理

有了上面的工作,我们就可以把这些对象组合起来,编写我们的业务逻辑。在面向对象的系统中,业务逻辑表现为对象之间的交互。在一些简单的系统中,没有复杂的业务逻辑,只是一些数据的维护工作,那么,有了上面两个部分的工作,我们实际上可能已经忘成了大部分的工作。

下面是一个简单的例子,表示了一张入库单入库的过程,在这个过程中,需要修改入库单上每种产品的现有库存量:

public void StoreIntoWarehouse(Form insertForm)

{

FormDetail detail=insertForm.FormDetail;

detail.First();

PersistenceManager pm = PersistenceManagerFactory.Instance().CreatePersistenceManager();

Transaction tm=pm.CurrentTransaction;

tm.Begin();

try

{

if(detail.ObjectCount>0)

{

do

{

Product product=(Product)pm.FindObjectByPrimaryKey

(detail.ProductID,Type.GetType

("LogisticsDemo.EntityDefinitions.Product"));

product.CurrentCount =detail.InCount;

pm.UpdateObject(product);

}while(detail.Next());

}

pm.PersistNewObject(insertForm);

tm.Commit();

}

catch(Exception e)

{

tm.Rollback();

throw e;

}

finally

{

pm.Close();

}

}

可以看到,在使用Websharp后,对于业务逻辑的编写,可以变成一个非常自然的过程,也能够节省很多代码量。

业务服务的提供

业务外观层(Business Facade)的目的,是隔离系统功能的提供者和使用者,更明确地说,是隔离业务逻辑的软件的用户界面(可以参见Facade设计模式)。可以使用现有的任何方法来构建构建这个层次,在我们提供的例子中,我们使用了Web Service。

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”

附1:Websharp主要接口定义:

PersistenceCapable:

public interface PersistenceCapable

{

EntityData EntityData{get;set;}

int ObjectCount{get;}

void AddNew();

bool Next();

void First();

}

PersistenceManager:

public interface PersistenceManager : IDisposable

{

void Close();

bool IsClosed{get;}

Transaction CurrentTransaction{ get;}

bool IgnoreCache{get;set;}

void PersistNewObject(EntityData entity);

void PersistNewObject(PersistenceCapable pc);

void UpdateObject(EntityData entity);

void UpdateObject(PersistenceCapable pc);

void DeleteObject(EntityData entity);

void DeleteObject(PersistenceCapable pc);

void Reload(EntityData entity);

void Reload(PersistenceCapable pc);

void Evict (object pc);

void EvictAll (object[] pcs);

void EvictAll (ICollection pcs);

void EvictAll ();

EntityData FindEntityDataByPrimaryKey(object id,string entityTypeName);

EntityData FindEntityDataByPrimaryKey(object id,EntityData entity);

PersistenceCapable FindObjectByPrimaryKey(object id,PersistenceCapable pc);

PersistenceCapable FindObjectByPrimaryKey(object id,Type entityType);

Query NewQuery();

Query NewQuery(string entityTypeName);

Query NewQuery(string entityTypeName,string filter);

Query NewQuery(string entityTypeName,string filter,QueryParameterCollection paramColletion);

DataAccess NewDataAccess();

}

Transaction:

public interface Transaction

{

void Begin();

void Commit();

void Rollback();

PersistenceManager PersistenceManager{get;}

}

Query:

public interface Query

{

string EntityTypeName{get;set;}

string Filter{get;set;}

QueryParameterCollection Parameters

{

get;

set;

}

string Ordering{get;set;}

bool IgnoreCache{get;set;}

EntityData QueryData();

PersistenceCapable QueryObject(PersistenceCapable ps);

EntityData LoadSubObject(EntityData entity,string subTypeName);

PersistenceCapable QueryObject(PersistenceCapable ps,string subTypeName);

EntityData LoadSubObjects(EntityData entity);

PersistenceManager PersistenceManager{get;}

bool QuerySubObjects{get;set;}

bool IsClosed{get;}

void Close ();

void Open();

}

DataAccess:

public interface DataAccess

{

#region Support Property & Method

DatabaseType DatabaseType{get;}

IDbConnection DbConnection{get;}

PersistenceManager PersistenceManager{get;}

IDbTransaction BeginTransaction();

void Open();

void Close();

bool IsClosed{get;}

#endregion

#region ExecuteNonQuery

int ExecuteNonQuery(CommandType commandType, string commandText);

int ExecuteNonQuery(string commandText);

int ExecuteNonQuery(string commandText, QueryParameterCollection commandParameters);

int ExecuteNonQuery(CommandType commandType, string commandText, QueryParameterCollection commandParameters);

#endregion ExecuteNonQuery

#region ExecuteDataSet

DataSet ExecuteDataset(CommandType commandType, string commandText);

DataSet ExecuteDataset(string commandText);

DataSet ExecuteDataset(CommandType commandType, string commandText, QueryParameterCollection commandParameters);

DataSet ExecuteDataset(string commandText, QueryParameterCollection commandParameters);

DataSet ExecuteDataset(CommandType commandType, string commandText,string tableName);

DataSet ExecuteDataset(string commandText,string tableName);

DataSet ExecuteDataset(CommandType commandType, string commandText, QueryParameterCollection commandParameters,string tableName);

DataSet ExecuteDataset(string commandText, QueryParameterCollection commandParameters,string tableName);

DataSet ExecuteDataset(CommandType commandType, string commandText,DataSet ds);

DataSet ExecuteDataset(string commandText,DataSet ds);

DataSet ExecuteDataset(CommandType commandType, string commandText, QueryParameterCollection commandParameters,DataSet ds);

DataSet ExecuteDataset(string commandText, QueryParameterCollection commandParameters,DataSet ds);

DataSet ExecuteDataset(CommandType commandType, string commandText,DataSet ds,string tableName);

DataSet ExecuteDataset(string commandText,DataSet ds,string tableName);

DataSet ExecuteDataset(CommandType commandType, string commandText, QueryParameterCollection commandParameters,DataSet ds,string tableName);

DataSet ExecuteDataset(string commandText, QueryParameterCollection commandParameters,DataSet ds,string tableName);

#endregion ExecuteDataSet

#region ExecuteReader

IDataReader ExecuteReader(CommandType commandType, string commandText);

IDataReader ExecuteReader(string commandText);

IDataReader ExecuteReader(CommandType commandType, string commandText, QueryParameterCollection commandParameters);

IDataReader ExecuteReader(string commandText, QueryParameterCollection commandParameters);

#endregion ExecuteReader

#region ExecuteScalar

object ExecuteScalar(CommandType commandType, string commandText);

object ExecuteScalar(string commandText);

object ExecuteScalar(CommandType commandType, string commandText, QueryParameterCollection commandParameters);

object ExecuteScalar(string commandText, QueryParameterCollection commandParameters);


[4] [5] [6] [7] [8]

上一页  [1] [2] [3] [4] [5] [6] [7] [8] 下一页

教程录入:admin    责任编辑:admin 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     
     
     
     

    asp连接mysql数据库

    asp连接mysql数据库-2

    frontpage2000教程---制作主页
    免责声明!本站资料大部分来自于互联网,其版权归原作者或其他合法者所有.如内容涉及或侵犯了您的权益,请通知本人,我将尽快处理!.欢迎您的光临。
    辽ICP备07003958号
    无师自通,伴你一生-教程网