CSDN博客

img windly81

Duwamish 7 初探——数据流程

发表于2004/7/7 21:20:00  250人阅读

Duwamish?7是微软的一个基于ASP.NET的分布式应用程序范例。?
???
??由于工作上的原因,本人不得不对其研究一二。有所心得,不敢独乐,故于此与众位分享之。一并探讨ASP.NET,万望众位达人不吝赐教,。?
???
??btw?在MSDN.NET中有其结构与流程详解,本人在此基础上总结心得,并对其中不甚明了之处做一补充,若有疑问可查阅之。?
???
??Duwamish的若干个核心文件:?
???
??SystemFramework/ApplicationAssert.cs?//?验证数据合法性?
??SystemFramework/ApplicationConfiguration.cs?//?定义读写配置的框架?
??Common/DuwamishConfiguration.cs?//?读写配置(通过ApplicationConfiguration)?
???
??以上是整个应用程序的框架核心,还有一个ApplicationLog.cs,作用和Configuration类似。?
???
??Web/web.config?//?应用程序配置文件?
??Web/PageBase.cs?//?Web窗体页基类,供aspx派生,其中定义了需要页面间共享的数据(如用户、订单信息,用属性定义)?
??Web/ModuleBase.cs?//?Web控件基类,供Module/*.ascx派生,其中定义了所有模块所需要的应用程序路径和其他共享信息(用属性定义)?
??Duwamish?7是一个很小的应用(相对于更多的商业应用),但是微软仍然将它的结构、框架、层次定义得十分复杂,使人不得不对其产生由衷的敬仰:?P?
???
??复杂么?说起来也并非难以掌握。?
???
??用户界面——Web?
??业务外观——BusinessFacade?
??业务规则——BusinessRules?
??数据访问——DataAccess?
???
??如此而已,一个严谨、清晰、易于维护的Web应用大都如此。我们以一个用户登录过程为例探究其数据流程。?
???
??Web/Secure/logon.aspx接受用户登录表单提交,触发Logon.LogonButton_Click事件(Web/Secure/logon.aspx.cs中204行)?
???
??Web/Secure/logon.aspx.cs中243行:?
???
??custData?=?(new?CustomerSystem()).GetCustomerByEmail(LogonEmailTextBox.Text,?LogonPasswordTextBox.Text);?
???
??BusinessFacade中CustomerSystem类(Business/Facade/CustomerSystem.cs)实现“用户账号存取接口”逻辑?
???
??其中BusinessFacade.GetCustomerByEmail()(Business/Facade/CustomerSystem.cs中45行)定义“通过Email读取用户信息”接口?
???
??Business/Facade/CustomerSystem.cs中58行:?
???
??using?(DataAccess.Customers?customersDataAccess?=?new?DataAccess.Customers())?
??{?
???dataSet?=?customersDataAccess.LoadCustomerByEmail(emailAddress);?
??}?
???
??DataAccess中Customers类(DataAccess/Customers.cs)实现“用户账号数据访问”逻辑?
???
??其中Customers.LoadCustomerByEmail()(DataAccess/Customers.cs中217行)定义“通过Email读取用户信息”接口——通过访问SQL?Server存储过程“GetCustomerByEmail”?
???
??DataAccess/Customers.cs中227行:?
???
??dsCommand.SelectCommand?=?GetLoadCommand();?
???
??DataAccess.Customers.GetLoadCommand()初始化存储过程及参数并返回其接口(DataAccess/Customers.cs中112行)?
???
??DataAccess/Customers.cs中119行:?
???
??loadCommand?=?new?SqlCommand("GetCustomerByEmail",new?SqlConnection?(DuwamishConfiguration.ConnectionString));?
???
??初始化存储过程。其数据库连接由Common.DuwamishConfiguration中ConnectionString属性获得。?
???
??Common中DuwamishConfiguration类(Common/DuwamishConfiguration.cs)定义了应用程序配置信息的访问接口(通过访问类的属性)?
???
??其中DuwamishConfiguration.ConnetionString属性提供“数据库连接字符串访问”接口?
???
??Common/DuwamishConfiguration.cs中151行:?
???
??public?static?String?ConnectionString?
??{?
???get?
???{?
???return?dbConnectionString;?
???}?
??}?
???
??Common/DuwamishConfiguration.cs中107行由默认值常量设置“数据库连接字符串”:?
???
??dbConnectionString?=?DATAACCESS_CONNECTIONSTRING_DEFAULT;?
???
??Common/DuwamishConfiguration.cs中107行由读取“应用程序配置文件”中相应设置“数据库连接字符串”:?
???
??dbConnectionString?=?ApplicationConfiguration.ReadSetting(settings,?DATAACCESS_CONNECTIONSTRING,?DATAACCESS_CONNECTIONSTRING_DEFAULT);?
???
??SystemFramework中ApplicaitionConfiguration类定义了配置读写接口(SystemFramework/ApplicationConfiguration.cs)?
???
??其中ApplicationConfiguration.ReadSetting定义“读取配置”接口?
???
??SystemFramework/ApplicationConfiguration.cs中190行:?
???
??public?static?String?ReadSetting(NameValueCollection?settings,?String?key,?String?defaultValue)?
??{?
???try?
???{?
???Object?setting?=?settings[key];?
???
???return?(setting?==?null)???defaultValue?:?(String)setting;?
???}?
???catch?
???{?
???return?defaultValue;?
???}?
??}?
???
??至此,一条从界面到数据库的通道就被顺利开通了。用户账户数据被一层一层地返回给界面,并由界面定义的逻辑去处理。?
0 0

相关博文

我的热门文章

img
取 消
img