Migration to EAB 2.0

Topics: Enterprise Library Core
Dec 10, 2007 at 9:27 AM
Hi all.

I'm having a problem. I've read a lot of web pages so far but I'm still very confused with the Configuration changes that appeared in version 2.0.

First:
My old App.config was something like:

<configuration>
<configSections>
<section name="enterpriselibrary.configurationSettings" type="Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManagerSectionHandler, Microsoft.Practices.EnterpriseLibrary.Configuration" />
</configSections>
<enterpriselibrary.configurationSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
applicationName="OneAgent" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration">
<configurationSections>
<!-- Application Configuration -->
<configurationSection name="ApplicationConfiguration" encrypt="false">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="Config\ApplicationConfiguration.config" />
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
<includeTypes />
</dataTransformer>
</configurationSection>
<!-- UI Configuration -->
<configurationSection name="UIConfiguration" encrypt="false">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="Config\UIConfiguration.config" />
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
<includeTypes />
</dataTransformer>
</configurationSection>
</configurationSections>
(...)

By words, I have about 4 ou 5 separated config files.

Question: Can I still do the same?


Second:
In my code, to retrieve the configuration values I used to do this:
ConfigurationManager.ClearSingletonSectionCache("UIConfiguration");
this.uIConfiguration = ConfigurationManager.GetConfiguration("UIConfiguration") as UIConfiguration;

This "UIConfiguration" is a section on "App.config" that points to "Config/UIConfiguration.config".

How can I do the same now? I think that I have to use IConfigurationSource but I can't understand how.

Any help will be appreciated.

Thanks
Dec 10, 2007 at 6:43 PM
Hi,

The config system was replaced to leverage the new configuration support from the .NET framework. Regarding storing configuration to a different file, this is supported by the .NET framework using the configSource property (see http://msdn2.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx) but no specific support is provided by the configuration tool for this.

For storing you own configuration, you can either use the framework's ConfigurationManager (see http://msdn2.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx) or use a configuration source. You can see some sample code at ms-help://ms.EntLib.2007May/EnterpriseLibrary/html/00-150-Adding_Application_Code.htm and get the configuration information using the GetSection method (see ms-help://ms.EntLib.2007May/EntLibAPIRef/html/c8dd1a11-9fb7-705c-9939-26af5a829fa0.htm).

Regards,
Fernando
Dec 11, 2007 at 8:11 AM
Sorry, I must be really dumb..
Can you help a little more?

So... Looks like that I don't need EAB to do what I want, right? But can I still use it? I have a lot of applications that use EAB and now I just want to migrate them to .NET 2.0.

So, first:
<configSections>
<section name="enterpriselibrary.configurationSettings" type="Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManagerSectionHandler, Microsoft.Practices.EnterpriseLibrary.Configuration" />
</configSections>

This ConfigurationManagerSectionHandler doesn't exist anymore, right? I can't find any similar class to replace :(


Second:
<configurationSection name="UIConfiguration" encrypt="false">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="Config\UIConfiguration.config" />
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
<includeTypes />
</dataTransformer>
</configurationSection>

Can EAB 2.0 understand this 'configurationSection'? I have a simple class "UIConfiguration" and when I do something like:
uiConfiguration = ConfigurationManager.GetConfiguration("UIConfiguration") as UIConfiguration;

with some kind of magic my class had all the properties set.

The UIConfiguration.config had this format:

<?xml version="1.0" encoding="utf-8"?>
<UIConfiguration>
<xmlSerializerSection type="Collab.OneContact.OneAgent.UIConfiguration, Collab.OneContact.OneAgent, Version=2.1.4.0, Culture=neutral, PublicKeyToken=null">
<UIConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<!-- MainBar, Context Menus -->
<ShowButtonAccept>true</ShowButtonAccept>
<ShowButtonDial>true</ShowButtonDial> <!-- MainBar only -->
<ShowButtonNewEmail>true</ShowButtonNewEmail>
<ShowButtonHangup>true</ShowButtonHangup>
...


Can you help me?
If possible I don't want to change a lot the external config files, like UIConfiguration.config, because that will give me some migration problems on the final client.
Dec 11, 2007 at 4:59 PM
Answers inline.


So... Looks like that I don't need EAB to do what I want, right? But can I still use it? I have a lot of applications that use EAB and now I just want to migrate them to .NET 2.0.

I'm not following you now. What's EAB? Is it the Enterprise Library? You can't still use EntLIb v1.1 with .NET 2.0, although it's not recommended.


So, first:
<configSections>
<section name="enterpriselibrary.configurationSettings" type="Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManagerSectionHandler, Microsoft.Practices.EnterpriseLibrary.Configuration" />
</configSections>

This ConfigurationManagerSectionHandler doesn't exist anymore, right? I can't find any similar class to replace :(

The complete configuration subsystem changed to leverage what the .NET v2.0 Framework provides. You may want to look at the new configuration support documentation from MSDN, like http://msdn2.microsoft.com/en-us/library/system.configuration.configurationmanager(VS.80).aspx and http://msdn2.microsoft.com/en-us/library/ms178688.aspx (note that it's described as ASP.NET configuration but applies to the .NET framework really). There's also a configuration quick start showing how things work now.


Second:
<configurationSection name="UIConfiguration" encrypt="false">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="Config\UIConfiguration.config" />
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
<includeTypes />
</dataTransformer>
</configurationSection>

Can EAB 2.0 understand this 'configurationSection'? I have a simple class "UIConfiguration" and when I do something like:
uiConfiguration = ConfigurationManager.GetConfiguration("UIConfiguration") as UIConfiguration;

with some kind of magic my class had all the properties set.

The UIConfiguration.config had this format:

<?xml version="1.0" encoding="utf-8"?>
<UIConfiguration>
<xmlSerializerSection type="Collab.OneContact.OneAgent.UIConfiguration, Collab.OneContact.OneAgent, Version=2.1.4.0, Culture=neutral, PublicKeyToken=null">
<UIConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<!-- MainBar, Context Menus -->
<ShowButtonAccept>true</ShowButtonAccept>
<ShowButtonDial>true</ShowButtonDial> <!-- MainBar only -->
<ShowButtonNewEmail>true</ShowButtonNewEmail>
<ShowButtonHangup>true</ShowButtonHangup>
...


Can you help me?
If possible I don't want to change a lot the external config files, like UIConfiguration.config, because that will give me some migration problems on the final client.


You can have your own configuration objects and use attributes to drive serialization. You can look at all the configuration objects from EntLib and the MSDN documentation at http://msdn2.microsoft.com/en-us/library/system.configuration.configurationpropertyattribute.aspx. I'm not sure whether you can keep your schema where properties seem to be serialized to individual elements; such properties are usually serialized as attributes.

Hope this helps,
Fernando