Community Server Topic 2: Architecture

Source: Internet
Author: User

Community Server Topic 2: Architecture

Before analyzing the details of the CS project, it is necessary to understand the composition of the CS Project (solution) and the structure of the project in the CS project. This article consists of three parts: 1. Engineering Structure 2, three-tier architecture 3, database architecture.

1: Engineering Structure

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

The CS project consists of four parts:

A: system underlying architecture projects CommunityServerComponents and CommunityServerControls, it is provided to other project parent classes, interfaces, global variables, CS system settings, custom controls for public users, business logic for user and permission management, and exception handling.

B: CommunityServerBlogs, CommunityServerForums, CommunityServerGalleries, CommunityServerDocuments, and CommunityServerGuestBook. These projects implement their own business logic by inheriting and calling global methods and abstract their own Data providers. The business logic is different, but the project uses a three-tier structure.

C: UI project, which refers to CommunityServerWeb. This project almost does not contain logic code, but simply Html and the Skin (Skin is *. *. cs, which can be roughly understood as follows: for example, the Skin file in CommunityServerBlogs *. *. the cs logic code is implemented in the CommunityServerBlogs project and is not stored in *. in the same directory as the ascx file, it is compiled into CommunityServer together with other business logic in CommunityServerBlogs. blogs. dll ). At the same time, the UI project also saves the ages file and some configuration files.

D: DataProvider. Currently, only SqlDataProvider is implemented to operate SQL Server databases. DataProvider is actually a concrete implementation of the project database operation abstraction of entity B. The Provider Method of Data Operations brings several benefits, not concerning specific implementation, supporting multiple databases, and facilitating the division of labor among teams.

2. Three-tier architecture

Three-tier architecture is adopted in several projects, such as CommunityServerBlogs, CommunityServerForums, and CommunityServerGalleries. For example:

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

Business logic is interspersed in Contorls and Components. In a separate project, Contorls and Components are embodied in namespace. The following uses the CommunityServerGalleries project as an example to describe the three-layer structure of a specific project:

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

To facilitate file management, the Components and Contorls folders are created in the project to store the namespace CommunityServer. Galleries. Components and CommunityServer. Galleries. Controls respectively. If you are a beginner or not familiar with the layer-3 architecture, you may often be confused about the layer-3 architecture. In fact, the concept of this layer does not have an absolute division limit, instead of using a class as the smallest unit. This type of division is relative to the division of code functions. In the CommunityServerGalleries project, the operation code for the database is not directly written. Instead, the operation method is abstracted using the Provider method:

Example: public abstract Hashtable GetGalleries (bool mergePermissions );

The abstracted code can be called by the business logic like a common method. Because the Provider method is used, the data layer and the business layer are loosely coupled, it is easy to replace the database (you only need to replace the specific implementation method of the abstract data operation class without affecting the code at the business logic layer ).

The business logic includes the following parts: CommunityServer. galleries. all entity classes under Components. Most of these entity classes inherit the classes and interfaces defined or affirmed in the CommunityServerComponents project, such as Post, IThread, and PermissionBase. CommunityServer. some classes in the Galleries namespace are used to process data in the running process of business logic, cache and filter operations at the same time (the filtering operation is performed by CSApplication in the CommunityServerComponents project. to understand the process of defining delegation and event completion under the cs class, you need to have a certain understanding of CS. In the future, I will create a topic on delegation and event in the CS class ). Some business logic is obfuscated in CommunityServer. galleries. in some classes in the Controls namespace, they are closely related to the UI presentation layer. It is difficult to accurately define whether they belong to the business logic or the presentation layer code.

Classes in the presentation layer in CS can be roughly divided into three parts: 1: Yes *. ascx directly processes the user interface or user input and output Code. These classes indirectly inherit the TemplatedWebControl class in the CommunityServerControls project. 2: Some auxiliary classes are indispensable for skin replacement. These classes provide some basic services, such as finding the path of *. cs file *. ascx. 3: it is a user-defined control that does not require *. ascx. It generally inherits from the WebControls provided by. Net. These classes are put under the Controls/Utility folder.

The traditional Asp.net Web page is created *. aspx or *. both ascx and *. the cs file is used to operate controls on the page. The page is like a container. The corresponding classes will be automatically found at runtime through the Codebehind page (how can this process be implemented without being analyzed, but we can achieve the same effect through reflection, and at the same time get higher flexibility ). In the CS system, the UI is found through reflection *. the class corresponding to ascx implements the corresponding UI processing function, and *. as long as the name and the ID of the control remain unchanged in the content of ascx, how to replace the specific Html code does not affect the functions of the entire system. The CS system achieves skin replacement through such means, adding MasterPage can reduce the number of duplicates in Html code. Finally, with the combination of Html and CSS style sheets, you can easily change the style of the website's skin, including text and div layout. * After the. cs and *. ascx files are stripped off, the website artist and the program designer are truly separated, which is conducive to team collaboration and personal expertise.

