Configuration (Zhuan) of Enterprise Library)

Source: Internet
Author: User
Lai zi http://www.vbgood.com/vb.good/article-do-view-articleid-3856.html
First, the configurationmanager class is actually a collection of basic operation configuration data methods. This class has no specific purpose.

The most important class is the configurationbuilder class, which is the class for initial configuration.
There is also the configurationfile class, which is used to parse configuration files in XML format, and to add, delete, and update nodes in the XML file.
This type of Microsoft writes it too complicated. The specific configuration data and metadata are parsed by it. Complex.

The following describes how to use
Configurationmanager. getconfiguration ("configuration name ")
To configure the system operation process.

First, he uses the configurationmanager. Current internal attribute to check whether the configurationbuilder class has been created. If yes, the created configurationbuilder class is called. Obviously, this is a typical single-piece mode.
Then it calls the readconfiguration () method in the configurationbuilder class. The parameter is the configuration name we entered.

When a new configurationbuilder class instance is created
System. appdomain. currentdomain. setupinformation. configurationfile
Attribute acquisition ApplicationProgramMain configuration file (winform is app. config, webform is web. config), and then create a new configurationfile instance to parse the "enterpriselibrary. the content of the configurationsettings node generates an instance of the configurationsettings class. This instance contains an configurationsectiondatacollection class instance whose content is configurationsectiondata.

The configurationsectiondata and configurationsectiondatacollection instances are stored in the enterpriselibrary. configurationsettings content in the application configuration file.
A configurationsectiondatacollection collection is the content of a "configurationsections" node.
A configurationsectiondata is the content of the "configurationsection" node in the configuration file.

The sectionname attribute of the configurationsectiondata class is the name attribute of the configurationsection of the configuration file.

After resolving the application configuration file, the configurationbuilder starts to use the configurationsectiondatacollection indexer to find users from:
Configurationmanager. getconfiguration ("configuration name ")
The method is passed to the "configuration name" to check whether there is a configuration section with the same name in the collection. If there is a configuration section, a configurationsectiondata class instance is returned. If not, an exception is thrown.

After obtaining the configurationsectiondata instance, the system analyzes the content and finds out the content of "storageprovider" in the configurationsection in the configuration file. Of course, the current version only contains "xmlfilestorageproviderdata ", that is, the specific configuration data is stored in. in the config file, so you can continue to find the path attribute and get the actual configuration data saved by the user for "configuration name. the actual config address.
And get the data of xmlserializertransformerdata.

Here, the system processes the app. config/web. at this point, the system has learned the path and file name of the XML configuration file for storing specific configuration data, as well as the xmlserializertransformerdata.

Next, the control is transferred to the configurationbuilder. He creates a new configurationfile instance to parse the xml configuration file obtained from app. config. Configurationfile uses xmltextreader to process all content in the configuration file.

It obtains the object type serialized in the file through a fixed configuration section name "xmlserializersection" attribute type, and then generates the object through reflection, save all the child nodes (XML deserialization data) and their names to a hashtable. The parsing of an XML file ends.

As you know, in the application system configuration file app. config/Web. config, configuration data can be a collection, that is, processing multiple configuration files. Therefore, the result of the hashtable object storing the parsing result in configurationfile is thread-safe. configurationbuilder saves all the loop processing in the app. confi content, after processing all configuration files, stop file parsing.
At this time, the system will actually process the "configuration file name" entered by the user.
Configurationbuilder extracts the required configuration data from the cache. It is an object and then creates an itransformer interface type object (actually xmlserializertransformer) to obtain the object type and data to be deserialized, execute deserialization, and then return the object to the configurationmanager object, and then return it to the user. Then you only need to perform a forced type conversion to get the configuration content.

It is too complicated. Up to now, there are still many classes that have not been understood, including how to set up a monitoring class to start the background thread to monitor configuration data changes.
The role of the configurationcontext class and configurationview class is unclear. It is too troublesome.

In addition:

I took the time to read the cryptography Application Block of the Enterprise Library in the afternoon. I didn't find the meaning of the block launched by Microsoft.

First, this block provides two purposes. One is to perform symmetric encryption on the user-input string, and the other is to perform hash Hash hash operations on the user-input string to prevent the string from being modified.

Both methods are not very practical. Because the. NET class library already provides this function. For example
System. Security. cryptography. descryptoserviceprovider performs weak encryption
System. Security. cryptography. tripledescryptoserviceprovider executes strong encryption

The following two classes are also used:
System. Security. cryptography. rsapkcs1signatureformatter hashes the data to obtain the hashes.
System. Security. cryptography. rsapkcs1signaturedeformatter performs verification on data and hash content

In addition, I used its Quickstart, and I don't know why it is very slow. Why do we need to write blocks for the provided functions?

In addition, what I think is unpleasant is that most of the classes in the system. Security. cryptography. x509certificates namespace are explained in English.

In Visual Basic 6, many applications use the Windows registry to save settings. Visual Basic. NET provides application configuration files to implement the same functions. These configurations eliminate some development issues associated with the Registry and make it easy to modify the settings in your application.

First, create a new visual basic. Net project. Next, enter a new project in the project and select the application configuration file. This will add a new file named app. config in your project. (When an application is compiled, the file name is changed to the component name .)

This configuration file is in XML format. You need to add a new node named deleetaskunder the configuration node. This node contains application settings. Add a node named add with two attributes: Key and value. The key contains the values used to search for the settings, and the value contains the set values:

<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Deleetask>
<Add key = "testsetting" value = "test value"/>
</Appsettings>
</Configuration>

To obtain the set value, you must create a new instance for appsettingsreader.

Dim settingreader as new system. configuration. appsettingsreader ()

To obtain a setting, call the getvalue method. It accepts two independent variables: the key value and the set type:

Msgbox (settingreader. getvalue ("testsetting", GetType (string )))

The application configuration file provides a convenient, simple, and achievable Method for saving application settings.

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.