Community Server Topic 2: Architecture

Source: Internet
Author: User

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

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:

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:

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 the Skin-GalleryAdmin.ascx skin. 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:

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.

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,

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 that the four characters in the propertyvalues field start from 0 and belong to the "enablecomments" attribute value. 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.

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.