(002). NET large and open source project Nopcommerce Analysis--Installation page

Source: Internet
Author: User
Tags nopcommerce

This article mainly introduces the function and principle that the installation page involves to implement.

Initial launch Nopcommerce will enter a page with a URL of "/install", which involves 2 functions: 1. Page globalization; 2. Data preparation.

0. Reserve knowledge

Characteristics

JavaScript events

Cookies

Multi-activity result set

1. Page Globalization 1.1 display area text

In the lower right corner of the installation page there is a Select regional language feature, which can be seen in a considerable number of languages to choose from. When you finish selecting the corresponding area, the text of the page changes accordingly.

Page globalization There is one of the simplest implementations of sub-folders to build a station, such as Microsoft's MSDN, but the same page shared the basic design is probably very redundant-I mean the worst case.

The implementation is the routing parameter, for example.

The Nopcommerce page is a strongly typed view. The developer defined the view model in Nop.web-installcontroller-index () Installmodel and then went to the page output.

[Validator (typeof(Installvalidator))]  Public Partial classInstallmodel:basenopmodel { PublicInstallmodel () { This. Availablelanguages =NewList<selectlistitem>(); } [allowhtml] Public stringAdminEmail {Get;Set; }        [Allowhtml] [DataType (Datatype.password)] Public stringAdminPassword {Get;Set; }        [Allowhtml] [DataType (Datatype.password)] Public stringConfirmPassword {Get;Set; } [Allowhtml] Public stringdatabaseconnectionstring {Get;Set; }  Public stringDataprovider {Get;Set; }  Public BOOLdisablesqlcompact {Get;Set; } //SQL Server Properties         Public stringSqlconnectioninfo {Get;Set; } [Allowhtml] Public stringSQLServerName {Get;Set; } [Allowhtml] Public stringSqldatabasename {Get;Set; } [Allowhtml] Public stringSqlserverusername {Get;Set; } [Allowhtml] Public stringSqlserverpassword {Get;Set; }  Public stringSqlauthenticationtype {Get;Set; }  Public BOOLSqlservercreatedatabase {Get;Set; }  Public BOOLusecustomcollation {Get;Set; } [Allowhtml] Public stringCollation {Get;Set; }  Public BOOLdisablesampledataoption {Get;Set; }  Public BOOLInstallsampledata {Get;Set; }  PublicList<selectlistitem> Availablelanguages {Get;Set; } }

Here the attribute and inheritance base class do not control. As a general note, this feature is used by the View validation framework fluentvalidation, and the parent class is the domain object base class.

The string in the page design region is generated uniformly by the GetResource (string resourcename) method.

/// <summary>        ///Get Locale Resource value/// </summary>        /// <param name= "resourcename" >Resource name</param>        /// <returns>Resource Value</returns>         Public stringGetResource (stringresourcename) {            varLanguage =Getcurrentlanguage (); if(Language = =NULL)                returnresourcename; varResourcevalue =language. Resources. Where (R=r.name.equals (resourcename, Stringcomparison.invariantcultureignorecase)). Select (R=r.value).            FirstOrDefault (); if(String.IsNullOrEmpty (resourcevalue))//return name                returnresourcename; returnResourcevalue; }

The total flow of this method (including the child method called) is:

    1. Get the cookie value for "Nop.installation.lang"
    2. Traverse and read the XML file in the "/app_data/localization/installation/" directory that conforms to the naming requirement (regular expression) and store its child node information (the string used by the page) in the Installationlanguage object. Store the root node (<language name= "Simplified Chinese" isdefault= "false" isrighttoleft= "false" >) in List<installationlocaleresource > in.
    3. The current language object is derived according to the code attribute in list<installationlocaleresource> to match the cookie value installationlanguage
    4. If the cookie does not match (no cookie), the Request.UserLanguages preference in the browser (HttpContext.Request.UserLanguages.FirstOrDefault () ) to match the Code property
    5. If it does not match, the XML corresponding to the IsDefault property of True is returned installationlanguage
    6. If the exact match is not on, the installationlanguage corresponding to any XML is returned
    7. If anything happens, Getcurrentlanguage returns null and outputs the passed string directly.
    8. If nothing happens, match the qualifying information to the list<installationlocaleresource> based on the string and return

The implementation class involved in the above operation is mainly installationlocalizationservice.

And the function is complete.

1.2 Changing area text

The drop-down box for page output is like this:

The implementation of Nopcommerce is the drop-down box change trigger onchange event (onchange= "window.location.href = This.value;" ), and then issue a GET request page.

The route of the page has not changed from the results, but in fact this is the result of Changelanguage redirection:

 PublicActionResult Changelanguage (stringlanguage) {            if(datasettingshelper.databaseisinstalled ())returnRedirecttoroute ("Homepage");            _locservice.savecurrentlanguage (language); //Reload the page            returnRedirecttoaction ("Index","Install"); }

And the Middle _locservice.savecurrentlanguage (language); Change the value of the cookie named "Nop.installation.lang" to the requested language type.

 Public Virtual voidSavecurrentlanguage (stringlanguagecode) {            varHttpContext = Enginecontext.current.resolve(); varCookie =NewHttpCookie (languagecookiename); Cookies. HttpOnly=true; Cookies. Value=Languagecode; Cookies. Expires= DateTime.Now.AddHours ( -);            HttpContext.Response.Cookies.Remove (Languagecookiename);        HTTPCONTEXT.RESPONSE.COOKIES.ADD (cookie); }

Because the cookie is changed, the GetResource method gets a string that is also changed according to the current locale.

The first line of code, as it is generally stated, is to determine that the database has been installed and redirect to the home page according to the homepage rule .

2. Data Preparation work

Importing data is relatively straightforward. Executes a multi-activity result set (SQL script) after a series of judgements. The main reason is that the strongly typed attribute is more, so its post action if else is more. After the execution of these operations there is actually a plug-in installation and permission to install the process, you see the source code it.

Installcontroller-public ActionResult Index (Installmodel model)

(002). NET large and open source project Nopcommerce Analysis--Installation page

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.