Architecture documentation on CommunityStarterkit (translation)

xiaoxiao2021-03-06  106

This document contains a structure of CSK. The first part of the document mainly introduces two features of CSK: the skin and generated page and directory by the database, you can learn how these two features are implemented. The second part of this document discusses the modification of CSK. First, you will learn how to build a new topic to change the appearance of the site. The next learning is how to build a model component working on the CSK platform, such as a Jobs model component.

Part 1: Characteristics of CSK

★ Skin system

CSK is built on the ASP.NET community application (www.asp.net). Just like an ASP.NET community application, it also uses the skin system to determine the user interface from the code. There are four types of skin for CSK: page Skins - Page Skin determines the page on all layers. For example, it can determine the column navigation location on the page. In general, only one site is only one Page Skin. Content Skins - Content Skin is used to organize the content part on the page. For example, an appearance of a login page is determined by Content Skin. Generally, the page of Content Skin and the site is a one-to-one relationship. Control Skins - Control Skin is an exterior that customizes a control. For example, the appearance of the column navigation control is implemented by Control Skin. (There are still many kinds of controls, such as users, etc.) Template Skins - Template Skin determines the appearance of the control template, like ItemTemplate and HeadeRPlate in a REPEATER control. Different from Comment Views, such as Threaded, Embedded, Nested, implemented through different template skin.

Whenever, when you open a CSK page, a group of skin is called to determine the appearance of the page. For example, once you choose the Robotico theme for the site, and ask a login page, the following skin is called (not a full list):

Robotico Page Skin is located: /Themes/Robotico/Skins/PageSkins/Default.ascxLogin Page Content Skin is located: /Themes/Robotico/Skins/ContentSkins/User_login.ascxSection Menu Control Skin is located in: / Themes / Robotico / Skins / ControlSkins / Sections_SectionMenu. ASCX

How is the remaining part of how completely generated? In fact, the skin supports inheritance. If a skin cannot be called in a specific subject, the system automatically calls from the default topic. This is a very important point, which means that when you build a new topic, you don't need to build each skin and control. You only need to overwrite you want to modify your remote skin. The skin is composed of HTML code and ASP.NET control (not code). For example, the skin user_login.ascx of the login page may be some of the following:

<% @ Control%>

login please enter your username and password below.
IF you are a new user, click here to register .

the username you entered is invalid! The password you entered is invalid!

< TD colspan = "2">

click for a password reminder.

All pages of CSK are implemented using classes, which are derived from SkinnedcommunityControl. This basic class is responsible for the specific skin control. SkinnedCommunityControl class has an important property and an important way to rewrite: skintype properties, and initializeskin () methods. The Skintype property specifies the joint type between the skin, these skin there is (Contentskin, Controlskin, Templateskin). The initializeskin () method is used to reorganize all controls to achieve the control attribute specified in the code can be executed. For example, the class file (login.vb or login.cs) of the login page may be as follows:

Login.cs

