Environmental Overrides question

Jun 20, 2008 at 3:39 PM
Using visual studio, I created a environment called 'development', override my connection string, generated development.config and development.dconfig. I saved app.config and close it. Later, my configuration changed, I opened the app.config, but I didn't see the 'development' environment! What can I do to make it shows back with correct settings overrided in the editor screen?
Jun 20, 2008 at 3:47 PM
Hi,

You need to explicitly load the environmental overrides every time you need to use them. You do this by choosing the "Open Environment Delta" item in the context menu on the Environments node, and picking your delta file.

Fernando


mail_dcb wrote:
Using visual studio, I created a environment called 'development', override my connection string, generated development.config and development.dconfig. I saved app.config and close it. Later, my configuration changed, I opened the app.config, but I didn't see the 'development' environment! What can I do to make it shows back with correct settings overrided in the editor screen?


Jun 25, 2008 at 9:52 AM
I think it would be graet if you could select multiple delta files to open. In a recent project I have about 30 delta files.
Another nice feature wold be if EntLib loaded the delta files when opening a config file.

//Magnus
Jun 25, 2008 at 3:13 PM
That's quite a number. I logged a feature request for it http://www.codeplex.com/entlib/WorkItem/View.aspx?WorkItemId=17163.

I was going to suggest you created a new command that would let you load multiple files in a stand-alone design-time assembly that you could drop with the released binaries, and actually tried it out (it's really simple, the code is below with no resources so it stands on its own). However, there's a problem: in order for this to work reliably, the ConfigurationDesignManager attribute should reference the EnvironmentalOverridesConfigurationDesignManager as a prerrequisite so the tool ensures the design-time support is loaded in the right order; unfortunately, the environmental overrides design manager type is not public so you cannot reference it from an external assembly. I tried the code below and it worked for me, but if you try it YMMV.


using System;

using System.Globalization;

using System.Windows.Forms;

using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;

using Microsoft.Practices.EnterpriseLibrary.Configuration.EnvironmentalOverrides;

 

[assembly: ConfigurationDesignManager(typeof(OpenMultipleEnvironments.OpenMultipleEnvironmentsDesignManager))]

 

namespace OpenMultipleEnvironments

{

    class OpenMultipleEnvironmentsDesignManager : ConfigurationDesignManager

    {

        public override void Register(IServiceProvider serviceProvider)

        {

            new OpenMultipleEnvironmentsCommandRegistrar(serviceProvider).Register();

        }

    }

 

    class OpenMultipleEnvironmentsCommandRegistrar : CommandRegistrar

    {

        public OpenMultipleEnvironmentsCommandRegistrar(IServiceProvider serviceProvider)

            : base(serviceProvider)

        { }

 

        public override void Register()

        {

            ConfigurationUICommand openEnvironmentDelta = new ConfigurationUICommand(ServiceProvider,

                "Open Multiple Environment Deltas",

                "Open Multiple Environment Delta Files",

                CommandState.Enabled,

                new OpenMultipleEnvironmentsDeltaCommand(ServiceProvider),

                Shortcut.None, InsertionPoint.Action, null);

 

            AddUICommand(openEnvironmentDelta, typeof(EnvironmentalOverridesNode));

        }

    }

 

    class OpenMultipleEnvironmentsDeltaCommand : ConfigurationNodeCommand

    {

        public OpenMultipleEnvironmentsDeltaCommand(IServiceProvider serviceProvider)

            : base(serviceProvider)

        {

        }

 

        protected override void ExecuteCore(ConfigurationNode node)

        {

            IUIService uiService = ServiceHelper.GetUIService(ServiceProvider);

 

            using (OpenFileDialog fileDialog = new OpenFileDialog())

            {

                fileDialog.Filter = "Environment Delta File (*.dconfig)|*.dconfig";

                fileDialog.CheckFileExists = true;

                fileDialog.CheckPathExists = true;

                fileDialog.AddExtension = true;

                fileDialog.DefaultExt = ".dconfig";

                fileDialog.RestoreDirectory = true;

                fileDialog.Multiselect = true;

 

                if (DialogResult.OK == uiService.ShowOpenDialog(fileDialog))

                {

 

                    uiService.BeginUpdate();

                    try

                    {

                        foreach (string fileName in fileDialog.FileNames)

                        {

                            try

                            {

                                EnvironmentNodeBuilder nodeBuilder = new EnvironmentNodeBuilder(ServiceProvider);

                                EnvironmentNode childNode = nodeBuilder.Build(fileName, node.Hierarchy);

 

                                node.AddNode(childNode);

                                uiService.SetUIDirty(node.Hierarchy);

                                uiService.ActivateNode(childNode);

                            }

                            catch (Exception e)

                            {

                                uiService.ShowError(e, string.Format(CultureInfo.CurrentCulture, "Error opening the file '{0}", fileName));

                            }

                        }

                    }

                    finally

                    {

                        uiService.EndUpdate();

                    }

                }

            }

        }

    }

}

<!--EndFragment-->


magnushogberg wrote:
I think it would be graet if you could select multiple delta files to open. In a recent project I have about 30 delta files.
Another nice feature wold be if EntLib loaded the delta files when opening a config file.

//Magnus



Nov 5, 2008 at 7:09 AM
Hi,

I have diffrent application environments: Development, Test, Staging, Production, etc
Currently, I am logging using Database Trace Listner programatically.
Now, I need to load environment specific details (e.g connection string for Development, Test, Staging, Production etc) programatically.
How/Where can i specify environment specific details in my web.config or anywhere else?

Anyone have sample example for above scanerio?

Thanks,
Kaushal