基于bs的考試報-名信息處理系統(tǒng)畢業(yè)文件設(shè)計(論文+開題報告+中期檢查表+答辯),基于,bs,考試,信息處理,系統(tǒng),畢業(yè),文件,設(shè)計,論文,開題,報告,講演,呈文,中期,檢查表,答辯
ASP.NET 2.0 用戶模式
摘要
ASP.NET 2.0的新特性如成員人數(shù)、個性化以及外形輪廓都是基于一個新的的.NET模式——用戶模式。 這個用戶模式定義了一種簡易的插件體系,你能利用系統(tǒng)提供的用戶插件或者編寫自己的而不用重寫代碼也不用重新編繹整個的解決方案。該用戶模式良好的功能模塊劃分允許應用程序開發(fā)平臺支持不同的設(shè)備或者媒體的同類功能。在本文中,Kamran M Qamar 闡述了什么是用戶模式,什么時候使用它,什么樣的ASP.NET功能模塊會使用了它,怎樣創(chuàng)建自己的模式,最終,你怎樣在.NET 1.x 中使用模塊的優(yōu)點。
文章
介紹
事物是不斷發(fā)展變化的,這話對軟件工程領(lǐng)域特別適用,因為這里的變化是頻繁而且巨大的?,F(xiàn)在我們提出的解決方案正被新的技術(shù)挑戰(zhàn)著。然而,把這些新技術(shù)湊合在一起,建立解決方案并不總是可行的。軟件工程很早就已經(jīng)認識到了這點,并且已開始在它實施的商業(yè)活動中進行抽象以確保解決方案不被改變。
ASP.NET開發(fā)團隊在朝著縮短網(wǎng)絡(luò)應用開發(fā)時間的野心勃勃的目標前進的道路上,面臨著許多挑戰(zhàn).他們希望創(chuàng)建的解決方案不僅僅是簡易、嚴整而且是可擴展的。他們更看中的是因為它要是可升級的,容易使用的并且有著良好文檔支持的,內(nèi)部實現(xiàn)完全可控的。結(jié)論是進行一個新的設(shè)計,它必須是一個允許擴展和z和變程序應用進程的,同時還有一定的商業(yè)需求的。
乍一看,這種用戶模式的出現(xiàn)是作為一種抽象的模式的增強版本,事實上,它的好處并不止這么多,它是一個綜合單一、軍略以及配置組件的縮體。這個模式本身不是新技術(shù),也不是一種應用軟件,更應注意的是它的DotNetNuke and Log4Net,同時也非常徹底的應用到了它。ASP.NET 2.0逐漸的標準化它的方法并把它應用到主流的發(fā)展中去了。
正文接下來我將闡述在哪里我們可以使用到這種模式。然后我們再在運用ASP.NET 2.0 Beta一起探索應用程序的細節(jié)過程,為了做到這些,我將創(chuàng)建一個基于ASP.NET 2.0 Beta 版本的解決方案,然后我再認真介紹在使用這個版本時的詳細步驟,最終我將介紹ASP.NET 1.x的基本框架與ASP.NET 2.0的不同之處,因此,你可以從今天開始使用它,并且在激活它之后可以在它里面添加你寫的代碼。
這篇文章假設(shè)你已經(jīng)非常熟悉所設(shè)計的模式,尤其是抽象工廠與單一模式,如果不是這樣的話,我將建議你跳過這一步,只需要看一下文章的結(jié)尾的結(jié)論就可以了。
系統(tǒng)需求
先在你的機子上運行樣本代碼,代碼將是必要的:
· .NET Framework 2.0 Beta (CTP October 2004))
· Visual Studio 2005 or Visual Studio 2005 Express Editions (Web Developer, and Visual C# )
· Visual Studio 2003
· Internet Explorer
我們可在還面這個網(wǎng)址上找到我們要的:http://lab.msdn.microsoft.com/express/vwd/default.aspx
安裝并且運行這個程序代碼
所有文章中的樣品代碼都是用C#寫的,這個樣本代碼的下載包含兩個方面的問題:
· A VS.NET 2005 問題包含給用戶提供網(wǎng)關(guān)與網(wǎng)址工程。用戶的網(wǎng)關(guān)方案擁有所有的類,這些類可以員這些網(wǎng)關(guān)來進行支付,而網(wǎng)址工程則是為了測試應用程序同時還擁有為用戶所提供的信用卡。
· The VS.NET2003 問題則是包含兩個命名為ProviderModel 和TestProviderModel工程文件。第一個工程文件是一個庫,這個庫允許你在。NET1.x中進行用戶模式的執(zhí)行,而第二個則是使用這個庫來支付解決方案的所有的進程。這個解決方案更深入地使用了在第二個工程文件中為.NET 2.0定義的相同的類,當你注意到在這兩個類中中的指令沒有改變時,他們僅僅為不同的時間段來進行編譯,第二個工程文件是作為一個應用程序而創(chuàng)建的,這個文件顯示了整個用戶模式可以在窗口與網(wǎng)頁中使用它。
問題的代理模式
一個成功的軟件是與它的可擴展的性能是成正比的,如果一個軟件獨立于怎樣去創(chuàng)建、組成、提出它自己的特點,那么這個解決方案在將來可以升級。這種放縱的聯(lián)合允許我們將來根據(jù)需要地來使用這種解決方案。我們將在以下幾種情況下考慮:
· 系統(tǒng)說明書寫的不是很清楚并且這個系統(tǒng)經(jīng)常的改變。
· 系統(tǒng)需要處理相同類型的事物但是不能在運行程序的時候處理實型。
· 系統(tǒng)的應用方面經(jīng)過一段時期將會有所擴展。
這些都是基本的需求,同時人們應用了各種不同的方法來解決這個問題,有一伙人地在解決這個問題的時候提出了一種模式 ,他們把這種模式就叫做虛擬工廠模式。而這種模式的目的是為了:"為了提供一個為創(chuàng)建一組相互有聯(lián)系但又相互獨立的統(tǒng)一體,但又沒有定義具體的類。"
虛擬工廠模式提供了一個提取層,但是,這種方法也有其局限性,更重要的是:
1. 這是一種基于解決方案的代碼。這個工廠的類需要了解一些具體的、必須創(chuàng)建的類是什么,如果這些解決方案可以觀察通過增加一些接口應用程序來進行擴展,那么,至少我們可以從核心內(nèi)容中對這個工廠進行更新。
2. 那個基于合作方法的接口的用途限制了解決方案的性能,如果接口的需求被改變了,那么所有的舊的代碼將會要重新寫入,因此,我們不能在核心技術(shù)中很容易的增加某些新的功能。
用戶模式的解決方案
一種最理想的解決方案,我們不需要每次更改工廠里每個類的核心代碼,我們只要在一些接口中增加新的功能模塊,我們也可以使用一種遺傳算法來連接到接口上去,從制作一種更新的代碼時就實施一種最為普通的API來保護我們自己的信息。
這種用戶模式確實做到了這一點,它使用了最簡單的、最基本的應用配置來增加、清理、移除具體的沒有重新編譯的核心代碼的應用程序。這就像建立了一個鏈式的結(jié)構(gòu)體系,而這個體系可以根據(jù)需要進行擴展。ASP.NET 2.0提供了 SQL and Access provider 作為可以互換成員對象,但是,如果你想從經(jīng)典的ASP或者ASP.Net 1.x中退出,并且已經(jīng)有了通俗的成員對象數(shù)據(jù)庫,那么它就不能中止,而且,你還可以根據(jù)需要來重新設(shè)計它,還可以建立一個傳統(tǒng)的成員對象供給,同時應用它來代替對用戶透明的界面,最后我們可以在ASP.NET 2.0中掌握他的新的性能。
這種用戶模式使用界面來進行合作,或者很好地定義了API,就像在虛擬工廠模式中的接口一樣,此模式也允許完全控制在API中應用程序的工具,在我介紹怎樣使用ASP.NET 2.0之前,我們就是使用的這種擁有此種功能的模式我們也要了解這種模式中內(nèi)部是怎么工作的。
我們要不斷地他新的技術(shù)來更好地實現(xiàn)它。為了證明此點:我們怎么去實施基于解決方案的這種用戶模式,我將創(chuàng)建一個最簡單的信用卡用戶來控制使用這種模式,此模式可以由信用卡中的信息和使用一種網(wǎng)關(guān)來支付交易的過程對這種模式進行升級。被控制界面支持交付并且還可退款,我將創(chuàng)建兩個界面:一個只是用來支持處理信用卡和美國特殊的卡,而另一個也是用來支持這些但還可以處理一些額外的、不同作用的卡。這些界面是很簡單的,而且它們不能帶進賬戶里那些復雜的比如商物鑒定等。額外的邏輯性能可以控制怎么從一些基于卡類型的界面中選取正確的界面。在我跳過講述解決方案應用程序之前,讓我們來看看怎么樣完成這個產(chǎn)品的外觀的。圖1顯示了在失職時的實施控制圖,如果你試著去支付信用卡或者主卡,它將處理使用網(wǎng)關(guān)的途徑來對它進行支付,你就能在最底部注意到他們的交換ID是什么。
圖 1. The rendered Credit Card Control Charging Visa Card.
當你們試著用信用卡來支付,調(diào)節(jié)裝置將自動來選出擇一種最有效的網(wǎng)關(guān)途徑來進行支付,這種情況如圖2所示。
圖 2. The rendered Credit Card Control Charging Discover Card.
由于這篇文章重點是放在用戶模式之上,所以我將只討論有關(guān)用戶模式相關(guān)的代碼,然而,所有的相關(guān)控件源代碼都是可以下載到的。
代碼的執(zhí)行
ASP.NET 2.0關(guān)于用戶模式的代碼執(zhí)行情況是相當直接的。然而它設(shè)置某種規(guī)則,這種規(guī)則必須按照應用程序的執(zhí)行而制定的。 當我介紹這種簡單的試例之前,我將討論下這幾種規(guī)則:
規(guī)則1: 很好的定義合作關(guān)系
用戶模式必須使用一個抽象類來定義協(xié)議,該抽象類必須從System.Configuration.ProviderBase 繼承??蚣芙M使用了ProviderBase 類來把所有內(nèi)部結(jié)構(gòu)進行垂直劃分以便支持用戶的下層構(gòu)造(提供二級緩存和配置).通過對該類的繼承,它自動成為了用戶模式的組成部分,而不需要建立框架組。
用戶模式(協(xié)議類)應該定義所有的方法和屬性,只要它們是作為公共接口的功能實現(xiàn)內(nèi)核所需要。這個基礎(chǔ)類應該僅僅含有最少的功能函數(shù)集合,因此必須鼓勵執(zhí)行函數(shù)通過他們的方式提供真實參數(shù).
按照以上規(guī)則, PaymentGatewayProvider類的可能實現(xiàn)如下::
public abstract class PaymentGatewayProvider : ProviderBase
{
public abstract string ChargeCard(CrediCard card, double amount);
public abstract bool Refund(CreditCard card, double amount);
public abstract string[] SupportedCardTypes{get;}
}
用戶模式類抽象和繼承自ProviderBase . 該類發(fā)布了控制用的應用程序接口(API)。該接口的實現(xiàn)是獨立于控制核心函數(shù)之外的。
規(guī)則2: 唯一標志
每一個用戶模式都有唯一的一個標志名。
ASP.NET 2.0比為部件所作準備的軟件支持更多的程序,例如,為通過網(wǎng)關(guān)支付方式的方案。你可以像.NET、一次性或者其它的支付手段那樣對它進行處理,同時我們還可以為每個進程創(chuàng)建一個具體的界面。這個主框架可以讓我們跟任何人打招呼,或者所有的人使用這個界面為大家所創(chuàng)的戶頭,這個戶頭是作為身份識別而被使用的,因此,它必須是唯一確定的。通過繼承ProviderBase ,用戶界面定義了一個只讀戶頭作為私人財產(chǎn),所有的具體的應用程序的執(zhí)行都得通過它,產(chǎn)生合適的用戶名,而這個用戶名則是由提供都確定的唯一的用戶名。
規(guī)則3:配置信息
程序的配置信息就像一個有用的那個制造那個程序的提供者一樣,并且他們的初始值在程序運行配置文件時都應該被保護起來,而具體的應用程序則必須知道怎樣去初始化它。
一旦這個為部件或者是應用程序性能的用戶界面建立起來,你就得在使用它之前在用戶配置文件中對它進行說明,你可以為主程序相同的性能中,在用戶配置文件中定義一個全局變量, 一個主程序能有其自己的初始值或者通過配置文件來對它進行初始化,這種用戶模式配置的語法規(guī)則在聲明中可以允許你來定義它們的值來作為名字與值相對應,通常的語法規(guī)則被描述為:
The ASP.NET 2.0 Provider Model
Abstract
ASP.NET 2.0?s new features like Membership, Personalization, and Profiles are all based on a new model to .NET - The Provider model. The Provider model defines an easy plug-n-play architecture. You can use custom providers or write your own providers and use them without re-writing, re-compiling the entire solution. The provider model neatly distributes the functionalities hence allows parallel development of applications to support different devices or medium for the same functionality. In this article, Kamran M Qamar will explain what the provider model is, when it should be used, which functionalities in ASP.NET are using it, how you can create your own providers and finally how you can architect your own solution to reap the benefits of the Provider Model today, using .NET 1.x.
Article
Introduction
One thing that is constant is change. This is especially true for software industry where change is very often and swift. The solutions we create today are challenged by each new technology. Whereas, building a solution from scratch to incorporate these new developments is not always feasible. Software architects have learnt this early in the game and started abstracting the business behavior from its implementation to protect their solutions from change.
The ASP.NET team has been faced with many challenges while working toward the ambitious goal of reducing the development time for web developers. They wanted to create a solution that is not only simple and elegant but also extendable. More specifically they wanted a scalable, easy to use and well documented system with full control over its internal implementations. The result is a design which is termed the Provider Model that allows you to extend or change the behavior of an application or control based on the business requirements.
At first glance, the Provider Model appears as an enhanced version of the Abstract Factory Pattern . In reality it is more then that. It is a system in itself which incorporates a number of patterns like the Singleton , the Strategy , and Component Configurator patterns. The Provider Model itself is not new, a number of applications, most notable DotNetNuke and Log4Net, have been successfully using it for quite sometime. ASP.NET 2.0 standardizes the approach and brings it to mainstream development.
In the text to come, I will be explaining where you should use the Provider Model. Then I will explore the implementation details as they are implemented in the ASP.NET 2.0 Beta. To do this I will build a Payment Gateway solution based on the Provider Model. Next I will look into the issues in using the Provider Model and finally I will introduce a Provider Model framework for ASP.NET 1.x mimicking it against ASP.NET 2.0 so you can start using it today and be able to port your code to ASP.NET 2.0 when it goes live.
This article assumes you are familiar with design patterns, especially Abstract Factory and Singleton Patterns. If not, I would encourage you to skim through the links in the Related Links section at the end of this article.
System Requirements
To run the sample code for the sample you will need:
· .NET Framework 2.0 Beta (CTP October 2004))
· Visual Studio 2005 or Visual Studio 2005 Express Editions (Web Developer, and Visual C# )
· Visual Studio 2003
· Internet Explorer
You can download Visual Studio 2005 Express Editions from http://lab.msdn.microsoft.com/express/vwd/default.aspx
Installing and Compiling The Sample Code
All the sample code for the article has been written in C#. The sample download for this article contains two solutions.
· A VS.NET 2005 solution containing ProviderGateway and Web project. The ProviderGateway solution has all the classes that implement the payment gateway providers. The Web project is the test application and has the Credit card control that uses these providers.
· The VS.NET2003 solution contains two projects named ProviderModel and TestProviderModel. The first is a library that allows you to implement Provider Model in .NET1.x. The TestProviderModel uses this library to implement the payment processor solution. This project further uses the same classes as defined in ProviderGateway project for .NET 2.0. As you will notice there is no change in the two class set, they are just compiled for different runtimes. The test project is built as a console application that shows that the Provider Model could be used both for Windows and Web applications.
The Problem Abstract Factory Pattern
Softwares success is directly proportional to its extensibility features. If the software is independent of how its constituent pieces are created, composed and presented, the solution will be more scalable going forward. This loose coupling will allow us to expend the solution as needed in the future. Consider the situations where:
· The system specifications are not clear and continuously changing.
· The system needs to handle objects of same type but the actual type is known only at run time.
· The system implementation will be extended over a period of time.
These are very common requirements and people have solved these problems in a number of different ways. The Gang of four (See the Related Links Section) spotted a pattern in solutions for these problems. They named it the Abstract Factory Pattern . The intent of this pattern is:
"To provide an interface for creating families of related or dependent objects without specifying their concrete classes"
The Abstract Factory Pattern provides an abstraction layer but there are a number of limitations with this solution, most importantly:
3. It is a code based solution. The Factory class need to know what concrete classes are available that could be created. If the solution is extended by adding new implementations of the interface then at minimum we have to update the Factory class from the core.
4. The use of an Interface based contract approach limits the solutions functionality. If the interface is required to be changed, all the old code will break thus we cannot easily add new functionalities in core implementation.
The Solution The Provider Model
The ideal solution is the one where we do not have to change the core implementation of the Factory class each time we add a new implementation of the interface. We can also use the chain of inheritance as compare to Interface, to publish a common API to protect ourselves from having to make contract updates.
The Provider Model does exactly this. It uses standard application configuration files to add, clear or remove a concrete implementation to the solution without recompiling the core. This creates a plug-n-play architecture which could be extended as needed. For instance, ASP.NET 2.0 provides SQL and Access provider for membership which is interchangeable. But it does not stop here, if you were porting an existing application from classic ASP or ASP.Net 1.x and already have custom membership database, then you do not need to redesign it, you can create a custom Membership provider and use it instead of the out-of-box providers and still reap the benefits of all the features of ASP.NET 2.0.
The Provider Model uses the Provider to publish the contract or the well defined API just like interface in the Abstract Factory Pattern. The model also aloows full control to the implementer in implementing the API. Before I show how ASP.NET 2.0 uses this model in its own functionalities, you need to understand the inner workings of the model.
To get a hold on new technology is to apply it. To demonstrate, how to implement the Provider Model based solutions, I will create a simple CreditCard user control using the Provider Model. The control will prompt for credit card information and process the transaction using one of the Payment Gateway providers. The provider for this control will support charge and refunds only. I will create two providers, one of them (PayPalPaymentGatewayProvider) will support processing of Visa, Master and American Express cards only and the other (ANetPaymentGatewayProvider) will support these and additionally the Discover card. The providers are very simple and do not take into account the complexity such as merchant verification. Extra logic will be in the control to choose the correct provider based on the card type. Before I jump into the implementation of the solution, lets see how the finish product looks. Figure 1 shows the rendered control in default mode, if you try to charge a Visa or Master card it will process the request using PayPalPaymentGatewayProvider, you can notice that by the returned transaction id displayed at the bottom.
Figure 1. The rendered Credit Card Control Charging Visa Card.
When you try to charge using a Discover card, the control will automatically choose ANetPaymentGatewayProvider as shown in Figure 2.
Figure 2. The rendered Credit Card Control Charging Discover Card.
Since this article is concentrating on the Provider Model, I will discuss only the relevant Provider Model sections of code. However, full source code of the control is available in download.
The Implementation
ASP.NET 2.0s implementation of the Provider Model is very straight forward. However it does set certain rules that must be followed to implement it. As I develop the sample I will discuss each of these rules:
Rule 1: Well Defined Contract
The Provider must define the contract using an abstract class and that must be inherited from System.Configuration.ProviderBase . The framework uses the ProviderBase class for all the internal plumbing to support the provider infrastructure (provider caching and configuration). By inheriting from this class it automatically becomes the part of the Provider Model built within the framework.
The Provider (contract class) should define all the methods and properties that it requires to implement the core functionalities as the public API. The base class should have only the minimum set of required functionalities, hence to encourage the implementers to provide real value by their concrete providers.
Following this rule, the PaymentGatewayProvider class can be seen below:
public abstract class PaymentGatewayProvider : ProviderBase
{
public abstract string ChargeCard(CrediCard card, double amount);
public abstract bool Refund(CreditCard card, double amount);
public abstract string[] SupportedCardTypes{get;}
}
The provider class is abstract and inherits from ProviderBase . The class publishes the API that the control will use. The implementation of this API is independent of the controls core functionality.
Rule 2: Unique Name
Each provider has to have a unique name
ASP.NET 2.0 supports more than one provider for a component. For example, for the PaymentGatewayProvider you can have processors like Authorize.NET, PayPal or any other leading bank and create a concrete provider for each kind of processor. The framework will then let you make a call to anyone or all of them using the name of the provider. The providers name is used as the identification key, therefore it should be unique. By virtue of inheriting from ProviderBase , the provider has a read-only Name property. All the concrete implementations have to override it and return the appropriate name that uniquely identifies the provider.
Rule 3: Configuration Information
The Provider configuration information, like available providers, and their initialization values should be maintained in an application configuration file ( Web.config for an ASP.NET application and App.config for a Windows application). The concrete implementation of the Provider should know how to initialize itself.
Once the provider for a component or application feature is created, you have to describe it in the configuration file before it can be used. You can define an unlimited number of providers in the configuration section for the same feature. A provider can itself have initialization values or use configuration files to configure itself. The Provider Model configuration syntax allows you to define the values as name-value pairs within the declaration. The General syntax to describe the provider is shown below:
19