Exemple #1
0
        public void ProvideGetProperty(IAppHostElement pElement, IAppHostProperty pProperty)
        {
            switch (pProperty.Name)
            {
            case "logfileCount":
                string logDirectory = (string)pElement.Properties["logfileDirectory"].Value;

                if (Directory.Exists(logDirectory))
                {
                    pProperty.Value = Directory.GetFiles(logDirectory, "????????.log").Length;
                }
                else
                {
                    pProperty.Value = 0;
                }
                break;
            }
        }
        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);
                }
            }
        }