Community Server Topic II: Architecture _ Practical Skills

Source: Internet
Author: User
Tags reflection
Community Server Topic II: Architecture

In the CS detailed analysis before, it is necessary to understand the CS project (solution) composition, as well as the composition of the project in CS project structure, this article is divided into three parts: 1, Engineering structure 2, three layer frame 3, database architecture.

1: Engineering structure

=538) {this.width=538} "border=0>

CS project is mainly divided into 4 parts

A: System infrastructure project Communityservercomponents, Communityservercontrols, provided to other project parent class, interface, global variables, CS system settings, public user custom control, user and Rights management business logic, exception handling, and so on.

B:communityserverblogs, Communityserverforums, Communityservergalleries, Communityserverdocuments, Communityserverguestbook. These projects are to implement their own business logic by inheriting, invoking the global method, and abstracting their own data Provider, the business logic is different, but the project adopts three-tier structure.

C:ui project, this refers to Communityserverweb. The project contains almost no logical code, just simple HTML and skin in the application project (skin is *.ascx file, but not associated with the corresponding *.cs, which can be roughly understood: communityserverblogs file * in skin. The *.cs logical code associated with Ascx is implemented in the Communityserverblogs project and is not guaranteed to exist in the same directory as the *.ascx file. Instead, it is compiled with the other business logic in Communityserverblogs as CommunityServer.Blogs.dll). The languages file and some configuration files are also saved in the UI project.

D:dataprovider, only Sqldataprovider is currently implemented to operate on the SQL Server database. Dataprovider is actually a concrete implementation of the abstract of the entity Project database operations in part B. The provider way of data operation brings several benefits, does not care about the concrete implementation, supports multiple databases, and is advantageous to the team cooperation Division.

2, three-storey architecture

In Communityserverblogs, Communityserverforums, Communityservergalleries and several other projects have adopted a three-tier architecture, the following figure:

=538) {this.width=538} "border=0>

The business logic is interspersed in contorls and components, in a separate project contorls and components are embodied in namespace, The following is an example of the three-tier structure of a specific project, Communityservergalleries project:

=538) {this.width=538} "border=0>

In order to facilitate file management, the project has established components and Contorls folders to store namespaces separately for CommunityServer.Galleries.Components and CommunityServer.Galleries.Controls. If you are a beginner or are not too knowledgeable about the three-tier structure, there may be times when you are puzzled by the three-tier architecture, in fact the concept of this layer does not have an absolute dividing line, much less a class as the smallest unit. This division is relative, and is a division of code functionality for writing. The Communityservergalleries project does not directly write the operation code for the database, but instead uses the provider method to abstract the methods of operation:

Example: Public abstract Hashtable getgalleries (bool mergepermissions);

The abstract code can be called by business logic just like normal methods, because of the provider approach, the data layer is loosely coupled to the business layer and can be easily replaced (only by replacing the specific implementation of the abstract data manipulation class without affecting the code in the business Logic layer).

The business logic consists of several parts: CommunityServer.Galleries.Components all the entity classes, most of which inherit post, Ithread, Permissionbase classes and interfaces that have been defined or declared in the Communityservercomponents project. Communityserver.galleries namespaces, which are used to handle data during the operation of the business logic, while caching and filtering operations (filtering is done through the CSApplication.cs in the Communityservercomponents project) class to define the completion of the delegate and event, to understand this process needs to have a certain understanding of CS, follow-up I will do a CS in the Commission and event topics. There is also a part of the business logic that is confused in some classes under the CommunityServer.Galleries.Controls namespace, and they are closer to the UI presentation layer, and it is difficult to define exactly whether they belong to the business logic or the presentation layer code.

The class in the presentation layer in CS can be roughly divided into three parts, 1: The code that needs to be *.ascx directly to handle the user interface or user input and output, these classes are indirectly inherited from the Communityservercontrols project Templatedwebcontrol class. 2: To carry on the skin can not be without the use of some auxiliary classes, these classes provide some basic services, such as: Find *.cs files corresponding to the *.ascx path. 3: is a user-defined control that does not require *.ascx, and is generally inherited from. NET provides the WebControls. These classes are placed under the Controls/utility folder.

The traditional ASP.net web page design in the establishment of *.aspx or *.ascx will also create a *.cs file with the same name, to implement the control of the page operation, the page is like a container at this time. The corresponding class is automatically found by the Codebehind page at run time (how the process is implemented without analysis, but we can achieve the same effect through reflection, with a higher flexibility). The UI of the CS system is to find the corresponding class of *.ascx by reflection, and *.ascx as long as the ID of the control in the name and content is unchanged, how the specific HTML code is replaced does not affect the function of the whole system. CS system is also through such means to achieve the purpose of the skin, while adding masterpage can reduce the duplication of the HTML code part. Finally, the combination of HTML and CSS style sheets makes it easy to change the skin style of the site, including the text and div layout. *.cs and *.ascx file stripping after the website art and program designers really separate, is conducive to teamwork, play personal expertise.

It is also important to note that many of the *.aspx files in the CS project are just a frames page that has been added to the masterpage, or even an empty file with nothing (such as most default.aspx pages), with a large number of "<galleries" embedded in the framework file: GalleryAdmin id= "GalleryAdmin" runat= "/>" Such controls, in fact, this control corresponds to the skin-galleryadmin.ascx skin. If you can understand here, want to see understand CS Most of the code should not have a problem.

