Mgen spa Engineering 2 tutorial (Part 1): Interface Generation option-spaobjectoption

Source: Internet
Author: User

Back to the tutorial directory

In the previous tutorial, we learned about the four major components of the SPA project. In this tutorial, we started to step into the code section. This section describes the options generated on the interface to prepare for creating an instance program in the next section.

Directory

  • 1. Option type Overview
  • 2. multi-language resource storage
  • 3. verification options

 

Returned directory
1. Option type Overview

The Interface Generation option is easy to understand. As described in its name, it provides configuration setting parameters for the generated interface.

The option type generated on the Interface corresponds to the spaobjectoption type, which is in the mgen. Spa namespace. This type is defined as follows:

 

This type is simple and has three attributes, which represent three configuration options respectively.

The title attribute is the simplest. It refers to the description text of the entire process (or interface). For example, if the generated interface is the login interface, the title attribute can be "login ". Note that it will be displayed in different forms on different platforms. For example, in Windows Forms based programs such as WPF, the title attribute will be displayed on the title of the dialog box form, in a page-based environment such as Windows Phone or winrt, the title is displayed as the page title.

 

Next, let's take a closer look at the remaining two attributes.

 

 

 

Returned directory
2. multi-language resource storage

The second lecture describes the resource storage configuration for multiple languages. This option corresponds to the resourceprovider attribute of spaobjectoption.

 

We know that the SPA project fully supports multiple languages. The same data can be edited in different languages as follows:

 

To implement such a function, any place that represents the interface text must exist in the form of a key, and resources in each language are stored in the resource. When the SPA project creates an interface, it finds the corresponding key from the corresponding resource storage, retrieves the specific language value, and then displays it on the interface.

Therefore, the function of resource storage is to find resources in the corresponding language based on the corresponding key. The required language is defined in the currentuiculture attribute of the current thread (this is. Net content ). The spa does not limit the specific execution of resource storage, but uses an interface to define the resource storage format.

 

The resourceprovider attribute of spaobjectoption is the iresourceprovider interface, which represents a resource storage type. It is defined in the mgen. Spa namespace as follows:

Namespace mgen. SPA

{

Public interface iresourceprovider

{

String getstring (string key );

String getenum (Enum E );

}

}

 

The iresourceprovider interface defines two methods: getstring and getenum.

Getstring is what we mentioned above. The parameter is the key, and the return value is the corresponding text of the current language. Getenum: Let's talk about the selector control. Now, you can ignore it.

 

Of course, developers do not need to inherit the iresourceprovider interface each time they use resources. The SPA project provides a default execution type of the defaultresprovider type, which is also in the mgen. Spa namespace. The execution of this type is simple:

Public class defaultresprovider: iresourceprovider

{

ResourceManager resmgr;

 

Public defaultresprovider (type restype)

{

If (restype = NULL)

{

Throw new argumentnullexception ("restype ");

}

Resmgr = new ResourceManager (restype );

}

 

Public String getstring (string key)

{

Return resmgr. getstring (key );

}

 

Public String getenum (Enum E)

{

Return resmgr. getstring (E. GetType (). Name + "_" + E. tostring ());

}

}

 

You can see that the defaultresprovider type is initialized through a resx Resource Type generated by Visual Studio. The execution of the getstring method actually returns the key value of the resx resource. The execution of getenum is to connect the enumeration type name and enumeration value with "_" as a key, and then obtain the language and text from the internal resources.

 

 

 

 

Returned directory
3. verification options

The last introduced option is the verification option, which corresponds to the validationoption attribute of spaobjectoption. Its type is validationoption, which is also in the mgen. Spa namespace. It contains three sub-attributes, which are described in detail:

 

1. Verify the trigger option: validationtrigger attribute

The verification trigger option defines when the control will be verified. The verification trigger option corresponds to the validationtrigger enumeration (similar to validationtrigger in WPF). The following options are available:

Propertychanged: each time the user changes the control, the verification is executed.

Lostfocus: when the control loses focus, the verification is executed.

Explicit: verification is not automatically executed and needs to be manually called by the developer. (This will be discussed later in this tutorial)

 

2. Verification option after loading: onloadvalidation attribute

After loading, the verification option defines whether to perform verification immediately after the spa generates the interface. Corresponds to the onloadvalidation enumeration. Options include:

None

Required: Verify

 

For example, we need a non-empty string, but the text box is empty by default. If the setting is not verified after loading, no error is prompted after the interface is displayed (because verification is not performed ):

 

If the verification is set after loading, the interface will be verified immediately after display:

 

3. object option: objectoption attribute

The object option defines whether the data storage after the target object is updated, corresponding to the objectoption enumeration. The options include:

New: the values of all controls on the interface are empty.

Edit: the control on the interface reads the core values.

 

This is easy to understand. In fact, it is to tell the spa whether you want to create a new interface or read the data of the object behind it to edit it. Note the combination of objectoption and onloadvalidation.

 

OK. This part of Interface Options is very simple. We will use the knowledge learned in this section in the next section, then define the type, generate the type data, and bind the object, finally, create the hello World Program for the SPA project on each platform. In Part 1 of the tutorial, we will talk about this part based on the example.

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.