private static SectionList GetConfigurationSections(string sectionGroupName, IAppHostSectionGroup sectionGroup)
        {
            SectionList sectionList = new SectionList();
            string      text        = string.IsNullOrEmpty(sectionGroupName) ? sectionGroup.Name : (sectionGroupName + "/" + sectionGroup.Name);

            for (uint num = 0u; num < sectionGroup.Count; num += 1u)
            {
                IAppHostSectionGroup sectionGroup2         = sectionGroup[num];
                SectionList          configurationSections = GetConfigurationSections(text, sectionGroup2);
                sectionList.AddRange(configurationSections);
            }
            IAppHostSectionDefinitionCollection sections = sectionGroup.Sections;

            for (uint num2 = 0u; num2 < sections.Count; num2 += 1u)
            {
                IAppHostSectionDefinition appHostSectionDefinition = sections[num2];
                sectionList.Add(new SectionDefinition(string.IsNullOrEmpty(text) ? appHostSectionDefinition.Name : (text + "/" + appHostSectionDefinition.Name), (AllowDefinition)Enum.Parse(typeof(AllowDefinition), appHostSectionDefinition.AllowDefinition, true), (OverrideModeDefault)Enum.Parse(typeof(OverrideModeDefault), appHostSectionDefinition.OverrideModeDefault, true), appHostSectionDefinition.Type));
            }
            return(sectionList);
        }
        private void RegisterConfigurationSections(SectionList sectionList, bool remove)
        {
            IAppHostWritableAdminManager appHostWritableAdminManager = new AppHostWritableAdminManagerClass();

            appHostWritableAdminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
            IAppHostConfigManager configManager    = appHostWritableAdminManager.ConfigManager;
            IAppHostConfigFile    configFile       = configManager.GetConfigFile("MACHINE/WEBROOT/APPHOST");
            IAppHostSectionGroup  rootSectionGroup = configFile.RootSectionGroup;

            foreach (SectionDefinition current in sectionList)
            {
                if (RegisterConfigSection(appHostWritableAdminManager, current, current.Name, rootSectionGroup, remove))
                {
                    if (remove)
                    {
                        Console.WriteLine("Unregistered section: " + current.Name);
                    }
                    else
                    {
                        Console.WriteLine("Registered section: " + current.Name);
                    }
                }
                else
                {
                    if (remove)
                    {
                        Console.WriteLine("Section not currently registered, ignoring: " + current.Name);
                    }
                    else
                    {
                        Console.WriteLine("Section already registered, ignoring: " + current.Name);
                    }
                }
            }
            appHostWritableAdminManager.CommitChanges();
        }
        private static bool RegisterConfigSection(IAppHostWritableAdminManager adminManager, SectionDefinition sectionDefinition, string sectionName, IAppHostSectionGroup sectionGroup, bool remove)
        {
            string text         = null;
            string sectionName2 = sectionName;
            int    num          = sectionName.IndexOf('/');

            if (num >= 0)
            {
                text         = sectionName.Substring(0, num);
                sectionName2 = sectionName.Substring(num + 1, sectionName.Length - num - 1);
            }
            if (text != null)
            {
                uint count = sectionGroup.Count;
                for (uint num2 = 0u; num2 < count; num2 += 1u)
                {
                    IAppHostSectionGroup appHostSectionGroup = sectionGroup[num2];
                    if (appHostSectionGroup.Name.Equals(text, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(RegisterConfigSection(adminManager, sectionDefinition, sectionName2, appHostSectionGroup, remove));
                    }
                }
                if (remove)
                {
                    return(false);
                }
                IAppHostSectionGroup sectionGroup2 = sectionGroup.AddSectionGroup(text);
                return(RegisterConfigSection(adminManager, sectionDefinition, sectionName2, sectionGroup2, remove));
            }
            else
            {
                IAppHostSectionDefinitionCollection sections = sectionGroup.Sections;
                bool flag   = false;
                uint count2 = sections.Count;
                for (uint num3 = 0u; num3 < count2; num3 += 1u)
                {
                    IAppHostSectionDefinition appHostSectionDefinition = sections[num3];
                    if (appHostSectionDefinition.Name.Equals(sectionName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    if (remove)
                    {
                        return(false);
                    }
                    IAppHostSectionDefinition appHostSectionDefinition2 = sections.AddSection(sectionName);
                    appHostSectionDefinition2.OverrideModeDefault = sectionDefinition.OverrideModeDefault.ToString();
                    appHostSectionDefinition2.AllowDefinition     = sectionDefinition.AllowDefinition.ToString();
                    appHostSectionDefinition2.Type = sectionDefinition.Type;
                    return(true);
                }
                else
                {
                    if (remove)
                    {
                        try
                        {
                            IAppHostElement adminSection = adminManager.GetAdminSection(sectionName, "MACHINE/WEBROOT/APPHOST");
                            adminSection.Clear();
                        }
                        catch (Exception)
                        {
                        }
                        sections.DeleteSection(sectionName);
                        return(true);
                    }
                    return(false);
                }
            }
        }