13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 15: .<strong>NET</strong> Framework ApplicationConfigurationOverviewTo the extent that it is possible, all applications, regardless of plat<strong>for</strong>m, should bedesigned <strong>in</strong> a parametric way and should read some of their sett<strong>in</strong>gs from an externalfile. Simply by updat<strong>in</strong>g the configuration file, developers and system adm<strong>in</strong>istrators canchange the way <strong>in</strong> which the application works as well as elements of the user<strong>in</strong>terface. In <strong>Microsoft</strong> W<strong>in</strong>dows 3.x, user preferences and application sett<strong>in</strong>gs wereusually stored <strong>in</strong> INI files located <strong>in</strong> the W<strong>in</strong>dows folder or <strong>in</strong> the application's ma<strong>in</strong>directory. This practice was reta<strong>in</strong>ed <strong>in</strong> <strong>Microsoft</strong> W<strong>in</strong>32, although s<strong>in</strong>ce W<strong>in</strong>dows 95,the system registry has become the recommended store <strong>for</strong> W<strong>in</strong>32 and ComponentObject Model (COM) application sett<strong>in</strong>gs. With both INI files and the registry, however,the developer had a certa<strong>in</strong> degree of freedom <strong>in</strong> design<strong>in</strong>g the layout of the data.Various guidel<strong>in</strong>es have been suggested over time, but <strong>in</strong> fact the structure of INI filesand registry subtrees was different from one application to the next.The <strong>Microsoft</strong> .<strong>NET</strong> Framework def<strong>in</strong>es a tailor-made, <strong>XML</strong>-based API to accessconfiguration files and, <strong>in</strong> do<strong>in</strong>g so, <strong>for</strong>ces developers to adopt a common, rich, andpredef<strong>in</strong>ed schema <strong>for</strong> stor<strong>in</strong>g application sett<strong>in</strong>gs. Us<strong>in</strong>g configuration files,adm<strong>in</strong>istrators can control which resources a user can access, which versions ofassemblies an application will use and from where, and which connection str<strong>in</strong>gsshould be used. Configuration files can also <strong>in</strong>clude application-specific sett<strong>in</strong>gs suchas the buttons to be displayed on the toolbar, the size and position of controls, andother, more specific, state <strong>in</strong><strong>for</strong>mation. Us<strong>in</strong>g configuration files, you give yourapplication a bunch of dynamic properties and elim<strong>in</strong>ate the need to recompile everytime different sett<strong>in</strong>gs should be applied..<strong>NET</strong> Framework configuration files are <strong>XML</strong> files saved with the .config extension andnamed and located accord<strong>in</strong>g to the type of the application. Managed code can use theclasses <strong>in</strong> the System.Configuration namespace to read sett<strong>in</strong>gs from the configurationfiles but not to write sett<strong>in</strong>gs to those files. Configuration files are considered pla<strong>in</strong> <strong>XML</strong>files, and appropriate <strong>XML</strong> writers should be used to edit their contents.In this chapter, we'll delve <strong>in</strong>to the .<strong>NET</strong> Framework configuration eng<strong>in</strong>e, review<strong>in</strong>g thecharacteristics of the ma<strong>in</strong> classes <strong>in</strong>volved and how key tasks are accomplished. We'llanalyze the various types of configuration files and their overall schemas, and you'lllearn how to customize a .config file with custom tags and custom contents.Configuration FilesThe .<strong>NET</strong> Framework provides three basic types of configuration files: mach<strong>in</strong>e,application, and security. Despite their different contents and goals, all configurationfiles are <strong>XML</strong> files and share the same schema. For example, all configuration filesbeg<strong>in</strong> with a node and then differentiate their contents and child nodesaccord<strong>in</strong>g to the f<strong>in</strong>al goal and the <strong>in</strong><strong>for</strong>mation conta<strong>in</strong>ed. In this chapter, we'll focusprimarily on application configuration files, but this section also provides a quick<strong>in</strong>troduction to the other types of configuration files.504

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!