Custom XML dynamic configuration program

Source: Internet
Author: User

Overview

1. When developing programs, we often need to use the following two basic modules:

1> set basic program parameters, such as paging parameters and mail parameters;

2> in table-based development, some judgment logic is placed in table data;

2. In these two basic scenarios, we have the following requirements:

1> Centralized Management;

2> to be configurable, modify the parameters without restarting the system;

3> easy to use.

Main functions of the program

1> set basic program parameters, such as paging parameters and mail parameters;

---- Automatically add the configuration information in XML to the corresponding object.

2> in table-based development, some judgment logic is placed in table data;

---- Automatically load the Dctionary data in XML to the corresponding entity. However, this method needs to be further optimized. Currently, it only supports loading Dictionary and more complex structures.

Main Code

1. First define and reference the entity in the code.

Example

        Dictionary<, > Dictionary<, >

2. Define the corresponding XML file. The basic configuration information of the program is configured in AppSettings.

Under the node.

                                                                       

3. Finally, a piece of XML loading code is required to load the XML configuration information in 2 to the object in 1.

       Dictionary<, Dictionary<, >> DictAppSettings =  Dictionary<, Dictionary<, >>= System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory.ToString(),    LoadSettings(            XmlNode dictRootNode = FileHelper.GetXMLNode(path,  (XmlNode dictType <, > dict =  Dictionary<, > (XmlNode dictItem ].Value.Trim(), dictItem.Attributes[             serializer =              jAppSetting = serializer.Serialize(DictAppSettings[             jDict =             json = .Format(, jAppSetting.Remove(jAppSetting.Length - ), jDict.Remove(, = serializer.Deserialize<AppSetting>   CacheRemovedCallback( key,              xmlFilePath = (            System.Threading.Thread.Sleep(    XmlNode GetXMLNode( path, =    CacheDependencyFile(= 
Final Effect

1. When the program runs for the first time, the corresponding configuration information is output.

2. When you modify some parameters, you can obtain the latest information without restarting them. Note: After modifying the parameters for 3 seconds, refresh the page.

 

Download complete code

Related Article

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.