public void then_differences_should_not_be_detected()
        {
            var sut0 = new ConfigurationReader("Etw\\Configuration\\WithDiff0.xml");
            var sut1 = new ConfigurationReader("Etw\\Configuration\\WithDiff1.xml");
            ConfigurationElement config0 = sut0.Read();
            ConfigurationElement config1 = sut1.Read();

            Assert.AreEqual(
                config0.SinkConfigurationElements.First().SinkConfiguration,
                config1.SinkConfigurationElements.First().SinkConfiguration);
        }
        public void then_differences_should_be_detected()
        {
            var sut1 = new ConfigurationReader("Etw\\Configuration\\WithDiff1.xml");
            var sut2 = new ConfigurationReader("Etw\\Configuration\\WithDiff2.xml");
            ConfigurationElement config1 = sut1.Read();
            ConfigurationElement config2 = sut2.Read();

            Assert.AreEqual("Microsoft.SemanticLogging.Etw", config1.TraceEventService.SessionNamePrefix);
            Assert.AreEqual("Microsoft.SemanticLogging.Etw.Diff1", config2.TraceEventService.SessionNamePrefix);

            Assert.AreEqual(1, config1.SinkConfigurationElements.First().EventSources.Count());
            Assert.AreEqual(2, config2.SinkConfigurationElements.First().EventSources.Count());

            Assert.AreNotEqual(
                config1.SinkConfigurationElements.First().SinkConfiguration,
                config2.SinkConfigurationElements.First().SinkConfiguration);
        }
        public void then_instance_is_loaded_with_all_sinks()
        {
            var sut = new ConfigurationReader("Etw\\Configuration\\WithManySinks.xml");
            ConfigurationElement config = sut.Read();

            SinkConfigurationElement[] elements = config.SinkConfigurationElements.ToArray();
            Assert.AreEqual(4, elements.Length);
            Assert.AreEqual("Microsoft.SemanticLogging.Etw", config.TraceEventService.SessionNamePrefix);

            Assert.IsNotNull(elements[0].SinkPromise.Value);
            Assert.AreEqual(1, elements[0].EventSources.Count());

            Assert.IsNotNull(elements[1].SinkPromise.Value);
            Assert.AreEqual(1, elements[1].EventSources.Count());

            Assert.IsNotNull(elements[2].SinkPromise.Value);
            Assert.AreEqual(1, elements[2].EventSources.Count());
        }
        /// <summary>
        /// Loads the specified file name.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="monitorChanges">If set to <c>true</c> monitor file changes.</param>
        /// <param name="createSinks">If set to <c>true</c> [create sinks].</param>
        /// <returns>
        /// The loaded <see cref="TraceEventServiceConfiguration" /> instance.
        /// </returns>
        /// <exception cref="ConfigurationException">All the validation errors detected when opening the file.</exception>
        public static TraceEventServiceConfiguration Load(string fileName, bool monitorChanges = false, bool createSinks = true)
        {
            var configReader = new ConfigurationReader(fileName);
            ConfigurationElement configElement = configReader.Read();

            var serviceSettings =
                new TraceEventServiceSettings
                {
                    SessionNamePrefix = configElement.TraceEventService.SessionNamePrefix
                };

            var sinkSettings = new List<SinkSettings>();

            foreach (var element in configElement.SinkConfigurationElements)
            {
                var eventSources =
                    element.EventSources.Select(
                        e =>
                            new EventSourceSettings(
                                e.Name,
                                e.EventId,
                                e.Level,
                                e.MatchAnyKeyword,
                                e.Arguments.Select(a => new KeyValuePair<string, string>(a.Key, a.Value)),
                                e.ProcessNameFilters.Select(p => p.Name)));
                var sink = createSinks ?
                    new SinkSettings(element.Name, element.SinkPromise.Value, eventSources) :
                    new SinkSettings(element.Name, element.SinkPromise, eventSources);
                sink.SinkConfiguration = element.SinkConfiguration;
                sinkSettings.Add(sink);
            }

            var configuration = new TraceEventServiceConfiguration(sinkSettings, serviceSettings);

            if (monitorChanges)
            {
                configuration.StartConfigurationWatcher(configReader.File);
            }

            return configuration;
        }