ConfigurationHandlersInstallComponent.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Tools / xws_reg / System / ServiceModel / Install / Configuration / ConfigurationHandlersInstallComponent.cs / 2 / ConfigurationHandlersInstallComponent.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

namespace System.ServiceModel.Install.Configuration 
{
    using System; 
    using System.Collections.Generic; 
    using System.Configuration;
    using System.IO; 
    using System.Reflection;
    using System.ServiceModel.Channels;
    using System.Text;
    using System.Xml; 
    using System.Xml.Serialization;
    using System.Globalization; 
 
    internal class ConfigurationHandlersInstallComponent : ServiceModelInstallComponent
    { 
        ConfigurationLoader configLoader;
        string displayString;
        ServiceModelConfiguration serviceModelConfiguration;
 
        ConfigurationHandlersInstallComponent(ConfigurationLoader configLoader)
        { 
            // Get the XML we need to add. 
            Assembly assembly = this.GetType().Assembly;
 
            using (Stream stream = assembly.GetManifestResourceStream(ServiceModelInstallStrings.ServiceModelConfigurationXml))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(ServiceModelConfiguration));
                this.serviceModelConfiguration = (ServiceModelConfiguration) serializer.Deserialize(stream); 
            }
 
            this.configLoader = configLoader; 
        }
 
        internal override string DisplayName
        {
            get {return this.displayString; }
        } 

        protected override string InstallActionMessage 
        { 
            get
            { 
                Configuration config = configLoader.MachineConfiguration;
                StringBuilder message = new StringBuilder();

                if (null != this.serviceModelConfiguration.SectionGroups && 
                    0 < this.serviceModelConfiguration.SectionGroups.Count)
                { 
                    for (int i = 0; i < this.serviceModelConfiguration.SectionGroups.Count; i++) 
                    {
                        ServiceModelConfigurationSectionGroup indigoSectionGroup = this.serviceModelConfiguration.SectionGroups[i]; 
                        message = message.Append(SR.GetString(SR.CommunicationSectionInstall, indigoSectionGroup.Name, config.FilePath));

                        if (i + 1 < this.serviceModelConfiguration.SectionGroups.Count)
                        { 
                            message = message.Append("\n");
                        } 
                    } 
                }
 
                if (null != this.serviceModelConfiguration.Sections &&
                    0 < this.serviceModelConfiguration.Sections.Count)
                {
                    if (0 < message.Length) 
                    {
                        message = message.Append("\n"); 
                    } 

                    for (int i = 0; i < this.serviceModelConfiguration.Sections.Count; i++) 
                    {
                        ServiceModelConfigurationSection indigoSection = this.serviceModelConfiguration.Sections[i];
                        message = message.Append(SR.GetString(SR.CommunicationSectionInstall, indigoSection.Name, config.FilePath));
 
                        if (i + 1 < this.serviceModelConfiguration.Sections.Count)
                        { 
                            message = message.Append("\n"); 
                        }
                    } 
                }

                return message.ToString();
            } 
        }
 
        internal override string[] InstalledVersions 
        {
            get 
            {
                List installedVersions = new List();

                Configuration config = configLoader.MachineConfiguration; 

                if (null != this.serviceModelConfiguration.SectionGroups) 
                { 
                    foreach (ServiceModelConfigurationSectionGroup indigoSectionGroup in this.serviceModelConfiguration.SectionGroups)
                    { 
                        if (IsSectionGroupInstalled(indigoSectionGroup.Name, ref config))
                        {
                            ConfigurationSectionGroup sectionGroup = config.SectionGroups[indigoSectionGroup.Name];
 
                            string versionString = InstallHelper.GetVersionStringFromTypeString(sectionGroup.Type);
 
                            if (!String.IsNullOrEmpty(versionString)) 
                            {
                                installedVersions.Add(indigoSectionGroup.Name + ServiceModelInstallStrings.VersionStringSeparator + versionString); 
                            }
                        }
                        else if (null == config)
                        { 
                            config = configLoader.MachineConfiguration;
                        } 
                    } 
                }
 
                if (null != this.serviceModelConfiguration.Sections)
                {
                    foreach (ServiceModelConfigurationSection indigoSection in this.serviceModelConfiguration.Sections)
                    { 
                        if (IsSectionInstalled(indigoSection.Name, ref config))
                        { 
                            SectionInformation section = config.Sections[indigoSection.Name].SectionInformation; 

                            string versionString = InstallHelper.GetVersionStringFromTypeString(section.Type); 

                            if (!String.IsNullOrEmpty(versionString))
                            {
                                installedVersions.Add(indigoSection.Name + ServiceModelInstallStrings.VersionStringSeparator + versionString); 
                            }
                        } 
                        else if (null == config) 
                        {
                            config = configLoader.MachineConfiguration; 
                        }
                    }
                }
 
                return installedVersions.ToArray();
            } 
        } 

        internal override bool IsInstalled 
        {
            get
            {
                Configuration config = configLoader.MachineConfiguration; 
                if (null != this.serviceModelConfiguration.SectionGroups)
                { 
                    foreach (ServiceModelConfigurationSectionGroup indigoSectionGroup in this.serviceModelConfiguration.SectionGroups) 
                    {
                        if (!IsSectionGroupInstalled(indigoSectionGroup.Name, ref config)) 
                        {
                            return false;
                        }
                    } 
                }
 
                if (null != this.serviceModelConfiguration.Sections) 
                {
                    foreach (ServiceModelConfigurationSection indigoSection in this.serviceModelConfiguration.Sections) 
                    {
                        if (!IsSectionInstalled(indigoSection.Name, ref config))
                        {
                            return false; 
                        }
                    } 
                } 

                return true; 
            }
        }

        protected override string ReinstallActionMessage 
        {
            get 
            { 
                Configuration config = configLoader.MachineConfiguration;
                StringBuilder message = new StringBuilder(); 

                if (null != this.serviceModelConfiguration.SectionGroups &&
                    0 < this.serviceModelConfiguration.SectionGroups.Count)
                { 
                    for (int i = 0; i < this.serviceModelConfiguration.SectionGroups.Count; i++)
                    { 
                        ServiceModelConfigurationSectionGroup indigoSectionGroup = this.serviceModelConfiguration.SectionGroups[i]; 
                        message = message.Append(SR.GetString(SR.CommunicationSectionReinstall, indigoSectionGroup.Name, config.FilePath));
 
                        if (i + 1 < this.serviceModelConfiguration.SectionGroups.Count)
                        {
                            message = message.Append("\n");
                        } 
                    }
                } 
 
                if (null != this.serviceModelConfiguration.Sections &&
                    0 < this.serviceModelConfiguration.Sections.Count) 
                {
                    if (0 < message.Length)
                    {
                        message = message.Append("\n"); 
                    }
 
                    for (int i = 0; i < this.serviceModelConfiguration.Sections.Count; i++) 
                    {
                        ServiceModelConfigurationSection indigoSection = this.serviceModelConfiguration.Sections[i]; 
                        message = message.Append(SR.GetString(SR.CommunicationSectionReinstall, indigoSection.Name, config.FilePath));

                        if (i + 1 < this.serviceModelConfiguration.Sections.Count)
                        { 
                            message = message.Append("\n");
                        } 
                    } 
                }
 
                return message.ToString();
            }
        }
 
        protected override string UninstallActionMessage
        { 
            get 
            {
                Configuration config = configLoader.MachineConfiguration; 
                StringBuilder message = new StringBuilder();

                if (null != this.serviceModelConfiguration.SectionGroups &&
                    0 < this.serviceModelConfiguration.SectionGroups.Count) 
                {
                    for (int i = 0; i < this.serviceModelConfiguration.SectionGroups.Count; i++) 
                    { 
                        ServiceModelConfigurationSectionGroup indigoSectionGroup = this.serviceModelConfiguration.SectionGroups[i];
                        message = message.Append(SR.GetString(SR.CommunicationSectionUninstall, indigoSectionGroup.Name, config.FilePath)); 

                        if (i + 1 < this.serviceModelConfiguration.SectionGroups.Count)
                        {
                            message = message.Append("\n"); 
                        }
                    } 
                } 

                if (null != this.serviceModelConfiguration.Sections && 
                    0 < this.serviceModelConfiguration.Sections.Count)
                {
                    if (0 < message.Length)
                    { 
                        message = message.Append("\n");
                    } 
 
                    for (int i = 0; i < this.serviceModelConfiguration.Sections.Count; i++)
                    { 
                        ServiceModelConfigurationSection indigoSection = this.serviceModelConfiguration.Sections[i];
                        message = message.Append(SR.GetString(SR.CommunicationSectionUninstall, indigoSection.Name, config.FilePath));

                        if (i + 1 < this.serviceModelConfiguration.Sections.Count) 
                        {
                            message = message.Append("\n"); 
                        } 
                    }
                } 

                return message.ToString();
            }
        } 

        // ConfigurationSection.Equals does not compare the AllowDefinition nor the AllowExeDefinition 
        // fields for equality. 
        bool CompareSections(ConfigurationSection configSection, ConfigurationSection installedConfigSection)
        { 
            bool retVal = false;

            if (null != configSection && null != installedConfigSection)
            { 
                if (configSection.GetType() == installedConfigSection.GetType())
                { 
                    SectionInformation compareSectionInfo = configSection.SectionInformation; 
                    SectionInformation installSectionInfo = installedConfigSection.SectionInformation;
 
                    if (String.Equals(compareSectionInfo.Type, installSectionInfo.Type, StringComparison.Ordinal))
                    {
                        if (compareSectionInfo.AllowDefinition == installSectionInfo.AllowDefinition)
                        { 
                            if (compareSectionInfo.AllowExeDefinition == installSectionInfo.AllowExeDefinition)
                            { 
                                retVal = true; 
                            }
                        } 
                    }
                }
            }
 

            return retVal; 
        } 

        internal static ConfigurationHandlersInstallComponent CreateNativeConfigurationHandlersInstallComponent() 
        {
            ConfigurationHandlersInstallComponent configurationHandlers = new ConfigurationHandlersInstallComponent(new NativeConfigurationLoader());
            configurationHandlers.displayString = SR.GetString(SR.CommunicationSectionName);
            return configurationHandlers; 
        }
 
        internal static ConfigurationHandlersInstallComponent CreateWow64ConfigurationHandlersInstallComponent() 
        {
            if (!InstallHelper.Is64BitMachine() || String.IsNullOrEmpty(InstallHelper.Wow64MachineConfigFileName)) 
            {
                throw new ConfigurationLoaderException(SR.GetString(SR.Wow64NotInstalled));
            }
 
            ConfigurationHandlersInstallComponent configurationHandlers = new ConfigurationHandlersInstallComponent(new Wow64ConfigurationLoader());
            configurationHandlers.displayString = SR.GetString(SR.CommunicationSectionNameWow64); 
            return configurationHandlers; 
        }
 
        // This is method holds workaround code for System.Configuration issues
        // that need additional processing of machine.config.
        void FixupMachineConfig()
        { 
            // MB 36807 / VSW 547957: Setting allowExeDefinition = MachineOnly on config section handler results in empty section being put in machine.config
            foreach (ServiceModelConfigurationSectionGroup sectionGroup in serviceModelConfiguration.SectionGroups) 
            { 
                this.FixupServiceModelSectionGroup(sectionGroup, ServiceModelInstallStrings.Configuration + "/" + sectionGroup.Name);
            } 

            foreach (ServiceModelConfigurationSection section in serviceModelConfiguration.Sections)
            {
                this.FixupServiceModelSection(section, ServiceModelInstallStrings.Configuration + "/" + section.Name); 
            }
        } 
 
        void FixupServiceModelSection(ServiceModelConfigurationSection section, string path)
        { 
            configLoader.RemoveNodeFromConfigFile(configLoader.MachineConfigurationFilePath, path, true);
        }

        void FixupServiceModelSectionGroup(ServiceModelConfigurationSectionGroup sectionGroup, string path) 
        {
            foreach (ServiceModelConfigurationSectionGroup childSectionGroup in sectionGroup.SectionGroups) 
            { 
                this.FixupServiceModelSectionGroup(childSectionGroup, path + "/" + childSectionGroup.Name);
            } 

            foreach (ServiceModelConfigurationSection childSection in sectionGroup.Sections)
            {
                this.FixupServiceModelSection(childSection, path + "/" + childSection.Name); 
            }
 
            configLoader.RemoveNodeFromConfigFile(configLoader.MachineConfigurationFilePath, path, true); 
        }
 
        internal override void Install(OutputLevel outputLevel)
        {
            Configuration config = configLoader.MachineConfiguration;
 
            if (null != this.serviceModelConfiguration.SectionGroups)
            { 
                foreach (ServiceModelConfigurationSectionGroup indigoSectionGroup in this.serviceModelConfiguration.SectionGroups) 
                {
                    if (!IsSectionGroupInstalled(indigoSectionGroup.Name, ref config)) 
                    {
                        if (null == config)
                        {
                            config = configLoader.MachineConfiguration; 
                        }
 
                        this.InstallSectionGroup(indigoSectionGroup, config.SectionGroups); 
                    }
                    else 
                    {
                        EventLogger.LogWarning(SR.GetString(SR.CommunicationSectionAlreadyExists, indigoSectionGroup.Name, config.FilePath), (OutputLevel.Verbose == outputLevel));
                    }
                } 
            }
 
            if (null != this.serviceModelConfiguration.Sections) 
            {
                foreach (ServiceModelConfigurationSection indigoSection in this.serviceModelConfiguration.Sections) 
                {
                    if (!IsSectionInstalled(indigoSection.Name, ref config))
                    {
                        if (null == config) 
                        {
                            config = configLoader.MachineConfiguration; 
                        } 

                        this.InstallSection(indigoSection, config.Sections); 
                    }
                    else
                    {
                        EventLogger.LogWarning(SR.GetString(SR.CommunicationSectionAlreadyExists, indigoSection.Name, config.FilePath), (OutputLevel.Verbose == outputLevel)); 
                    }
                } 
            } 

            configLoader.Save(); 
            this.FixupMachineConfig();
        }

        internal override void Reinstall(OutputLevel outputLevel) 
        {
            // We don't want to uninstall the handlers if we're reinstalling, because that removes any custom behaviors/extensions/etc. 
            // including those installed by VS or by later versions of the Framework 
            if (OutputLevel.Quiet != outputLevel)
            { 
                EventLogger.LogToConsole(SR.GetString(SR.InstallMessage, this.DisplayName));
            }

            EventLogger.WriteMsiStyleLogEntry(SR.GetString(SR.InstallMessage, this.DisplayName)); 
            this.Install(outputLevel);
        } 
 
        void InstallSection(ServiceModelConfigurationSection indigoSection, ConfigurationSectionCollection sectionCollection)
        { 
            Type sectionType = Type.GetType(indigoSection.Type, false);
            if (null == sectionType)
            {
                throw new InvalidOperationException(SR.GetString(SR.CommunicationSectionCouldNotLoadType, indigoSection.Type)); 
            }
 
            ConfigurationSection configSection = (ConfigurationSection) Activator.CreateInstance(sectionType); 
            configSection.SectionInformation.Type = indigoSection.Type;
 
            if (!String.IsNullOrEmpty(indigoSection.AllowDefinition))
            {
                configSection.SectionInformation.AllowDefinition = (ConfigurationAllowDefinition) Enum.Parse(typeof(ConfigurationAllowDefinition), indigoSection.AllowDefinition, true);
            } 

            if (!String.IsNullOrEmpty(indigoSection.AllowExeDefinition)) 
            { 
                configSection.SectionInformation.AllowExeDefinition = (ConfigurationAllowExeDefinition) Enum.Parse(typeof(ConfigurationAllowExeDefinition), indigoSection.AllowExeDefinition, true);
            } 

            sectionCollection.Add(indigoSection.Name, configSection);
        }
 
        void InstallSectionGroup(ServiceModelConfigurationSectionGroup indigoSectionGroup, ConfigurationSectionGroupCollection sectionGroupCollection)
        { 
            Type sectionGroupType = string.IsNullOrEmpty(indigoSectionGroup.Type) ? typeof(ConfigurationSectionGroup) : Type.GetType(indigoSectionGroup.Type, false); 
            if (null == sectionGroupType)
            { 
                throw new InvalidOperationException(SR.GetString(SR.CommunicationSectionCouldNotLoadType, indigoSectionGroup.Type));
            }

            ConfigurationSectionGroup configSectionGroup = (ConfigurationSectionGroup) Activator.CreateInstance(sectionGroupType); 
            configSectionGroup.Type = indigoSectionGroup.Type;
            configSectionGroup.ForceDeclaration(true); 
            sectionGroupCollection.Add(indigoSectionGroup.Name, configSectionGroup); 

            if (null != indigoSectionGroup.Sections) 
            {
                foreach (ServiceModelConfigurationSection indigoSection in indigoSectionGroup.Sections)
                {
                    InstallSection(indigoSection, configSectionGroup.Sections); 
                }
            } 
 
            if (null != indigoSectionGroup.SectionGroups)
            { 
                foreach (ServiceModelConfigurationSectionGroup sectionGroup in indigoSectionGroup.SectionGroups)
                {
                    InstallSectionGroup(sectionGroup, configSectionGroup.SectionGroups);
                } 
            }
        } 
 
        bool IsSectionGroupInstalled(string sectionGroupName, ref System.Configuration.Configuration config)
        { 
            bool retVal = false;

            try
            { 
                retVal = (null != config.GetSectionGroup(sectionGroupName));
            } 
            catch (FileNotFoundException) 
            {
                // FileNotFoundException occurs when the assembly holding this section group's configuration handler 
                // cannot be found.  In this case, we need to remove this entry from the config XML by hand.
                configLoader.Save();
                configLoader.RemoveNodeFromConfigFile(config.FilePath,
                    String.Format(CultureInfo.InvariantCulture, "configuration/configSections/sectionGroup[@name = \"{0}\"]", sectionGroupName), 
                    false);
 
                config = null; 
            }
 
            return retVal;
        }

        bool IsSectionInstalled(string sectionName, ref System.Configuration.Configuration config) 
        {
            bool retVal = false; 
 
            try
            { 
                retVal = (null != config.GetSection(sectionName));
            }
            catch (FileNotFoundException)
            { 
                // FileNotFoundException occurs when the assembly holding this section's configuration handler
                // cannot be found.  In this case, we need to remove this entry from the config XML by hand. 
                configLoader.Save(); 
                configLoader.RemoveNodeFromConfigFile(config.FilePath,
                    String.Format(CultureInfo.InvariantCulture, "configuration/configSections/section[@name = \"{0}\"]", sectionName), 
                    false);

                config = null;
            } 

            return retVal; 
        } 

        internal override void Uninstall(OutputLevel outputLevel) 
        {
            bool removedItem = false;

            if (null != this.serviceModelConfiguration.SectionGroups) 
            {
                foreach (ServiceModelConfigurationSectionGroup indigoSectionGroup in this.serviceModelConfiguration.SectionGroups) 
                { 
                    Configuration machineConfig = configLoader.MachineConfiguration;
                    if (IsSectionGroupInstalled(indigoSectionGroup.Name, ref machineConfig)) 
                    {
                        if (InstallHelper.ShouldInstallToWebConfig)
                        {
                            Configuration webConfig = configLoader.RootWebConfiguration; 
                            if (IsSectionGroupInstalled(indigoSectionGroup.Name, ref webConfig))
                            { 
                                configLoader.RootWebConfiguration.SectionGroups.Remove(indigoSectionGroup.Name); 
                                configLoader.Save();
                                configLoader.RemoveNodeFromConfigFile(configLoader.RootWebConfigurationFilePath, 
                                    String.Format(CultureInfo.InvariantCulture, "{0}/{1}", ServiceModelInstallStrings.Configuration, ServiceModelInstallStrings.ConfigSections),
                                    true);
                            }
                        } 

                        configLoader.MachineConfiguration.SectionGroups.Remove(indigoSectionGroup.Name); 
                        configLoader.Save(); 
                    }
                    else 
                    {
                        EventLogger.LogWarning(SR.GetString(SR.CommunicationSectionNotInstalled, indigoSectionGroup.Name, configLoader.MachineConfiguration.FilePath), (OutputLevel.Verbose == outputLevel));
                    }
                } 
            }
 
            if (null != this.serviceModelConfiguration.Sections) 
            {
                foreach (ServiceModelConfigurationSection indigoSection in this.serviceModelConfiguration.Sections) 
                {
                    Configuration machineConfig = configLoader.MachineConfiguration;
                    if (IsSectionInstalled(indigoSection.Name, ref machineConfig))
                    { 
                        if (InstallHelper.ShouldInstallToWebConfig)
                        { 
                            Configuration webConfig = configLoader.RootWebConfiguration; 
                            if (IsSectionInstalled(indigoSection.Name, ref webConfig))
                            { 
                                configLoader.RootWebConfiguration.Sections.Remove(indigoSection.Name);
                                configLoader.Save();
                            }
                        } 

                        configLoader.MachineConfiguration.Sections.Remove(indigoSection.Name); 
                        configLoader.Save(); 
                    }
                    else 
                    {
                        EventLogger.LogWarning(SR.GetString(SR.CommunicationSectionNotInstalled, indigoSection.Name, configLoader.MachineConfiguration.FilePath), (OutputLevel.Verbose == outputLevel));
                    }
                } 
            }
 
            if (removedItem) 
            {
                // Only display this message if we changed configuration. 
                configLoader.Save();
            }
        }
 
        internal override InstallationState VerifyInstall()
        { 
            InstallationState installState = InstallationState.Unknown; 

            if (this.IsInstalled) 
            {
                Configuration config = configLoader.MachineConfiguration;

                if (null != this.serviceModelConfiguration.SectionGroups) 
                {
                    foreach (ServiceModelConfigurationSectionGroup indigoSectionGroup in this.serviceModelConfiguration.SectionGroups) 
                    { 
                        installState = this.VerifySectionGroup(indigoSectionGroup, config.SectionGroups);
 
                        if (InstallationState.InstalledDefaults != installState)
                        {
                            break;
                        } 
                    }
                } 
 
                if (InstallationState.InstalledDefaults == installState &&
                    null != this.serviceModelConfiguration.Sections) 
                {
                    foreach (ServiceModelConfigurationSection indigoSection in this.serviceModelConfiguration.Sections)
                    {
                        installState = this.VerifySection(indigoSection, config.Sections); 

                        if (InstallationState.InstalledDefaults != installState) 
                        { 
                            break;
                        } 
                    }
                }
            }
            else 
            {
                installState = InstallationState.NotInstalled; 
            } 

            return installState; 
        }

        InstallationState VerifySection(ServiceModelConfigurationSection indigoSection, ConfigurationSectionCollection sectionCollection)
        { 
            InstallationState installState = InstallationState.Unknown;
 
            Type sectionType = Type.GetType(indigoSection.Type, false); 
            if (null == sectionType)
            { 
                throw new InvalidOperationException(SR.GetString(SR.CommunicationSectionCouldNotLoadType, indigoSection.Type));
            }

            ConfigurationSection configSection = (ConfigurationSection) Activator.CreateInstance(sectionType); 
            MethodInfo initializeDefault = sectionType.GetMethod("InitializeDefault", BindingFlags.Instance | BindingFlags.NonPublic);
            initializeDefault.Invoke(configSection, null); 
            configSection.SectionInformation.Type = indigoSection.Type; 

            if (!String.IsNullOrEmpty(indigoSection.AllowDefinition)) 
            {
                configSection.SectionInformation.AllowDefinition = (ConfigurationAllowDefinition) Enum.Parse(typeof(ConfigurationAllowDefinition), indigoSection.AllowDefinition, true);
            }
 
            if (!String.IsNullOrEmpty(indigoSection.AllowExeDefinition))
            { 
                configSection.SectionInformation.AllowExeDefinition = (ConfigurationAllowExeDefinition) Enum.Parse(typeof(ConfigurationAllowExeDefinition), indigoSection.AllowExeDefinition, true); 
            }
 
            ConfigurationSection installedConfigSection = sectionCollection[indigoSection.Name];

            if (this.CompareSections(configSection, installedConfigSection))
            { 
                installState = InstallationState.InstalledDefaults;
            } 
            else 
            {
                installState = InstallationState.InstalledCustom; 
            }

            return installState;
        } 

        InstallationState VerifySectionGroup(ServiceModelConfigurationSectionGroup indigoSectionGroup, ConfigurationSectionGroupCollection sectionGroupCollection) 
        { 
            InstallationState installState = InstallationState.Unknown;
 
            Type sectionGroupType = String.IsNullOrEmpty(indigoSectionGroup.Type) ? typeof(ConfigurationSectionGroup) : Type.GetType(indigoSectionGroup.Type, false);
            if (null == sectionGroupType)
            {
                throw new InvalidOperationException(SR.GetString(SR.CommunicationSectionCouldNotLoadType, indigoSectionGroup.Type)); 
            }
 
            ConfigurationSectionGroup configSectionGroup = (ConfigurationSectionGroup) Activator.CreateInstance(sectionGroupType); 
            configSectionGroup.Type = String.IsNullOrEmpty(indigoSectionGroup.Type) ? typeof(ConfigurationSectionGroup).AssemblyQualifiedName : indigoSectionGroup.Type;
            configSectionGroup.ForceDeclaration(true); 

            ConfigurationSectionGroup installedConfigSectionGroup = sectionGroupCollection[indigoSectionGroup.Name];
            if (null == installedConfigSectionGroup)
            { 
                installState = InstallationState.Unknown;
            } 
            else 
            {
                if (indigoSectionGroup.Name.Equals(installedConfigSectionGroup.Name, StringComparison.Ordinal) && 
                    configSectionGroup.Type.Equals(installedConfigSectionGroup.Type, StringComparison.OrdinalIgnoreCase) &&
                    configSectionGroup.IsDeclared == installedConfigSectionGroup.IsDeclared)
                {
                    installState = InstallationState.InstalledDefaults; 
                }
                else 
                { 
                    installState = InstallationState.InstalledCustom;
                } 
            }

            if (null != indigoSectionGroup.Sections &&
                InstallationState.InstalledDefaults == installState) 
            {
                foreach (ServiceModelConfigurationSection indigoSection in indigoSectionGroup.Sections) 
                { 
                    installState = VerifySection(indigoSection, installedConfigSectionGroup.Sections);
 
                    if (InstallationState.InstalledDefaults != installState)
                    {
                        break;
                    } 
                }
            } 
 
            if (null != indigoSectionGroup.SectionGroups &&
                InstallationState.InstalledDefaults == installState) 
            {
                foreach (ServiceModelConfigurationSectionGroup sectionGroup in indigoSectionGroup.SectionGroups)
                {
                    installState = VerifySectionGroup(sectionGroup, installedConfigSectionGroup.SectionGroups); 

                    if (InstallationState.InstalledDefaults != installState) 
                    { 
                        break;
                    } 
                }
            }

            return installState; 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK