private CtsConfigurationSetting DeserializeSetting(XmlReader reader)
        {
            string name = reader.Name;
            CtsConfigurationSetting ctsConfigurationSetting = new CtsConfigurationSetting(name);

            if (reader.AttributeCount > 0)
            {
                while (reader.MoveToNextAttribute())
                {
                    string name2 = reader.Name;
                    string value = reader.Value;
                    ctsConfigurationSetting.AddArgument(name2, value);
                }
            }
            return(ctsConfigurationSetting);
        }
        // Token: 0x06000C82 RID: 3202 RVA: 0x0006E4D4 File Offset: 0x0006C6D4
        public static CtsConfigurationSetting GetSimpleConfigurationSetting(string subSectionName, string settingName)
        {
            CtsConfigurationSetting         ctsConfigurationSetting = null;
            IList <CtsConfigurationSetting> configuration           = ApplicationServices.Provider.GetConfiguration(subSectionName);

            foreach (CtsConfigurationSetting ctsConfigurationSetting2 in configuration)
            {
                if (string.Equals(ctsConfigurationSetting2.Name, settingName, StringComparison.OrdinalIgnoreCase))
                {
                    if (ctsConfigurationSetting != null)
                    {
                        ApplicationServices.Provider.LogConfigurationErrorEvent();
                        break;
                    }
                    ctsConfigurationSetting = ctsConfigurationSetting2;
                }
            }
            return(ctsConfigurationSetting);
        }
        /// <summary>
        /// Deserializes an individual configuration setting.
        /// </summary>
        /// <param name="reader">The XmlReader containing the setting to deserialize.</param>
        /// <returns>A <see cref="CtsConfigurationSetting"/> instance containing the configuration setting.</returns>
        private static CtsConfigurationSetting DeserializeSetting(XmlReader reader)
        {
            string settingName = reader.Name;

            CtsConfigurationSetting setting = new CtsConfigurationSetting(settingName);

            if (reader.AttributeCount > 0)
            {
                while (reader.MoveToNextAttribute())
                {
                    string argumentName  = reader.Name;
                    string argumentValue = reader.Value;

                    setting.AddArgument(argumentName, argumentValue);
                }
            }

            return(setting);
        }