Namespace aspnet.starterkit.communities {

Using system; using system.web.ui.webcontrols; using aspnet.starterkit.communities; using system.Web.security;

// ******************************************************** ***************************** / / / LOGIN Class //// REPRESENTS THE User Login Page Which Enables // Users to login to the community. // / / ************************************************** ******************** Public class login: SKINNEDCOMMUNITYCONTROL {string _skinfilename = "users_login.ascx";

TEXTBOX TXTUSERNAME; TextBox TxtPassword; CheckBox Chkpersist; Button Btnlogin; Panel PnlinvalidUserName; Panel PnlinvalidPassword; HyperLink LnkpasswordReminder;

// ******************************************************** ****************************** / / / Login Constructor /// Calls The Base SkinnedcommunityControl Constructor // and assigns the default page skin. /// * *********************************************************** ******************

Public login (): base () {// Assign a default skin file name if (skinfilename == null) SKINFILENAME = _skinfilename;

// ******************************************************** ********************* / / / SKINTYPE Property // // Specifies The Skins Directory Where This Page's Skin file is located. //// *** *********************************************************** **************** Override protected string skintype {get {return "contentskins";}}

// ******************************************************** ****************************** / / / INITIALIZESKIN METHOD / / / RETRIEVES All the Controls from the page Skin /// ******** *********************************************************** ************ Override protected void initializeskin (Control Skin) {// Find the username textbox txtusername = (TextBox) getControl (Skin, "txtusername");

// Find the Password TextBox txtPassword = (TextBox) GetControl (skin, "txtPassword"); txtPassword.TextChanged = new System.EventHandler (btnLogin_Click); // Find the Persist Checkbox (Optional) chkPersist = (CheckBox) GetOptionalControl (skin , "chkPersist"); // Find the Invalid Username Panel pnlInvalidUsername = (Panel) GetControl (skin, "pnlInvalidUsername"); pnlInvalidUsername.Visible = false; // Find the Invalid Password Panel pnlInvalidPassword = (Panel) GetControl (skin, " PnlinvalidPassword "); pnlinvalidpassword.visible = false; // Find login button btnlogin = (button) getControl (Skin," btnlogin "); btnlogin.click = new system.EventHandler (btnlogin_click);

// Find Password Reminder LNKPasswordReminder = (HyperLink) getControl (Skin, "LNKPasswordReminder"); lnkpasswordReminder.navigateURL = "~ / users_passwordReminder.aspx";

// ******************************************************** ********************* / / / BTNLOGIN_CLICK METHOD //// Checks UserName and Password Against Database. If // Everything Checks, Logins the user. // // ******************************************************** ********************* VOID BTNLOGIN_CLICK (Object S, Eventargs E) {Bool BLPERSIST = false; // determine WHether Password Should Be Persisted If (chkpersist! = Null ) blPersist = chkPersist.Checked; // Either login or display error message switch (UserUtility.LoginUser (txtUsername.Text, txtPassword.Text)) {case 0:! // Success FormsAuthentication.SetAuthCookie (txtUsername.Text, blPersist); string RedirectURL = formsauthentication.getredirectURL (txtusername.text, blpersist) .tolower (); if (Redirecturl.indexof ("Users_lo gout.aspx ") == -1) Context.Response.Redirect (redirectUrl); else Context.Response.Redirect (CommunityGlobals.ResolveBase (" default.aspx ")); break; case 1: // Invalid Password pnlInvalidPassword.Visible = true; pnlinvalidusername.visible = false; break; case 2: // invalid username pnlinvaliDUsername.visible = true; pnlinvalidpassword.visible = false; break;}}}}

The SkintYpe property of the Login class specifies the skin of the class with the class, which means that the control system will try to get the skin from the selected topic directory. The initializeskin () method uses getControl () to get Content Skin all controls. GetControl () is a method for the SkinnedCommunityControl class that can get the control information from a skin. Here, initializeskin () extracts information from TXTUSERNAME and TXTPASSWORD TEXTBOXES and BTNLogin Button from Content Skin. After obtaining the BTNLogin Button control information from Content Skin, this control is associated with the bithlogin_click event handles handle. When the customer clicks on the login button, btnlogin_Click () performs the determination whether the user is allowed to operate the database. All pages in the CSK implement the same operation like login. Each page contains a class and a skin. The skin determines the appearance of the page, and the class contains all the page feature. All pages in the CSK implement the initializeskin () method so that you can call the controls in the skin combined with this page. When the control is removed from the skin, the properties of the control can be modified in the code. The advantage of this setup page method is that it is possible to change its appearance by changing the skin in combination with the pages, which can be found in the Chinese. When you choose a different topic, like Arc / Robotico / Professional et al, different skin will be combined with the page and make the appearance of the site quickly change.

★ Generate pages and directories from the database

In the entire CSK, the real .aspx file has only one, it is a CommunityDefault.aspx file in the root directory. It is responsible for displaying any other requested pages, do not pay ignite this page is requested from the site. All pages and directories in the CSK are dynamically generated from the table of the database. Whenever you request a page, an HTTP model component called Communities immediately handles this request. The model component will entertain the following moves: 1. Determine site information with the page; 2, determine the information information combined with the page; 3. Determine page information with the page; 4, determine and page User information combined together; 5, store all information (sites, columns, pages, etc.); 6, use the context.rewritepath () method to redirect the request to the CommunityDefault.aspx page. CommunityDefault.aspx uses information collected by the Communities model component to generate the target page to be displayed.

CommunityInfo / SectionInfo / PageInfo / UserInfo four objects

The Communities model component stores Community Information, Section Information, Page Information, and User Information in the Items Collection of the HttpContext object. That is to say, the information can be retrieved during the page request survival of the class and control (the foreigners write very bit, that is, can be programmed). Community Information is described as a class named CommunityInfo. This class is described by the name of the site; section Information is described as a class named SectionInfo, this class has a lot of properties, like Title, Path, Description, etc. They describe information about a specified column; Page Information is described as a class named PageInfo, including the attribute of a value of a value such as content, such as this page is still a picture system Finally, User Information is described as an object called UserInfo, which describes information such as username, user role, and permission to bind the user. For example, a UserInfo object has an attribute called MayAdd, which is used to determine if the user has the right to add content in a section. You can use the following code to use these information in classes and controls: C # CommunityInfo ObjcommunityInfo =

(CommunityInfo) System.Web.httpContext.current.Items ["CommunityInfo"];

SectionInfo objsectionInfo =

(SectionInfo) System.Web.httpContext.current.Items ["SectionInfo"];

PageInfo objPageInfo =

(PageInfo) System.Web.httpContext.current.Items ["PageInfo"];

Userinfo objuserinfo =

(UserInfo) System.Web.httpContext.current.Items ["UserInfo"];

The type of CSK page CSK uses the following three page types: Named Pages - Define a static content, like Login.aspx and Register.aspx and other pages, generate information of these pages in content; section Default Pages - When you open The Section Default Pages are turned on when a section is default. For example: The default page of the article publishing section and the photo browsing section is turned on. The information required to generate the section default page is stored in memory; Content Pages - Describes a unique content item in a database. For example, a content page may describe a special article, download and other files. It does not exist in memory. You must take it from the database each time you are requested. Community, page and section information table exists in several databases are: · Community_Communities - a list of all sites · Community_Sections - column list all sites · Community_NamedPages - a list of all sites Named Page · Community_ContentPages - all sites of the Content Page list · Community_PageTypes - All Site Pages Type List When the CSK program is started, it will transfer the community_communies / community_sections / and common_namedpages data sheet. When the page request occurs, the Communities model component will execute a query action in memory, and Required Section and Page information Retrieve (for control program). If you request a Content page, such as a specific article or image, the Communities model component will perform the database query operation to obtain information. PART 2: Modify CSK

All source code for CSK is already included in the suite you downloaded, you can modify the topics and code contained in CSK to complete any of the purpose you want.

Create a new topic

Using CSK to create a new topic is very simple, just find an existing topic, such as the ARC theme, copy it to a new directory, and modify the skin. Once you have added a new directory in the topic directory, this topic will automatically display in the background management page. All themes are located in a communities directory, which has the following directory structure:

/ Communities

/ Common / themes

/ Community1 / themes

/ Community2 / themes

The Communities / Common directory contains some subjects that can be used by other sites, and a separate site can have the topic directory that only they can use. The topic directory structure is as follows:

/ Themes / Default / Skins / Contentskins / Controlskins / Pageskins / Templateskinskinskins

/ Styles

Default.aspx is located in Skin's Pageskins subdirectory, which determines the skin of all page layout under this topic. You can modify your skin to change the number of lines of this page, the location of the section and Topic menu, and some other relevant page layout.

If you want to change the appearance of the specified page, you need to add new skin files to the new subject's Contentskins to override the default page skin. For example, you want to modify the Login.aspx page now, you can copy the user_login.aspx files located in the default topic contentskins directory into the new topic and then modify.

You don't need to build a new skin or control for each skin like the default theme. If you don't provide skin, the system will find yourself from the default theme to the corresponding alternative skin. The topic directory is STYLES, which contains one or more style sheets that can be applied in the topic. All style sheets added to the Styles directory (must be used as the extension as the extension) to automatically display the style table drop in the background management page.

Create a new model component

You can build a new CSK model component, for example, you may need to create a new model component (Job Module) for displaying a list of works, and establishing a model component, you need the following basic steps:

1. Establish a page portion from the basic class SkinnedCommunityControl derived class, this class description model component; 2. Create a user control to describe the Content Skins used in this model component; 3, register a new page Community_namedpages And Community_PageTypes.

For example, the above example, you need to complete the following steps:

1, Jobs Section Page - Display a list of Jobs; 2, Job Page - Display a specific Job; 3, add job page - Allow users to add a Job; 4, Edit Job Page - Allow users to modify an existing job ;

Establish these pages, you need to start from the establishment of four class files. The CSK framework contains each of these pages: ContentListPage · ContentItempage · ContentAddPage · ConteniTeditPage These four basic classes are located in the / Engine / Framework / BaseClasses directory. As an example of implementing these classes, refer to the source code of the model components included in the CSK. For example, the Books model component contains Booksection, Book, Addbook, and EditBook classes.

Next, it is to establish a skin file to these classes. You need to add the following skin files in the contentskins directory of the topic directory: · Jobs_jobsection.ascx · jobs_job.ascx · jobs_addjob.ascx Note that only three skin files are listed, all of the standard model components of CSK are used in the same Increase and edit the page. An example of a Content Skins, you can refer to the Content Skins used by the Books model component. The Book model component contains the following skin (can be found in the / communities / common / themes / default / skins / contentskins directory): · Book.Ars_booksection.ascx · Books_book.ascx · Books_addbook.ascx After the finished page, before they display You also need to register them in the database. You need to add records in both data sheets in Community_Namedpages and Community_PageTypes.

To learn how the book section is registered with the SQL statement, you may refer to the instructions, as an example, below is the stored process to register the Booksection page:

If not exists (select * from community_pageTypes where pageType_name = 'book section')

Begin

INSERT INTO COMMUNITY_PAGETYPES

(

PageType_name,

PageType_Description, PageType_pageContent,

PageType_InsectionType

)

Values

(

'Book Section',

'Contains Book Listings',

'Aspnet.starterkit.communities.books.booksection',

1

)

End

Else

Print 'Warning: The Books Module Has Already Been Registered.'

After this statement is executed, the Books model component will increase or edit this model component by adding a column or editing section in your management page.

Time rush, there is no careful correction!

2004/8/20

转载请注明原文地址:https://www.9cbs.com/read-125017.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.053, SQL: 9
UserName:
Password: