Duwamish in-depth analysis

Source: Internet
Author: User
Tags configuration settings connection reset
Structure

Abstract:

This article introduces in detail the structure framework of duwamish online e-bookstore routine, and analyzes in detail some features and design patterns of this structure.


--------------------------------------------------------------------------------

Directory:

Introduction

Duwamish Introduction

Structure Analysis

Design Philosophy

Code Example

Summary

Author


--------------------------------------------------------------------------------

Introduction:

Can be used as Visual Studio. net. duwamish must include Microsoft. the net design team wants to send some information to developers. In fact, duwamish can indeed be called. A classic example of net developer learning, whether from its design architecture, programming skills or code style, shows us a standard. NET Enterprise Applications Program Features. Therefore, by studying duwamish examples, the experts can understand the design idea of. NET application architecture, and the low-handed can learn. NET programming skills, which is really suitable for all ages. :)

However, the purpose of this article is more targeted at intermediate. net learners. These readers are often familiar with C # Or VB. net syntax, some basic class libraries will be used, and some small programs will be made. However, when they started to develop an enterprise-level application with real practical value, they had a feeling of nowhere to start. If you happen to belong to this kind of learners, please follow me into the duwamish world and I believe you will surely get the harvest.


--------------------------------------------------------------------------------

Duwamish introduction:

Every time Microsoft launches a new technology, it will always launch some public Source code And developers can quickly master and implement the new technology by studying the code of the new technology. Microsoft creates a virtual online sales system application for an e-commerce company that sells books online, demonstrate to users the most common e-commerce enterprise-to-customer (B2C) model in typical online shopping practices, it includes basic functions such as membership, account management, shopping cart, search and checkout process. Duwamish has gone through three versions: 4.0, 5.0, and 7.0. The release of each version confirms the technological progress. Each version represents the most advanced technology trend at that time. The most recent duwamish version 7.0 will be studied and discussed here. It has gone through the COM/COM + technology and the duwamish of Microsoft DNA architecture, and is fully used in the latest version. NET technology and architecture, more advanced and mature than before.




If you have installed Visual Studio. net, you can.. NET Enterprise Samples Directory, such as: C: \ Program Files \ Microsoft Visual Studio. net \ enterprise samples \, or you can go to http://astradigital.com/duwamis#vb/to view a demo of the workshop in internet. For more information about duwamish, see Visual Studio. net with the msdn help address: MS-help: // Ms. VSCC/MS. msdnvs.2052/dwamish7/html/vtoriduwamishbooks70.htm.


--------------------------------------------------------------------------------

Duwamish structure analysis:

Duwamish 7.0 is a typical N-layer architecture with four logical layers:

Web Layer

The web layer provides clients with access to applications. This layer is implemented as a web project in the duwamish. sln solution file. The web layer consists of ASP. NET web forms and hidden code files. Web forms only use HTML to provide user operations, while code hidden files implement event processing for various controls.

Business appearance Layer

The business appearance layer provides an interface for the web layer to process accounts, category browsing, and book purchases. This layer is implemented as the businessfacade project in the duwamish. sln solution file. The business appearance layer is used as the isolation layer, which isolates the user interface from the implementation of various business functions. Except for low-level systems and support functions, all calls to the database server are performed through this assembly.

Business Rule Layer

The business rule layer is implemented as the businessrules project in the duwamish. sln solution file. It contains the implementation of various business rules and logic. Business Rules complete tasks such as verifying customer accounts and book orders.

Data access layer

The data access layer provides data services for the business rule layer. This layer is implemented as the dataaccess project in the duwamish. sln solution file.

What is confusing is the business appearance layer and business rule layer. Many people hear the most about the layer-3 structure when learning the layer-N structure development, which is the presentation layer, middle Layer and data layer. Duwamish's web layer and data access layer are easy to understand, that is, the traditional presentation layer and data layer, what is the relationship between the business appearance layer and the business rule layer and the intermediate layer that we are familiar?


--------------------------------------------------------------------------------

Design Philosophy:

In Web applications, some operations simply extract data from the database based on conditions and directly display the data to the webpage without any processing, for example, you can query a list of books of a certain type. Other operations, such as calculating the total price of books in an order and calculating kickbacks based on the customer's level, usually have many different functional classes and the operations are complicated. We can first imagine that if we adopt a three-tier structure, these commercial logic will generally be placed in the middle layer, then there will be a wide variety of internal, the Calling tasks of different classes with different usage methods are completely implemented in the presentation layer. This will inevitably increase the amount of code in the presentation layer, complicate the tasks in the presentation layer, and is not commensurate with the tasks in which the presentation layer only accepts user input and returns results, it also increases the coupling between layers.