Exemple #4
0
        /// <summary>
        /// Gets the specified configuration setting.
        /// </summary>
        /// <param name="subSectionName">Name of the configuration sub section.</param>
        /// <param name="settingName">Name of the configuration setting.</param>
        /// <returns>A <see cref="CtsConfigurationSetting"/> for the sepecified setting from the specified sub section.</returns>
        public static CtsConfigurationSetting GetSimpleConfigurationSetting(string subSectionName, string settingName)
        {
            CtsConfigurationSetting         result   = null;
            IList <CtsConfigurationSetting> settings = Provider.GetConfiguration(subSectionName);

            foreach (CtsConfigurationSetting setting in
                     settings.Where(setting => string.Equals(setting.Name, settingName, StringComparison.OrdinalIgnoreCase)))
            {
                if (result != null)
                {
                    Provider.LogConfigurationErrorEvent();
                    break;
                }

                result = setting;
            }

            return(result);
        }
        // Token: 0x06000C83 RID: 3203 RVA: 0x0006E544 File Offset: 0x0006C744
        internal static int ParseIntegerSetting(CtsConfigurationSetting setting, int defaultValue, int min, bool kilobytes)
        {
            if (setting.Arguments.Count != 1 || !setting.Arguments[0].Name.Equals("Value", StringComparison.OrdinalIgnoreCase))
            {
                ApplicationServices.Provider.LogConfigurationErrorEvent();
                return(defaultValue);
            }
            if (setting.Arguments[0].Value.Trim().Equals("unlimited", StringComparison.OrdinalIgnoreCase))
            {
                return(int.MaxValue);
            }
            int num;

            if (!int.TryParse(setting.Arguments[0].Value.Trim(), out num))
            {
                ApplicationServices.Provider.LogConfigurationErrorEvent();
                return(defaultValue);
            }
            if (num < min)
            {
                ApplicationServices.Provider.LogConfigurationErrorEvent();
                return(defaultValue);
            }
            if (kilobytes)
            {
                if (num > 2097151)
                {
                    num = int.MaxValue;
                }
                else
                {
                    num *= 1024;
                }
            }
            return(num);
        }
        private Dictionary <string, IList <CtsConfigurationSetting> > GetConfigurationSubSections()
        {
            Dictionary <string, IList <CtsConfigurationSetting> > dictionary = this.configurationSubSections;

            if (dictionary == null)
            {
                CtsConfigurationSection ctsConfigurationSection = null;
                try
                {
                    ctsConfigurationSection = (ConfigurationManager.GetSection("CTS") as CtsConfigurationSection);
                }
                catch (ConfigurationErrorsException)
                {
                    this.LogConfigurationErrorEvent();
                }
                CtsConfigurationSetting ctsConfigurationSetting = null;
                try
                {
                    string value = ConfigurationManager.AppSettings["TemporaryStoragePath"];
                    if (!string.IsNullOrEmpty(value))
                    {
                        ctsConfigurationSetting = new CtsConfigurationSetting("TemporaryStorage");
                        ctsConfigurationSetting.AddArgument("Path", value);
                    }
                }
                catch (ConfigurationErrorsException)
                {
                    this.LogConfigurationErrorEvent();
                }
                lock (this.lockObject)
                {
                    dictionary = this.configurationSubSections;
                    if (dictionary == null)
                    {
                        if (ctsConfigurationSection != null)
                        {
                            dictionary = ctsConfigurationSection.SubSectionsDictionary;
                        }
                        else
                        {
                            dictionary = new Dictionary <string, IList <CtsConfigurationSetting> >();
                            dictionary.Add(string.Empty, new List <CtsConfigurationSetting>());
                        }
                        if (ctsConfigurationSetting != null)
                        {
                            IList <CtsConfigurationSetting> list = dictionary[string.Empty];
                            bool flag2 = false;
                            foreach (CtsConfigurationSetting ctsConfigurationSetting2 in list)
                            {
                                if (string.Equals(ctsConfigurationSetting2.Name, ctsConfigurationSetting.Name))
                                {
                                    flag2 = true;
                                    break;
                                }
                            }
                            if (!flag2)
                            {
                                list.Add(ctsConfigurationSetting);
                            }
                        }
                        this.configurationSubSections = dictionary;
                    }
                }
            }
            return(dictionary);
        }
        /// <summary>
        /// Gets the configuration subsection specified.
        /// </summary>
        /// <param name="subSectionName">Name of the subsection.</param>
        /// <returns>
        /// A list of <see cref="CtsConfigurationSetting"/>s for the specified section.
        /// </returns>
        public IList <CtsConfigurationSetting> GetConfiguration(string subSectionName)
        {
            IList <CtsConfigurationSetting> subSection;

            if (this.configurationSubSections == null)
            {
                lock (this.lockObject)
                {
                    if (this.configurationSubSections == null)
                    {
                        try
                        {
                            CtsConfigurationSection section = ConfigurationManager.GetSection("CTS") as CtsConfigurationSection;

                            if (section != null)
                            {
                                this.configurationSubSections = section.SubSectionsDictionary;
                            }
                            else
                            {
                                this.configurationSubSections = new Dictionary <string, IList <CtsConfigurationSetting> >
                                {
                                    { string.Empty, new List <CtsConfigurationSetting>() }
                                };
                            }

                            string path = ConfigurationManager.AppSettings["TemporaryStoragePath"];

                            if (!string.IsNullOrEmpty(path))
                            {
                                CtsConfigurationSetting newSetting = new CtsConfigurationSetting("TemporaryStorage");
                                newSetting.AddArgument("Path", path);

                                subSection = this.configurationSubSections[string.Empty];

                                subSection.Add(newSetting);
                            }

                            ConfigurationManager.RefreshSection("CTS");
                        }
                        catch (ConfigurationErrorsException /*exception*/)
                        {
                            ApplicationServices.Provider.LogConfigurationErrorEvent();

                            this.configurationSubSections = new Dictionary <string, IList <CtsConfigurationSetting> >
                            {
                                { string.Empty, new List <CtsConfigurationSetting>() }
                            };
                        }
                    }
                }
            }

            if (subSectionName == null)
            {
                subSectionName = string.Empty;
            }

            if (!this.configurationSubSections.TryGetValue(subSectionName, out subSection))
            {
                subSection = EmptySubSection;
            }

            return(subSection);
        }
        protected override void DeserializeSection(XmlReader reader)
        {
            IList <CtsConfigurationSetting> list = new List <CtsConfigurationSetting>();

            this.subSections.Add(string.Empty, list);
            if (!reader.Read() || reader.NodeType != XmlNodeType.Element)
            {
                throw new ConfigurationErrorsException("error", reader);
            }
            if (!reader.IsEmptyElement)
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.IsEmptyElement)
                        {
                            CtsConfigurationSetting item = this.DeserializeSetting(reader);
                            list.Add(item);
                        }
                        else
                        {
                            string name = reader.Name;
                            IList <CtsConfigurationSetting> list2;
                            if (!this.subSections.TryGetValue(name, out list2))
                            {
                                list2 = new List <CtsConfigurationSetting>();
                                this.subSections.Add(name, list2);
                            }
                            while (reader.Read())
                            {
                                if (reader.NodeType == XmlNodeType.Element)
                                {
                                    if (!reader.IsEmptyElement)
                                    {
                                        throw new ConfigurationErrorsException("error", reader);
                                    }
                                    CtsConfigurationSetting item2 = this.DeserializeSetting(reader);
                                    list2.Add(item2);
                                }
                                else
                                {
                                    if (reader.NodeType == XmlNodeType.EndElement)
                                    {
                                        break;
                                    }
                                    if (reader.NodeType == XmlNodeType.CDATA || reader.NodeType == XmlNodeType.Text)
                                    {
                                        throw new ConfigurationErrorsException("error", reader);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (reader.NodeType == XmlNodeType.EndElement)
                        {
                            return;
                        }
                        if (reader.NodeType == XmlNodeType.CDATA || reader.NodeType == XmlNodeType.Text)
                        {
                            throw new ConfigurationErrorsException("error", reader);
                        }
                    }
                }
            }
        }
        protected override void DeserializeSection(XmlReader reader)
        {
            IList <CtsConfigurationSetting> unnamedSubSection = new List <CtsConfigurationSetting>();

            this.subSections.Add(string.Empty, unnamedSubSection);

            if (!reader.Read() || reader.NodeType != XmlNodeType.Element)
            {
                throw new ConfigurationErrorsException("error", reader);
            }

            if (!reader.IsEmptyElement)
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (reader.IsEmptyElement)
                        {
                            CtsConfigurationSetting setting = DeserializeSetting(reader);
                            unnamedSubSection.Add(setting);
                        }
                        else
                        {
                            string subSectionName = reader.Name;

                            if (!this.subSections.TryGetValue(subSectionName, out IList <CtsConfigurationSetting> subSection))
                            {
                                subSection = new List <CtsConfigurationSetting>();
                                this.subSections.Add(subSectionName, subSection);
                            }

                            while (reader.Read())
                            {
                                switch (reader.NodeType)
                                {
                                case XmlNodeType.Element:
                                    if (reader.IsEmptyElement)
                                    {
                                        CtsConfigurationSetting setting = DeserializeSetting(reader);
                                        subSection.Add(setting);
                                    }
                                    else
                                    {
                                        throw new ConfigurationErrorsException("error", reader);
                                    }

                                    break;

                                case XmlNodeType.EndElement:
                                    break;

                                case XmlNodeType.Text:
                                case XmlNodeType.CDATA:
                                    throw new ConfigurationErrorsException("error", reader);
                                }
                            }
                        }

                        break;

                    case XmlNodeType.EndElement:
                        break;

                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                        throw new ConfigurationErrorsException("error", reader);
                    }
                }
            }
        }