Another point must be noted: There are many CS projects *. the aspx file is just a framework page that has been added to MasterPage, or even a blank file that has nothing to do with (for example, most default files. the framework file contains a large number of controls, such as <Galleries: GalleryAdmin id = "GalleryAdmin" runat = "server"/>, in fact, this control corresponds to Skin-GalleryAdmin. the skin of ascx. If you can understand this, you can see that most of the CS code should not be faulty.

3. database architecture

Take a look at the DataProvider model:

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

The model shows that the abstract DataProvider is separated from the specific database operation DataProvider. In CS, Components and the abstract DataProvider are compiled in a project, SQL Server DataProvider is compiled separately. The benefit is that different DataProvider abstractions are replaced to implement different database operations. In addition, this loose coupling method is conducive to the opening of the team. How to implement this DataProvider method (I will briefly describe it here. For details, please pay attention to the subsequent topics )?

The abstract class is stored in the Providers directory of the corresponding project. Taking 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 easy to understand. In fact, the key is"

In the Instance, call the CreateInstance method in the DataProviders. cs class of the CommunityServerComponents project to initialize a GalleryDataProvider.

The process is first found in the Communityserver. config file

Public static readonly string GalleryDataProviderName = "GalleryDataProvider ";

"GalleryDataProvider" in, where:

<Add name = "GalleryDataProvider" type = "CommunityServer. Data. Handler, CommunityServer. SqlDataProvider" connectionStringName = "SiteSqlServer" databaseOwnerStringName = "SiteSqlServerOwner"/>

According to the content in "type", use Type. getType and Activator. createInstance sets CommunityServer. sqlDataProvider. the corresponding CommunityServer In the dll assembly. data. the GallerySqlDataProvider class is instantiated. after instantiation, it is similar to GalleryDataProvider. instance (). the call to GetGalleries (true) is to directly operate the CommunityServer. sqlDataProvider. the CommunityServer In the dll program. data. under the GallerySqlDataProvider class

Public override Hashtable GetGalleries (bool mergePermissions) method. This process may be difficult to understand, but it is only a matter of time.

SqlDataProvider (SqlDataProvider is an abstract Implementation of SQL Server database operations. You can also abstract the implementation of other databases, currently, CS only supports SQL Server). In SqlDataProvider, operations on stored procedures are used instead of SQL Text. I wrote about the benefits of this practice in the previous topic. Data caching and ordering:

Cache: My personal habit is to write the cache in the data layer, while CS writes the Cache Management in the business logic layer, and the number of caches is large, for example, read a single Gallery method from the CommunityServerGalleries project:

Public static Gallery GetGallery (string applicationKey, bool cacheable)

The general practice is to write a stored procedure for this method, and then call the relevant data from the database when there is data operation, and check whether the data is cached Based on the parameter. This looks good. I always think that the memory is precious and can be cached a little less, but CS's approach is to read all Gallery into Hashtable and cache it out! When reading a single Gallery, you can find it from the cache. You don't need to worry about the database, let alone write the Stored Procedure (this is very convenient ). Of course, CS defines the cache time. The cache will be released automatically after the expiration time, but new data will not be displayed before the cache is released, this is a good solution for some datasets that are not updated quickly (there is a better cache solution in SQL 2005, so you can update the cache when new data is updated ).

Data ordering: friends who have developed CRM should have some experience. Many fields need to be reserved in the database, because you do not know what storage requirements customers who use the CRM system will have, such: a crm user needs to save his customer's age, but it is impossible to add this storage field to such a problem during the CRM system design process. The common practice is to give some blank fields, initialize the user when using the SDK. However, the result is that the CRM database is terrible. What's even more terrible is that if you need to add fields that are not originally needed during software upgrade, It is very troublesome. The stored procedures from entity classes to database operations need to be changed. Data ordering can solve this problem. In fact, I was very excited when I saw CS for the first time. First, I realized that adding fields does not require re-writing data operation classes, you do not need to modify the stored procedure. Second, the stored fields are neat, and all values are saved in two fields,


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

First, analyze the stored data. The first is the PropertyNames field, "EnableComments: S: 0: 4: ModerateComments: S: 4: 5: EnableRatings: S: 9: 4: "" EnableComments "is actually an attribute name defined in the object class.": "indicates that the definition is complete." S: 0: 4 "indicates the attribute values of the four characters in the PropertyValues field that start from 0 and belong to" EnableComments ". Similarly," S: 4: 5 "indicates that the character starts from the fourth character, the next five attribute values that indicate "ModerateComments" can be used to obtain the values of all PropertyNames fields. (Remember that in Asp.net Forums, data is stored in Binary. You can search ntext in CS to solve the inconvenience caused by sequential data search .), Subsequent topics such as how to sequence are described.

The bottom layer of CS is the database and storage process. The key tables cs_Groups, cs_Sections, cs_Threads, and cs_Posts correspond to CommuntyServer respectively. group, Section, Thread, and Post classes in the Components namespace. Groups is a Group. corresponding to the Forum, it is "Section Group", Section "," clue ", and" Post ", corresponding to a Blog is "Blog group", "Blog", "clue", "essay or article ". This cs_Threads is a bit difficult to understand. In fact, it is a statistical and tracking of Post-related information under the corresponding Section, such as the last reply time and the total number of comments.

The architecture of the Community Server project is roughly analyzed above. The details will be analyzed one by one in subsequent topics. In any case, Community Server is a relatively large project. It requires a lot of text to fully explain and analyze the system.

Related Article

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.