To solve this problem, let's take a look at the description of the facade mode in design patterns:

Intent:

Provides a consistent interface for a group of interfaces in the subsystem. The facade mode defines a high-level interface, which makes the subsystem easier to use.

Applicability:

When you want to provide a simple interface for a complex subsystem. Subsystems tend to become more and more complex as they evolve. In most modes, More and smaller classes are generated. This makes subsystems more reusable and easier to customize, but it also brings some difficulties for users who do not need to customize subsystems. Facade can provide a simple default view, which is sufficient for most users, and users who need more customization can bypass the facade layer.

There is a large dependency between the implementation part of the client program and the abstract class. Introducing facade to separate this subsystem from customers and other subsystems can improve the independence and portability of the subsystem.

When you need to build a layered sub-system, use the facade mode to define the entry points for each layer of the sub-system. If subsystems are mutually dependent, you can make them communicate only through facade, thus simplifying the dependency between them.

Structure:




The contradiction mentioned above is exactly the same as the problem to be solved in the facade mode described in the design mode. The solution proposed in the design mode is to introduce a facade object, let this fa c Ade be responsible for managing calls to internal classes of the system, and provide a single and simple interface for the presentation layer. This fa C Ade object is the businessfacade (Business appearance) layer in our duwamish design.

The following is the duwamish structure diagram:




We can clearly see that the browser first calls the presentation layer Web, then the Web sends the request to the business appearance layer, and the Business appearance layer initially processes the request, determine whether to call the business rule layer or directly call the data access layer to obtain data. Finally, access the database at the data access layer and return the results to the browser according to the following steps (other structure modules involved in the figure will be described in detail later ).


--------------------------------------------------------------------------------

Sample Code:

The following is a sample code for two different processing paths:

Get product catalog

The presentation layer calls the business appearance layer:

Productsystem = new productsystem ();

Categoryset = productsystem. getcategories (categoryid );

The business appearance layer directly calls the data layer:

Public categorydata getcategories (INT categoryid)
{
If (dscommand = NULL)
{
Throw new system. objectdisposedexception (GetType (). fullname );
}
Return fillcategorydata ("getcategories", "@ categoryid", categoryid );
}

Add order

The presentation layer calls the business appearance layer:

