A simple model and maintenance tool for winform program configuration information-instructions for use

Source: Internet
Author: User
1. Preface

. NET Framework is a computer configuration and applicationProgramConfiguration and Security Information defines a set of standard configuration files. The memory ing and access of these configuration files are supported by the configuration assembly.

For some large-scale application systems and software in specialized fields, configuration information compilation and maintenance is a complex task. A while ago, due to the working relationship, a configuration assembly was used to design a simple model for defining the configuration information structure (which cannot be called a framework) and a maintenance tool. Although it is useless to change jobs, it seems to me that there is still practical value. Therefore, I sorted out the documents. If you need them, you can use this application.

This document describes how to use this model and tool.

For more information about container aion assembly, see msdn, especially the section on creating custom configurations. My Summary of configuration is in. NET Framework configuration summary.

For the design ideas of this model and tool, please refer to a simple design and maintenance tool for winform program configuration information-design description.

: Https://sourceforge.net/projects/yedaoqproject/files/YedaoqConfiguration/YedaoqConfiguration-Release.rar/download

2. Overview 2.1 What can it help you do?

This model and tool aims to help developers create a reasonably structured configuration information structure, improve efficiency, and reduce maintenance costs.

1. Assists in constructing tree-level Configuration structures.

2. AutomaticallyCodeThe defined configuration structure is synchronized to the configuration file.

3. Data in the configuration file is automatically read to the memory. Changes to the memory data are also automatically saved to the configuration file.

4. You can use the editor to intelligently perceive access to configuration information without using a keyword string.

5. Provide tools to edit the initial configuration data provided to each customer.

This model and tool are designed in the following three aspects:

1. Clear and hierarchical configuration structure.

2. Make the configuration information easy to access.

3. Block file operations.

2.2 what has been done based on configuration?

This model is partially extended by the configuration assembly and partially encapsulates the interfaces used by the original configuration assembly to simplify the use process.

1. Configuration access to configuration information is in the configuration file (ing as the configuration object ). This model provides appconfiguration, so that all configuration information of the entire system (which can be distributed and stored in multiple configuration files) forms an overall structure in the memory. This facilitates the use of configuration information and makes the configuration file more transparent to users.

2. Some restrictions and security issues related to configuration are addressed. Makes it easier to define the configuration structure.

3. An API prototype iappconfigurationprovider is provided for you to implement the enumeration and switching functions for multiple configuration files.

4. A tool is provided to synchronize the structure of the configuration file and edit the content of the configuration file.

3. User Guide 3.1 General Concepts

Configuration information tree: a tree-like configuration information structure defined by appconfiguration, configurationsection, and configurationsectiongroup. appconfiguration is the root node. You must use appconfiguration to define the root node, and appconfiguration cannot be used to define other nodes. Configurationsectiongroup is a non-leaf node of the tree. It is used to link parent nodes and child group (segment) nodes. configurationsection is a leaf node of the tree, which contains a set of configuration data.

Top-level Configuration group: directly defines the Configuration group in appconfiguration. The top-level Configuration group is different from the common sub-Configuration group. It is actually the outermost Configuration group in a configuration file, and is organized under the appconfiguration for the sake of integrity. Retrieving top-level Configuration groups requires not only name keywords, but also file names and other information. This information should be encapsulated in the iconfigurationunitinfo object and passed to the appconfiguration indexer.

Configuration scope: Microsoft divides configuration information into three scopes: Computer, application, and user. This model is limited to the application scope, so it contains the last two scopes. The concept of scope is generally used to determine the location of the configuration file (the configuration information of the application domain is generally stored in the installation directory, and the configuration information of the user domain is generally stored in my documents ), this is why two directory fields are provided in clientinfo.

3.2 type Overview

Assembly: yedaoqconfiguration. dll

Namespace: yedaoqconfiguration

Type

Description

Appconfiguration

The base class of the root node of the configuration information structure. The indexer is provided to obtain the top-level Configuration group.

Appconfigurationproviderattribute

Used to mark the attributes of appconfigurationprovider. The tool uses this attribute to find appconfigurationprovider from the Assembly.

Clientinfo

The basic implementation of iclientinfo, used to save the customer information (and the directory information of the configuration file ).

Configurationhelper

Provides public logic for obtaining configuration segments (groups) and reflection.

Configurationobjectmanager

Map the configuration file to a configuration object and manage the configuration object for appconfiguration.

Configurationsectiongroupinfo

Class that stores top-level Configuration group information.

Configurationsectioninfo

Class that stores the top-level Configuration segment information.

Configurationunitbase

The base classes of configurationsectiongroupinfo and configurationsectioninfo, which describe the information of the top-level Configuration unit.

Enumconfigdomain

Used to describe the scope (User Domain, application domain) of the top-level Configuration Group. This concept originated from Microsoft.

Exconfigurationsection

Inherit from configurationsection and implement icustomtypedescriptor. Any custom configurationsection should be based on this class.

Iappconfiguration

Configure the interface of the root node of the information structure. The Implementer should inherit the appconfiguration.

Iappconfigurationprovider

Enumerate users and provide users with iappconfiguration interfaces.

Iclientinfo

The implementation interface of clientinfo.

Iconfigurationobjectmanager

The implementation interface of configurationobjectmanager.

Iconfigurationunitinfo

The implementation interface of configurationunitbase.

3.3 use this model to transform your application and use tools to maintain configuration information

To use this model and tool, you must do the following:

1. Use appconfiguration, configurationsection, and configurationsectiongroup to define the configuration information structure model;

2. Implement an iappconfigurationprovider.

3.3.1 define the configuration information structure model

Create all custom configurationsections and configurationsectiongroup using the declarative model. The custom configurationsection must be inherited from the exconfigurationsection. Otherwise, the list displayed by the maintenance tool contains redundancy information. For declarative models, seeArticle.

Create a derived class from appconfiguration and define the top-level Configuration group.

For example, refer to the program Test Project: Configurationsectiona , Configurationsectionb , Configurationsectiongrouptest , Testappconfiguration .

3.3.2 Implementation Iappconfigurationprovider

Iappconfigurationprovider is an interface for enumerating customers and obtaining customer configurations. Applications should implement relevant logic independently. The implementation class of iappconfigurationprovider must be:

1. constructor with no parameters.

2. Use appconfigurationproviderattribute to modify the attributes.

The maintenance tool uses this interface to obtain the customer list and appconfiguration data of each customer. The process of using this interface is as follows:

Image.

As an example, we assume that the configuration information of our application is stored in the config subdirectory. There are several customers. each customer's configuration file is placed in a sub-directory of config. These Sub-directories have the same name as the customer name. Then, you can implement iappconfigurationprovider in this way:

See program Test Project: Testappconfigurationprovider .

3.3.3 use of configurationmodifier

Place configurationmodifier.exe in the application directory. When it is enabled, this tool searches all the assemblies in the directory for classes with the appconfigurationproviderattribute attribute. If yes, the customer list is displayed in the list box in the upper left corner. Select the customer whose configuration information you want to edit. The configuration information tree is displayed in the left-side Treeview. After selecting the leaf node, you can edit the configuration items in the Custom configurationsection in propertygrid on the right.

3.3.4 source program Compilation

Source program: https://yedaoqproject.svn.sourceforge.net/svnroot/yedaoqproject/YedaoqConfiguration

Before compilation, download another dependent assembly and reference it to the yedaoqconfiguration and configurationmodifier projects.

The dependent assembly location is: https://sourceforge.net/projects/yedaoqproject/files/MySolution/CommonLibrary.dll/download

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.