Use of Configurationsettings or XMLDocument class ????

  • Thread starter Thread starter serge calderara
  • Start date Start date
S

serge calderara

Dear all,

I have define a configuration file for my application with
different section groups and settings belonging to each
individual group like as follow :

=====================================================
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<!-- Definition of the User Management section -->
<sectionGroup name="UserManagement">
<section name="settings"

type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>

<!-- Definition of the Configuration Mangement
section -->
<sectionGroup name="ConfigurationManagement">
<section name="settings"

type="System.Configuration.NameValueSectionHandler" />
<section name="database"

type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>

<!-- Definition of the Language Management section -->
<sectionGroup name="LanguageManagement">
<section name="settings"

type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>

<!-- Definition of the HMI builder Management section --<sectionGroup name="HMIBuilder">
<section name="settings"

type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>
</configSections>

<!-- Definition of the User management assembly setting
Parameter define in this section are only used by
UserMangement -->
<UserManagement>
<settings>
<add key="LastLoginName"
value="calderara" />
<add key="RememberEntry" value="1" />
</settings>
</UserManagement>

<!-- Definition of the Configuration management
assembly setting
Parameter define in this section are only used by
UserMangement -->
<ConfigurationManagement>
<settings>
<add key="ConfigSaved" value="yes" />
<add key="AccessProviderDNS"
value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" />
</settings>
<database>
<add key="Path" value="E:\Configuration data
base" />
<add key="DNS"
value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" />
<add key="sqlserver" value="true" />
</database>
</ConfigurationManagement>

<!-- Definition of the Language management assembly setting
Parameter define in this section are only used by
UserMangement -->
<LanguageManagement>
<settings>
<add key="Default" value="English" />
</settings>
</LanguageManagement>

<!-- Definition of the HMI builder assembly setting
Parameter define in this section are only used by
UserMangement -->
<HMIBuilder>
<settings>
<add key="XPos" value="100" />
</settings>
</HMIBuilder>

<!-- Definition of the application setting
Find here any parameters for the global application
startup phase
key : represent the name of the key to scan
value: represent the actual value of the found key --<appSettings>
<add key="LogFile" value="TraceLog.txt" />
<add key="LogFilePath" value="C:" />
</appSettings>
<!-- Definition of the tracing operation
bActivate : Set tracing to ON or OFF (1=ON, 0=OFF)
TraceSeverity : define what type of message level
should be trace based
on TraceLevel (none, info, warning,fatal, verbose =
0,1,2,3,4)
Note that a value of 3 will trace also level 1 and
2 -->
<system.diagnostics>
<switches>
<add name="Enabled" value="1" />
<add name="TraceSeverity" value="1" />
</switches>
</system.diagnostics>
</configuration>

What is the best way to access and return those different
settings ?
Should I go with ConfigurationSettings class or use of
XMLDocument class ?

If A request is send to retrive parameter for a group I
should be able to rertreve all entry at once even if it
has different section.

thanks for your comments
regards
 
Hi Serge,
What is the best way to access and return those different
settings ?
Should I go with ConfigurationSettings class or use of
XMLDocument class ?

Go for the ConfigurationSettings class, e.g.

NameValueCollection userManagement;
userManagement = ConfigurationSettings.GetConfig("UserManagement")
as NameValueCollection;

and dereference like this:

userManagement["LastLoginName"]...

I think this is easier than using the XMLDocument class.
If A request is send to retrive parameter for a group I
should be able to rertreve all entry at once even if it
has different section.

Through the collection above you can retrieve any value in that group.
 
Thanks for your answer,

I go with Configurationsetting class for the time beeing.
But then I have one question:

How to know if the request parameter is valid ?

Exaemple:
userManagement = ConfigurationSettings.GetConfig("UserManagement")

I need first to be sure that the section "UserMangement is still present
and if not return an error
or by this :

userManagement["LastLoginName"]...

I need toi be sure first that LastLoginname is really present and if not
return an erro as well.

What is the way to identify that a section or group is present?

thanks for your answer
regards
 
Hi Serge,

calderara serge said:
userManagement["LastLoginName"]...

I need toi be sure first that LastLoginname is really present and if not
return an erro as well.

What is the way to identify that a section or group is present?

Well, you could check for a null and for extra safety use a try..catch
handler.
 
Back
Top