コード例 #1
0
        /// <summary>
        /// Populates the config item in the configuration collection according to the following rules:
        /// 1) If there is no config item under the given key will populate the config value under the given key.
        /// 2) If there is already a value for the given key will check if the new item has higher priority and will
        /// populate the new value under the given key and add the old value to the override list.
        /// 3)If the new value has lower priority than the old value it shall be added to the override list.
        /// </summary>
        /// <param name="conf">The configuration collection</param>
        /// <param name="key">The key for this configuration item</param>
        /// <param name="value">The Value of this configuration item</param>
        /// <param name="priority">The priority of this config item</param>
        /// <param name="fileName">The file name where this config item was found at</param>
        /// <param name="isArray">Indicates whether or not this entry is of array type and which kind</param>
        /// <param name="node">The XML node where this config item was found at</param>
        private void PutOrUpdateEntry(Dictionary <string, ConfigItem> conf, string key, string value, uint priority,
                                      string fileName, ArrayType isArray, XmlNode node = null, Exception exception = null)
        {
            var configItemInfo = new ConfigItemInfo
            {
                FileName = fileName,
                Priority = priority,
                Value    = value
            };

            conf.TryGetValue(key, out ConfigItem old);
            if (old == null)
            {
                var configItem = new ConfigItem(_configDecryptor)
                {
                    Key = key, Value = value, Priority = priority, Node = node, isArray = isArray, ParsingException = exception
                };
                configItem.Overrides.Add(configItemInfo);
                conf[key] = configItem;
            }
            else if (old.Priority < priority)
            {
                var configItem = new ConfigItem(_configDecryptor)
                {
                    Key              = key,
                    Value            = value,
                    Priority         = priority,
                    Node             = node,
                    Overrides        = old.Overrides,
                    isArray          = isArray,
                    ParsingException = exception
                };
                configItem.Overrides.Add(configItemInfo);
                conf[key] = configItem;
            }
            else
            {
                old.Overrides.Add(configItemInfo);
            }
        }
コード例 #2
0
        private void PutOrUpdateEntry(Dictionary <string, ConfigItem> conf, string key, string value, uint priority, string fileName, XmlNode node = null)
        {
            var configItemInfo = new ConfigItemInfo
            {
                FileName = fileName,
                Priority = priority,
                Value    = value
            };

            ConfigItem old;

            conf.TryGetValue(key, out old);
            if (old == null)
            {
                var configItem = new ConfigItem {
                    Key = key, Value = value, Priority = priority, Node = node
                };
                configItem.Overrides.Add(configItemInfo);
                conf[key] = configItem;
            }
            else if (old.Priority < priority)
            {
                var configItem = new ConfigItem
                {
                    Key       = key,
                    Value     = value,
                    Priority  = priority,
                    Node      = node,
                    Overrides = old.Overrides
                };
                configItem.Overrides.Add(configItemInfo);
                conf[key] = configItem;
            }
            else
            {
                old.Overrides.Add(configItemInfo);
            }
        }