In my existing project I wanted to be able to store my User Interface Process configuration data OUTSIDE of my standard application configuration file (i.e. appname.exe.config or web.config). I felt that I was going to have a significant amount of navigational and process configuration data and I personally would be far happier storing it away from the standard config file. 


Perhaps I gave up too soon with the documentation and I am sure there is probably a sweeter way of achieving this requirement, but anyway here goes. Feel free to correct me if there is a better solution.


If want to store your User Interface Process Application Block 2 (UIPAB2) configuration data outside of the your main application configuration file then one method of achieving this is could be by using the Configuration Management Application Block (CMAB) in conjunction with the UIPAB2.



Conditions Of Using This Method

a) This method assumes you have working knowledge of both the UIPAB2 and the CMAB
b) You have to make very minor changes to the UIPAB2 source code in order to utilize this functionality . To download the the source code go to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/uipab.asp

The process of creating a UIPAB2 application is no different to normal. For tips on how to create applications using the UIPAB take a look at http://www.codeproject.com/dotnet/UIPAB1.asp and http://www.codeproject.com/dotnet/UIPAB2.asp for some great demos.

Incorporating the CMAB into your UIPAB2 project

STEP 1 – Add the Configuration Management Application Block and UIPAB2 to your solution. From the UIPAB2 project add a reference to it from the CMAB

STEP 2 – Add / amend you application configuration file to include the standard CMAB sections as shown in the sample below:

<configuration>
<!–The configSections and applicationConfigurationManagement sections are required for the CMAB–>
<configSections>
<section name=”applicationConfigurationManagement” type=”Microsoft.ApplicationBlocks.ConfigurationManagement.ConfigurationManagerSectionHandler,Microsoft.ApplicationBlocks.ConfigurationManagement, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null” />
<section name=”uipConfiguration” type=”Microsoft.ApplicationBlocks.UIProcess.UIPConfigHandler, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null”/>
</configSections>
<applicationConfigurationManagement>
<!–Implementation of the UIPAB as part of configuration management as opposed to using the standard config file readers–>
<!–Note that in this section we are pointing to an external configuration file, however we could be using any of the inbuilt CMAB functionality to hold the UIPAB configuration–>
<configSection name=”uipConfiguration”>
<configProvider assembly=”Microsoft.ApplicationBlocks.ConfigurationManagement,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null” type=”Microsoft.ApplicationBlocks.ConfigurationManagement.Storage.XmlFileStorage” signed=”false” refreshOnChange=”true” encrypted=”false” path=”..\..\..\TestConfigFile.config” />
</configSection>
</applicationConfigurationManagement>
<!–Usually the UIPAB config sections would appear here in the Config file. –>
<!–Because we are delegating the task to the CMAB they have been moved out–>
<!–to a seperate file location called TestConfigFile.config–>
</configuration>

STEP 3 – Move / create your UIPAB2 configuration file as per the sample shown below. NOTE THE USE OF TWO uipConfiguration nodes. This is due to differences in the way that the standard configuration reader works compared to the CMAB readers.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
<uipConfiguration>
<uipConfiguration>
<objectTypes>
<iViewManager
name=”ViewManager”
type=”Microsoft.ApplicationBlocks.UIProcess.WindowsFormViewManager, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null”/>
<state
name=”State”
type=”Microsoft.ApplicationBlocks.UIProcess.State, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null”/>
<controller
name=”UIController”
type=”InterfaceProcess.UIController, InterfaceProcess, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null” />
<statePersistenceProvider
name=”MemoryStatePersistence”
type=”Microsoft.ApplicationBlocks.UIProcess.MemoryStatePersistence, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null”/>
</objectTypes>
<views>
<view
name=”Explanation”
type=”DemoWindowsFormsApplication.Explanation, DemoWindowsFormsApplication, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null”
controller=”UIController”/>
<view
name=”Thanks”
type=”DemoWindowsFormsApplication.Thanks, DemoWindowsFormsApplication, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null”
controller=”UIController”/>
</views>
<navigationGraph name=”Nav”
startView=”Explanation”
state=”State”
statePersist=”MemoryStatePersistence”
iViewManager=”ViewManager”>
<node view=”Explanation”>
<navigateTo navigateValue=”Thanks” view=”Thanks” />
</node>
</navigationGraph>
</uipConfiguration>
</uipConfiguration>
</configuration>

STEP 4 – In the UIPAB2 Project open the Configuration\UIPConfiguration.cs file and add the following using directive :

using Microsoft.ApplicationBlocks.ConfigurationManagement;

STEP 5 – Modify the following line of code: (located in the public static UIPConfigSettings Config declaration)

Old Code

_currentConfig = (UIPConfigSettings)ConfigurationSettings.GetConfig( UipConfigSection );

New Code

_currentConfig = (UIPConfigSettings) ConfigurationManagement.ConfigurationManager.Read(UipConfigSection);

Sample Code Available For Download

Sample code is available for downloand from http://www.appsolutions.co.uk/samples/CombiningUIPABwithCMAB.zip

Post is provided as is. No guarantees are made as to its ability to function in a production environment.