예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XSimpleConfigurationSectionManager"/> class.
        /// </summary>
        public SimpleConfigurationSectionManager(string settings = null, string configPath = null)
        {
            if (settings == null)
            {
                return;
            }

            if (configPath == null)
            {
                var xmlConfigSection = (XmlNode)ConfigurationManager.GetSection(settings);
                if (xmlConfigSection != null)
                {
                    var cc = new ConfigNode(xmlConfigSection);
                    NodeAttributes = ConfigHelper.GetNodeChildAttributes(cc, ".");
                }
            }
            else
            {
                using (var configContainer = new ConfigContainer(configPath, "./rmqSettings"))
                {
                    var cc = configContainer.Node;
                    NodeAttributes = ConfigHelper.GetNodeChildAttributes(cc, ".");
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the configuration.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="sectionName">Name of the section.</param>
        /// <param name="settingsSectionName">Name of the settings section.</param>
        /// <returns></returns>
        public static IConfigContainer GetConfiguration(string fileName, string sectionName, string settingsSectionName)
        {
            lock (_congurations)
            {
                var key = FileKey(fileName, sectionName, settingsSectionName);

                ConfigContainerNode node;
                if (_congurations.ContainsKey(key))
                {
                    node = _congurations[key];
                }
                else
                {
                    var container = new ConfigContainer(fileName, sectionName, settingsSectionName);
                    container.OnConfigChange += DoOnConfigContainerChange;

                    node = new ConfigContainerNode()
                    {
                        FileKey = key, ReferenceCount = 0, ConfigContainer = container
                    };
                    _congurations.Add(key, node);

                    DoOnConfigContainerLoaded(container);
                }

                node.ReferenceCount++;

                return(node.ConfigContainer);
            }
        }