public void CanDeserializeSerializedWithAutoFlushConfiguration()
        {
            string name = "name";
            bool autoFlush = false;

            TraceSourceData data = new TraceSourceData(name, SourceLevels.Critical, false);
            data.TraceListeners.Add(new TraceListenerReferenceData("listener1"));
            data.TraceListeners.Add(new TraceListenerReferenceData("listener2"));

            LoggingSettings settings = new LoggingSettings();
            settings.TraceSources.Add(data);

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
            sections[LoggingSettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

            Assert.AreEqual(1, roSettigs.TraceSources.Count);
            Assert.IsNotNull(roSettigs.TraceSources.Get(name));
            Assert.AreEqual(SourceLevels.Critical, roSettigs.TraceSources.Get(name).DefaultLevel);
            Assert.AreEqual(autoFlush, roSettigs.TraceSources.Get(name).AutoFlush);
            Assert.AreEqual(2, roSettigs.TraceSources.Get(name).TraceListeners.Count);
            Assert.IsNotNull(roSettigs.TraceSources.Get(name).TraceListeners.Get("listener1"));
            Assert.IsNotNull(roSettigs.TraceSources.Get(name).TraceListeners.Get("listener2"));
        }
        /// <summary>
        /// Initialize a new instance of the <see cref="NotProcessedTraceSourceNode"/> with a <see cref="TraceSourceData"/> instance.
        /// </summary>
        /// <param name="traceSourceData">A <see cref="TraceSourceData"/> instance.</param>
        public NotProcessedTraceSourceNode(TraceSourceData traceSourceData)
            : base(Resources.UnprocessedTraceSourceNode)
        {
            if (null == traceSourceData) throw new ArgumentNullException("traceSourceData");

            SourceLevels = traceSourceData.DefaultLevel;
        }
Exemplo n.º 3
0
 private static void BuildTraceListenerReferences(TraceSourceData data, TraceSourceNode node)
 {
     foreach (TraceListenerReferenceNode refNode in node.Nodes)
     {
         data.TraceListeners.Add(refNode.TraceListenerReferenceData);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Initialize a new instance of the <see cref="ErrorsTraceSourceNode"/> with a <see cref="TraceSourceData"/> instance.
        /// </summary>
        /// <param name="traceSourceData">A <see cref="TraceSourceData"/> instance.</param>
        public ErrorsTraceSourceNode(TraceSourceData traceSourceData)
            : base(Resources.ErrorsTraceSourceNode)
        {
            if (null == traceSourceData) throw new ArgumentNullException("traceSourceData");

            SourceLevels = traceSourceData.DefaultLevel;
        }
		private void AddTraceListeners(ConfigurationNode node, TraceSourceData data)
		{
			foreach (TraceListenerReferenceData refData in data.TraceListeners)
			{
				TraceListenerReferenceNode referenceNode = new TraceListenerReferenceNode(refData);
				foreach(TraceListenerNode listenerNode in listeners.Nodes)
				{
					if (listenerNode.Name == referenceNode.Name)
					{
						referenceNode.ReferencedTraceListener = listenerNode;
					}
				}
				node.AddNode(referenceNode);
			}			
		}
 private void CreateTraceSourceNode(TraceSourceData traceSourceData)
 {
     CategoryTraceSourceNode traceSourceNode = new CategoryTraceSourceNode(traceSourceData);
     foreach (TraceListenerReferenceData traceListener in traceSourceData.TraceListeners)
     {
         TraceListenerReferenceNode referenceNode = new TraceListenerReferenceNode(traceListener);
         foreach (TraceListenerNode traceListenerNode in listeners.Nodes)
         {
             if (traceListenerNode.Name == referenceNode.Name)
             {
                 referenceNode.ReferencedTraceListener = traceListenerNode;
             }
         }
         traceSourceNode.AddNode(referenceNode);
     }
     node.AddNode(traceSourceNode);
 }
 public void Setup()
 {
     data = new TraceSourceData("source", SourceLevels.Error, true);
 }
 public void Setup()
 {
     data =
         new TraceSourceData("source", SourceLevels.Error, true)
         {
             TraceListeners = 
             { 
                 new TraceListenerReferenceData("listener1"), 
                 new TraceListenerReferenceData("listener2")
             }
         };
 }
        public void TraceSourceWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled()
        {
            TraceSourceData traceSource1Data = new TraceSourceData("traceSource1", SourceLevels.Error);
            section.TraceSources.Add(traceSource1Data);
            TraceSourceData traceSource2Data = new TraceSourceData("traceSource2", SourceLevels.Error);
            section.TraceSources.Add(traceSource2Data);

            MockRegistryKey machineTraceSourcesKey = new MockRegistryKey(false);
            machineKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, machineTraceSourcesKey);
            MockRegistryKey machineTraceSource2Key = new MockRegistryKey(false);
            machineTraceSourcesKey.AddSubKey("traceSource2", machineTraceSource2Key);
            machineTraceSource2Key.AddBooleanValue(AdmContentBuilder.AvailableValueName, false);

            provider.OverrideWithGroupPolicies(section, false, machineKey, userKey);

            Assert.AreEqual(2, section.TraceSources.Count);
            Assert.IsNotNull(section.TraceSources.Get("traceSource1"));
            Assert.IsNotNull(section.TraceSources.Get("traceSource2"));

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineTraceSourcesKey, machineTraceSource2Key));
        }
        public void MachineKeySourceOverrideWithoutListenersSubKeyTakesPrecedenceOverUserKeyOverrides()
        {
            TraceSourceData sourceData = new TraceSourceData("source1", SourceLevels.Critical, true);
            section.TraceSources.Add(sourceData);
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener1"));
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener2"));

            MockRegistryKey machineTraceSourcesKey = new MockRegistryKey(false);
            machineKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, machineTraceSourcesKey);
            MockRegistryKey machineSource1Key = new MockRegistryKey(false);
            machineTraceSourcesKey.AddSubKey("source1", machineSource1Key);
            machineSource1Key.AddEnumValue<SourceLevels>(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.ActivityTracing);
            machineSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false);
            MockRegistryKey userTraceSourcesKey = new MockRegistryKey(false);
            userKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, userTraceSourcesKey);
            MockRegistryKey userSource1Key = new MockRegistryKey(false);
            userTraceSourcesKey.AddSubKey("source1", userSource1Key);
            userSource1Key.AddEnumValue<SourceLevels>(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.ActivityTracing);
            userSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false);
            MockRegistryKey userSource1ListenersKey = new MockRegistryKey(false);
            userSource1Key.AddSubKey(LoggingSettingsManageabilityProvider.SourceTraceListenersPropertyName, userSource1ListenersKey);
            userSource1ListenersKey.AddBooleanValue("listener6", true);
            userSource1ListenersKey.AddBooleanValue("listener7", true);
            userSource1ListenersKey.AddBooleanValue("listener8", true);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.AreEqual(0, sourceData.TraceListeners.Count);

            Assert.IsTrue(
                MockRegistryKey.CheckAllClosed(
                    machineTraceSourcesKey, machineSource1Key,
                    userTraceSourcesKey, userSource1Key, userSource1ListenersKey));
        }
        public void TraceSourceTraceListenersAreOverridenIfListenerKeyIsPresentInUserKey()
        {
            TraceSourceData sourceData = new TraceSourceData("source1", SourceLevels.Critical, true);
            section.TraceSources.Add(sourceData);
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener1"));
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener2"));

            MockRegistryKey userTraceSourcesKey = new MockRegistryKey(false);
            userKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, userTraceSourcesKey);
            MockRegistryKey userSource1Key = new MockRegistryKey(false);
            userTraceSourcesKey.AddSubKey("source1", userSource1Key);
            userSource1Key.AddEnumValue<SourceLevels>(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.ActivityTracing);
            userSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false);
            MockRegistryKey userSource1ListenersKey = new MockRegistryKey(false);
            userSource1Key.AddSubKey(LoggingSettingsManageabilityProvider.SourceTraceListenersPropertyName, userSource1ListenersKey);
            userSource1ListenersKey.AddBooleanValue("listener3", true);
            userSource1ListenersKey.AddBooleanValue("listener4", true);
            userSource1ListenersKey.AddBooleanValue("listener5", true);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.AreEqual(3, sourceData.TraceListeners.Count);
            Assert.IsNotNull(sourceData.TraceListeners.Get("listener3"));
            Assert.IsNotNull(sourceData.TraceListeners.Get("listener4"));
            Assert.IsNotNull(sourceData.TraceListeners.Get("listener5"));

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(userTraceSourcesKey, userSource1Key, userSource1ListenersKey));
        }
        public void TraceSourceDefaultLevelIsOverridenFromUserKey()
        {
            TraceSourceData sourceData = new TraceSourceData("source1", SourceLevels.Critical, true);
            section.TraceSources.Add(sourceData);

            MockRegistryKey userTraceSourcesKey = new MockRegistryKey(false);
            userKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, userTraceSourcesKey);
            MockRegistryKey userSource1Key = new MockRegistryKey(false);
            userTraceSourcesKey.AddSubKey("source1", userSource1Key);
            userSource1Key.AddStringValue(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.Error.ToString());
            userSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.AreEqual(SourceLevels.Error, sourceData.DefaultLevel);
            Assert.AreEqual(false, sourceData.AutoFlush);

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(userTraceSourcesKey, userSource1Key));
        }
Exemplo n.º 13
0
 public TraceSourceNodeImpl(TraceSourceData data)
 {
     Rename(data.Name);
     SourceLevels = data.DefaultLevel;
 }