Public void addorder ()
{
Applicationassert. checkcondition (cartorderdata! = NULL, "Order requires data", applicationassert. linenumber );
Applicationlog. writetrace ("duwamish7.web. Cart. addorder: \ r \ ncustomerid:" +
Cartorderdata. Tables [orderdata. customer_table]. Rows [0] [orderdata. pkid_field]. tostring ());
Cartorderdata = (New ordersystem (). addorder (cartorderdata );
}

The business appearance layer calls the business rule layer:

Public orderdata addorder (orderdata order)
{
Applicationassert. checkcondition (order! = NULL, "order is required", applicationassert. linenumber );

(New businessrules. Order (). insertorder (order );
Return order;
}

The business rule layer calls the data layer:

Public bool insertorder (orderdata order)
{
// The complex processing logic is omitted here
If (isvalid)
{
Using (dataaccess. Orders ordersdataaccess = new dataaccess. Orders ())
{
Return (ordersdataaccess. insertorderdetail (Order)> 0;
}
}
Else
Return false;
}


--------------------------------------------------------------------------------

Summary:

By analyzing the structure design of duwamish7, we have mastered the fa c Ade mode and learned how to improve the application structure through the fa c Ade mode, at the same time, I learned about the basic concepts and processes of duwamish7, which laid a foundation for further analysis and study of other parts of duwamish7.

Configuration

Abstract:

This article describes in detail the structure and usage of the web. config configuration file of duwamish online e-bookstore, and describes the functions of the configuration file modules.


--------------------------------------------------------------------------------

Directory:

Introduction

Configuration section handler Declaration

Custom configuration section

Configuration section Handler

Summary

References

Author


--------------------------------------------------------------------------------

Introduction:

In almost every book that introduces ASP. NET programming, when talking about how to manage database connection strings, database connection strings are stored in the web. config file in the following form:

<Deleetask>

<Add key = "connectionstring" value = "Data Source = localhost; initial catalog = database; user id =; Password ="/>

</Appsettings>

Then access in the program using the following methods:

System. configuration. configurationsettings. etettings ["connectionstring"]

The advantage of doing so is obvious: When the database changes, you only need to change the web. the connection string in config does not need to re-compile the entire application, which brings great convenience to Application Deployment and transplantation.

If you think Web. if config is used only for this purpose, you will be wrong, Web. the configuration function of config is very powerful. It supports the extension of standard ASP.. Net configuration set, which reflects its functions to a certain extent in duwamish. I will analyze the duwamish web in detail below. config file, so that you can understand a typical development. net web application configuration technology.


--------------------------------------------------------------------------------

Configuration section handler Declaration

In duwamish solution. the config file is stored in a web project because the web. config requires IIS and ASP. net runtime Management and Support, so it should be placed in a virtual directory, Let's first look at its first part:

<Configsections>

<Section name = "applicationconfiguration" type = "duwamish7.systemframework. applicationconfiguration, duwamish7.systemframework"/>

<Section name = "duwamishconfiguration" type = "duwamish7.common. duwamishconfiguration, duwamish7.common"/>

<Section name = "sourceviewer" type = "system. configuration. namevaluesectionhandler, system, version = 1.0.3300.0, culture = neutral, publickeytoken = b77a5c561934e089"/> </configsections>

Three sections are defined here, which must appear between the <configsections> and </configsections> labels at the top of the configuration file. Here, they only use the name and type attributes. The name attribute defines the name of the specified configuration section, the Type attribute specifies the name of the configuration section handler class to be read from the configuration file. There are two parts, the first is the handler class name, the Assembly name (the Assembly must be in the bin directory), version number, public key, and other information.

What do they mean? For example, the first section tells ASP.. Net System. configuration. configurationsettings. when getconfig ("applicationconfiguration") is used to read the applicationconfiguration configuration section, duwamish7.systemframework is called. applicationconfiguration class to process this configuration section. For the configuration section processing class, we will discuss it in detail later. Let's continue to look at the web. config file.


--------------------------------------------------------------------------------

Custom configuration section

After the <system. Web> node, we can see the following XML elements. Article Description, which is not repeated here ):

<Applicationconfiguration>
<! -- Trace file settings -->
<Add key = "systemframework. Tracing. enabled" value = "false"/>
<! -- Set this to the file with the trace settings. This file shocould be relative
To the root application directory. -->
<Add key = "systemframework. Tracing. tracefile" value = "duwamishtrace.txt"/>
<! -- The tracelevel for this switch. -->
<Add key = "systemframework. Tracing. tracelevel" value = "4"/>
<! -- This switch name. The trace level for this name can be set through
Environment variables or the Registry -->
<Add key = "systemframework. Tracing. switchname" value = "duwamishtraceswitch"/>
<! -- This description of the tracing. switchname switch -->
<Add key = "systemframework. Tracing. switchdescription" value = "error and Information Tracing for duwamish"/>
<! -- Event Log Settings
Note: The default duwamish7 event source name is created in the Local Machine During setup. If you want to log events to a different event Source
That event source must exist.
-->
<Add key = "systemframework. EventLog. enabled" value = "true"/>
<Add key = "systemframework. EventLog. Machine" value = "."/>
<Add key = "systemframework. EventLog. sourcename" value = "duwamish7"/>
<! -- Use the standard tracelevel values:
0 = off
1 = Error
2 = warning
3 = info
4 = verbose -->
<Add key = "systemframework. EventLog. loglevel" value = "1"/>
</Applicationconfiguration>
<Duwamishconfiguration>
<! -- Settings specific to the duwamish Application -->
<Add key = "duwamish. dataaccess. connectionstring" value = "Server = Luyan \ netsdk; user id = duwamish7_login; Password = password; database = duwamish7; Connection Reset = false"/>
<Add key = "duwamish. Web. enablepagecache" value = "true"/>
<Add key = "duwamish. Web. pagecacheexpiresinseconds" value = "3600"/>
<Add key = "duwamish. Web. enablessl" value = "false"/>
</Duwamishconfiguration>
<Sourceviewer>
<! -- Valid directories for source browsing. Keep these lower case. -->
<Add key = "." value = ""/>
<Add key = "modules" value = ""/>
<Add key = ".. \ common \ data" value = ""/>
<Add key = ".. \ systemframework" value = ""/>
<Add key = ".. \ business \ Facade" value = ""/>
<Add key = ".. \ business \ rules" value = ""/>
<Add key = ".. \ dataaccess" value = ""/>
<Add key = "secure" value = ""/>
<Add key = "docs \ common" value = ""/>
<Add key = "docs \ dataaccess" value = ""/>
<Add key = "docs \ Facade" value = ""/>
<Add key = "docs \ rules" value = ""/>
<Add key = "docs \ Web" value = ""/>
</Sourceviewer>

The configuration section information is divided into two main areas: the configuration section handler declaration area and the configuration section setting area. Here is the configuration section setting area of the three sections just defined, it contains the actual configuration settings. For more information, see annotations. All configuration information must reside between the <configuration> and </configuration> root XML tags, the configuration section setting area is located after the <configsections> area.


--------------------------------------------------------------------------------

Configuration section Handler

As described above, section defines the class for processing configuration section: duwamish7.systemframework. applicationconfiguration and duwamish7.common. duwamishconfiguration, which are located in the systemframework and common projects respectively ,. net stipulates that all classes that can process configuration sections must implement the iconfigurationsectionhandler interface, while the iconfigurationsectionhandler interface is very simple. There is only one object create (Object parent, object configcontext, xmlnode section) method, this method does not need to be called proactively. It is in configurationsettings. getconfig is automatically called when the static method is used, that is, when you use configurationsett in the program When ings. getconfig is used to obtain the configuration section,. Net automatically instantiates the configuration section processing class based on the class name and path defined in the configuration section declaration and calls the create method. The following describes how to call the processing class of duwamish:

1. Call the applicationconfiguration. onapplicationstart static method in the application_onstart method of Global. asax and obtain the absolute path of the application root.

Void application_onstart ()
{
Applicationconfiguration. onapplicationstart (context. server. mappath (context. Request. applicationpath ));
String configpath = path. Combine (context. server. mappath (context. Request. applicationpath), "remotingclient. cfg ");
If (file. exists (configpath ))
Remotingconfiguration. Configure (configpath );
}


2. Call the system. configuration. configurationsettings. getconfig method in the static applicationconfiguration. onapplicationstart method to process the configuration section:

Public static void onapplicationstart (string myapppath)
{
Approot = myapppath;
System. configuration. configurationsettings. getconfig ("applicationconfiguration ");
System. configuration. configurationsettings. getconfig ("duwamishconfiguration ");
System. configuration. configurationsettings. getconfig ("sourceviewer ");
}

As you have noticed, duwamish does not get the value returned by getconfig, because the getconfig method will trigger the create method of the configuration section handler, you only need to obtain the configuration value in the create method.

3. Read configuration example: duwamish7.common. duwamishconfiguration class

Public object create (Object parent, object configcontext, xmlnode Section)
{

Namevaluecollection settings;

Try
{
Namevaluesectionhandler basehandler = new namevaluesectionhandler ();
Settings = (namevaluecollection) basehandler. Create (parent, configcontext, Section );
}
Catch
{
Settings = NULL;
}

If (settings = NULL)
{
Dbconnectionstring = dataaccess_connectionstring_default;
Pagecacheexpiresinseconds = web_pagecacheexpiresinseconds_default;
Enablepagecache = web_enablepagecache_default;
Enablessl = web_enablessl_default;
}
Else
{
Dbconnectionstring = applicationconfiguration. readsetting (settings, dataaccess_connectionstring, dataaccess_connectionstring_default );
Pagecacheexpiresinseconds = applicationconfiguration. readsetting (settings, web_pagecacheexpiresinseconds, web_pagecacheexpiresinseconds_default );
Enablepagecache = applicationconfiguration. readsetting (settings, web_enablepagecache, web_enablepagecache_default );
Enablessl = applicationconfiguration. readsetting (settings, web_enablessl, web_enablessl_default );
}

Return settings;
}

We can see that duwamish does not manually read data from an xmlnode, but directly transfers the data to a namevaluesectionhandler for actual configuration reading, all it does is check whether there are actually defined configuration values. If not, assign the default value.


--------------------------------------------------------------------------------

Summary:

So far, Web. the Configuration value in config is read to the static variables of the configuration class. Later, other static variables of the configuration class can be used to directly access the configuration value. For example, enter duwamish7.common anywhere in the program. duwamishconfiguration. connectionstring: Server = Luyan \ netsdk; user id = duwamish7_login; Password = password; database = duwamish7; Connection Reset = false. Ideally, you can expand your configuration section and configuration section handler to pre-process complicated custom configurations.


--------------------------------------------------------------------------------
Come from: http://www.cnblogs.com/goodspeed/articles/5018.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.