public void AddChildNodesTest()
        {
            DistributorSettingsNode node = new DistributorSettingsNode();
            applicationNode.Nodes.AddWithDefaultChildren(node);
            Assert.AreEqual(3, node.Nodes.Count);
            bool categories = false;
            bool formatters = false;
            bool sinks = false;

            foreach (ConfigurationNode configNode in node.Nodes)
            {
                if (configNode is CategoryCollectionNode)
                {
                    categories = true;
                }
                else if (configNode is FormatterCollectionNode)
                {
                    formatters = true;
                }
                else if (configNode is SinkCollectionNode)
                {
                    sinks = true;
                }
            }

            Assert.IsTrue(categories && formatters && sinks);
        }
Beispiel #2
0
        /// <summary>
        /// <para>Saves the configuration settings created for the application.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        public override void Save(IServiceProvider serviceProvider)
        {
            ConfigurationContext configurationContext = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);

            if (configurationContext.IsValidSection(DistributorSettings.SectionName))
            {
                DistributorSettingsNode distributorSettingsNode = null;
                try
                {
                    IUIHierarchy hierarchy = ServiceHelper.GetCurrentHierarchy(serviceProvider);
                    distributorSettingsNode = hierarchy.FindNodeByType(typeof(DistributorSettingsNode)) as DistributorSettingsNode;
                    if (distributorSettingsNode == null)
                    {
                        return;
                    }
                    DistributorSettings distributorSettings = distributorSettingsNode.DistributorSettings;
                    configurationContext.WriteConfiguration(DistributorSettings.SectionName, distributorSettings);
                }
                catch (ConfigurationException e)
                {
                    ServiceHelper.LogError(serviceProvider, distributorSettingsNode, e);
                }
                catch (InvalidOperationException e)
                {
                    ServiceHelper.LogError(serviceProvider, distributorSettingsNode, e);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// <para>Adds to the dictionary configuration data for
        /// the enterpriselibrary.configurationSettings configuration section.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        /// <param name="configurationDictionary">
        /// <para>A <see cref="ConfigurationDictionary"/> to add
        /// configuration data to.</para></param>
        public override void BuildContext(IServiceProvider serviceProvider, ConfigurationDictionary configurationDictionary)
        {
            DistributorSettingsNode node = GetDistributorSettingsNode(serviceProvider);

            if (node != null)
            {
                DistributorSettings settings = node.DistributorSettings;
                configurationDictionary[DistributorSettings.SectionName] = settings;
            }
        }
        public void DistributorSettingsPropertiesTest()
        {
            CategoryData categoryData = new CategoryData();
            categoryData.Name = SR.DefaultCategory;
            CategoryNode defaultCategory = new CategoryNode(categoryData);
            TextFormatterData formatterData = new TextFormatterData();
            formatterData.Name = SR.DefaultFormatter;
            TextFormatterNode defaultFormatter = new TextFormatterNode(formatterData);

            DistributorSettingsNode distributorSettings = new DistributorSettingsNode();
            applicationNode.Nodes.Add(distributorSettings);
            distributorSettings.DefaultFormatter = defaultFormatter;
            distributorSettings.DefaultCategory = defaultCategory;

            Assert.AreEqual(defaultCategory.Name, distributorSettings.DefaultCategory.Name);
            Assert.AreEqual(defaultFormatter, distributorSettings.DefaultFormatter);
        }
 /// <summary>
 /// <para>Opens the configuration settings and registers them with the application.</para>
 /// </summary>
 /// <param name="serviceProvider">
 /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
 /// </param>
 public override void Open(IServiceProvider serviceProvider)
 {
     ConfigurationContext configurationContext = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);
     if (configurationContext.IsValidSection(DistributorSettings.SectionName))
     {
         DistributorSettings distributorSettings = null;
         DistributorSettingsNode distributorSettingsNode = null;
         try
         {
             distributorSettings = (DistributorSettings)configurationContext.GetConfiguration(DistributorSettings.SectionName);
             distributorSettingsNode = new DistributorSettingsNode(distributorSettings);
             ConfigurationNode configurationNode = GetLoggingSettingsNode(serviceProvider);
             configurationNode.Nodes.Add(distributorSettingsNode);
         }
         catch (ConfigurationException e)
         {
             ServiceHelper.LogError(serviceProvider, distributorSettingsNode, e);
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// <para>Opens the configuration settings and registers them with the application.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        public override void Open(IServiceProvider serviceProvider)
        {
            ConfigurationContext configurationContext = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);

            if (configurationContext.IsValidSection(DistributorSettings.SectionName))
            {
                DistributorSettings     distributorSettings     = null;
                DistributorSettingsNode distributorSettingsNode = null;
                try
                {
                    distributorSettings     = (DistributorSettings)configurationContext.GetConfiguration(DistributorSettings.SectionName);
                    distributorSettingsNode = new DistributorSettingsNode(distributorSettings);
                    ConfigurationNode configurationNode = GetLoggingSettingsNode(serviceProvider);
                    configurationNode.Nodes.Add(distributorSettingsNode);
                }
                catch (ConfigurationException e)
                {
                    ServiceHelper.LogError(serviceProvider, distributorSettingsNode, e);
                }
            }
        }
        public void RuntimeTest()
        {
            GeneratedHierarchy.Open();
            Assert.AreEqual(0, ConfigurationErrorsCount);

            ConfigurationContext builder = GeneratedHierarchy.ConfigurationContext;
            if (builder.IsValidSection(DistributorSettings.SectionName))
            {
                DistributorSettings distributorSettings = builder.GetConfiguration(DistributorSettings.SectionName) as DistributorSettings;
                if (distributorSettings != null)
                {
                    DistributorSettingsNode distributorSettingsNode = new DistributorSettingsNode(distributorSettings);
                    foreach (ConfigurationNode node in distributorSettingsNode.Nodes)
                    {
                        if (node is SinkCollectionNode)
                        {
                            SinkCollectionNode sinkCollectionNode = (SinkCollectionNode) node;
                            Assert.AreEqual(4, sinkCollectionNode.SinkDataCollection.Count);
                        }
                        else if (node is FormatterCollectionNode)
                        {
                            FormatterCollectionNode formatterCollectionNode = (FormatterCollectionNode) node;
                            Assert.AreEqual(4, formatterCollectionNode.FormatterDataCollection.Count);
                        }
                        else if (node is CategoryCollectionNode)
                        {
                            CategoryCollectionNode categoryCollectionNode = (CategoryCollectionNode) node;
                            Assert.AreEqual(2, categoryCollectionNode.CategoryDataCollection.Count);
                        }
                    }

                    MsmqDistributorServiceNode msmqNode =
                        new MsmqDistributorServiceNode(distributorSettings.DistributorService);
                    Assert.IsNotNull(msmqNode.MsmqPath);

                }
                else
                {
                    Assert.Fail(String.Format("Can not load section: {0}", DistributorSettings.SectionName));
                }
            }
        }
        public void DistributorSettingsPropertiesTest()
        {
            DistributorSettings settings = ConfigurationManager.GetConfiguration(DistributorSettings.SectionName) as DistributorSettings;

            DistributorSettingsNode settingsNode = new DistributorSettingsNode(settings);
            GeneratedApplicationNode.Nodes.Add(settingsNode);
            settingsNode.ResolveNodeReferences();
            Assert.AreEqual(settings.DefaultCategory, settingsNode.DefaultCategory.Name);
            Assert.AreEqual(settings.DefaultFormatter, settingsNode.DefaultFormatter.Name);
        }
 public void YouCanOnlyAddTheFormattersCollectionOnceToTheDistributorsSettingsNode()
 {
     DistributorSettingsNode distributorSettings = new DistributorSettingsNode();
     applicationNode.Nodes.AddWithDefaultChildren(distributorSettings);
     distributorSettings.Nodes.Add(new FormatterCollectionNode());
 }