3. Database architecture

First look at the Dataprovider model:

=538) {this.width=538} "border=0>

The model can see that abstract dataprovider is separated from the specific database operation Dataprovider, in CS components and abstract dataprovider are compiled in a project, while SQL Server The Dataprovider is compiled separately. The benefits can be seen in terms of replacing different dataprovider abstractions to implement different database operations, and this loosely coupled approach facilitates the team's openness. How to achieve such a dataprovider way (I am here briefly, specifically please pay attention to the following topics)?

First look at the abstract class, the abstract class is stored in the corresponding project providers directory, in the gallery project as an example, its namespace is CommunityServer.Galleries.Components


=538) {this.width=538} "border=0>
The entire class is public abstract class, which is well understood, but the key is in the "Instance"

section, in instance initializes a gallerydataprovider by calling the CreateInstance method in the Communityservercomponents project DataProviders.cs class.

The process is first found in the Communityserver.config file

public static readonly String gallerydataprovidername = "Gallerydataprovider";

The "Gallerydataprovider" in, here is:

<add name = "Gallerydataprovider" type = "CommunityServer.Data.GallerySqlDataProvider", Communityserver.sqldataprovider "connectionStringName =" sitesqlserver "Databaseownerstringname =" Sitesqlserverowner "/>

According to the contents of "type", using Type.GetType and activator.createinstance to put the corresponding CommunityServer.SqlDataProvider.dll program The CommunityServer.Data.GallerySqlDataProvider class is instantiated and is instantiated like Gallerydataprovider.instance (). Getgalleries (True) is actually a direct manipulation of the CommunityServer.SqlDataProvider.dll assembly Under the CommunityServer.Data.GallerySqlDataProvider class

public override Hashtable Getgalleries (bool mergepermissions) method. This process may be difficult to understand, but understanding is only a matter of time.

The most closely related to the database in the data access layer is the Sqldataprovider (Sqldataprovider is an abstraction of the SQL Server database operation, and you can abstract the other databases so that CS only provides SQL Server implementations), The operation of the stored procedure is used in Sqldataprovider without the use of SQL Text. In the previous topic I wrote about the benefits of doing this, no more talking here. The main description is the caching and sequencing of data:

Caching: My personal habit is to write the cache in the data layer, while CS is writing cache management in the business logic layer, and the number of caches is very large, such as the Communityservergalleries project to read a single gallery method:

public static Gallery Getgallery (string applicationkey, bool cacheable)

The general approach is to write a stored procedure for this method, and then call the relevant data from the database when there is a data manipulation, and it looks good if the data is cached based on the parameters. I also always think that memory is precious, can less cache a little bit less cache, but the practice of CS is to read all gallery into the Hashtable, cache out! To read a single gallery from the cache, do not go to the database, not to write stored procedures (this is very convenient). Of course, the CS defines the time for caching. When the time expires, the cache is automatically freed, but the new data is not displayed until the cache is released, which is a good solution for some newer datasets that are not fast (there is a better caching solution in SQL 2005 that can update the cache when new data is updated).

Data sequencing: A friend who has developed CRM should have experience, many fields need to be reserved in the database, because you do not understand what kind of storage requirements customers use CRM system, such as: CRM users need to save the age of his customers, However, in the process of designing CRM system, it is impossible for such a problem to be specially added to this storage field, the usual practice is to give some empty fields, when the user uses the corresponding initialization for him. But the result is that the CRM database is miserable. What's more, if you need to add some fields that you didn't have when you want to upgrade the software, it's a hassle, and the stored procedures from entity classes to database operations need to be changed. and data sequencing can solve this problem, in fact, when I first saw CS this practice is very excited: first, the implementation of the add fields do not need to rewrite the data operation class, but also do not need to modify the relevant stored procedures. Second, the stored fields are neat, and all the values are saved in two fields, as shown in the figure:


=538) {this.width=538} "border=0>

First analyze the stored data, first of all, the PropertyNames field, "Enablecomments:s:0:4:moderatecomments:s:4:5:enableratings:s:9:4:" Enablecomments "is actually a property name defined in the entity class, and": "is defined, and" S:0:4 "indicates that the character in the Propertyvalues field has a property value of" Enablecomments "from the beginning of 0, with the same meaning:" S : 4:5 "indicates that, starting with the fourth character, the following 5 property values represent" moderatecomments ", and so on, and so on, you can get the values of all the fields PropertyNames. (Remember in asp.net forums when the data sequence is stored with the binary, in the CS to ntext can be searched, to solve the problem of the data search after the order of the inconvenience. ), and the follow-up topics on how to do so are described.

At the bottom of the CS is the database and stored procedures, the key tables cs_groups, Cs_sections, cs_threads, and cs_posts tables correspond to the group under the Communtyserver.components namespace, section, thread and post class, groups is the group, the corresponding forum is "plate group", "Block", "Clue" and "post", corresponding to the blog is "blog Group", "blog" "Clues", "essays or articles." This cs_threads is a bit difficult to understand, in fact it is the corresponding section of the Post related information statistics and tracking, such as the final reply time, the total number of comments and so on.

The architecture of the Community Server project is roughly analyzed, and the details are analyzed in one by one of subsequent topics. Anyway, community server is a relatively large project, it requires a lot of text to fully explain and analyze the system.

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.