public void UpdateSession(IEnumerable <EventSourceSettings> updatedEventSources)
        {
            Guard.ArgumentNotNull(updatedEventSources, "updatedEventSources");

            var eventSourceComparer = new EventSourceSettingsEqualityComparer(nameOnly: true);

            // updated sources
            foreach (var currentSource in this.eventSources.Intersect(updatedEventSources, eventSourceComparer).ToArray())
            {
                var updatedSource = updatedEventSources.Single(s => s.Name == currentSource.Name);
                if (updatedSource.Level != currentSource.Level ||
                    updatedSource.MatchAnyKeyword != currentSource.MatchAnyKeyword)
                {
                    TraceEventUtil.EnableProvider(this.session, updatedSource.EventSourceId, updatedSource.Level, updatedSource.MatchAnyKeyword, sendManifest: false);
                    currentSource.Level           = updatedSource.Level;
                    currentSource.MatchAnyKeyword = updatedSource.MatchAnyKeyword;
                }
            }

            // new sources
            foreach (var newSource in updatedEventSources.Except(this.eventSources, eventSourceComparer).ToArray())
            {
                TraceEventUtil.EnableProvider(this.session, newSource.EventSourceId, newSource.Level, newSource.MatchAnyKeyword, sendManifest: true);
                this.eventSources.Add(newSource);
            }

            // removed sources
            foreach (var removedSource in this.eventSources.Except(updatedEventSources, eventSourceComparer).ToArray())
            {
                this.session.DisableProvider(removedSource.EventSourceId);
                this.eventSources.Remove(removedSource);
            }
        }
Example #2
0
        public void UpdateSession(IEnumerable<EventSourceSettings> updatedEventSources)
        {
            Guard.ArgumentNotNull(updatedEventSources, "updatedEventSources");

            var eventSourceComparer = new EventSourceSettingsEqualityComparer(nameOnly: true);

            // updated sources
            foreach (var currentSource in this.eventSources.Intersect(updatedEventSources, eventSourceComparer).ToArray())
            {
                var updatedSource = updatedEventSources.Single(s => s.Name == currentSource.Name);
                if (updatedSource.Level != currentSource.Level ||
                    updatedSource.MatchAnyKeyword != currentSource.MatchAnyKeyword)
                {
                    TraceEventUtil.EnableProvider(this.session, updatedSource.EventSourceId, updatedSource.Level, updatedSource.MatchAnyKeyword, sendManifest: false);
                    currentSource.Level = updatedSource.Level;
                    currentSource.MatchAnyKeyword = updatedSource.MatchAnyKeyword;
                }
            }

            // new sources
            foreach (var newSource in updatedEventSources.Except(this.eventSources, eventSourceComparer).ToArray())
            {
                TraceEventUtil.EnableProvider(this.session, newSource.EventSourceId, newSource.Level, newSource.MatchAnyKeyword, sendManifest: true);
                this.eventSources.Add(newSource);
            }

            // removed sources
            foreach (var removedSource in this.eventSources.Except(updatedEventSources, eventSourceComparer).ToArray())
            {
                this.session.DisableProvider(removedSource.EventSourceId);
                this.eventSources.Remove(removedSource);
            }
        }
        public void UpdateSession(IEnumerable <Configuration.EventSourceSettings> updatedEventSources)
        {
            Guard.ArgumentNotNull(updatedEventSources, "updatedEventSources");
            var updatedSources = updatedEventSources as Configuration.EventSourceSettings[] ?? updatedEventSources.ToArray();

            var eventSourceNameComparer = new EventSourceSettingsEqualityComparer(nameOnly: true);
            var eventSourceFullComparer = new EventSourceSettingsEqualityComparer(nameOnly: false);

            // updated sources
            foreach (var currentSource in this.eventSources.Intersect(updatedSources, eventSourceNameComparer).ToArray())
            {
                var updatedSource = updatedSources.Single(s => s.Name == currentSource.Name);
                if (!eventSourceFullComparer.Equals(currentSource, updatedSource))
                {
                    currentSource.CopyValuesFrom(updatedSource);
                    TraceEventUtil.EnableProvider(
                        this.session,
                        currentSource.EventSourceId,
                        currentSource.Level,
                        currentSource.MatchAnyKeyword,
                        currentSource.Arguments,
                        currentSource.ProcessNamesToFilter,
                        sendManifest: false);
                }
            }

            // new sources
            foreach (var newSource in updatedSources.Except(this.eventSources, eventSourceNameComparer).ToArray())
            {
                TraceEventUtil.EnableProvider(
                    this.session,
                    newSource.EventSourceId,
                    newSource.Level,
                    newSource.MatchAnyKeyword,
                    newSource.Arguments,
                    newSource.ProcessNamesToFilter,
                    sendManifest: true);
                this.eventSources.Add(newSource);
            }

            // removed sources
            foreach (var removedSource in this.eventSources.Except(updatedSources, eventSourceNameComparer).ToArray())
            {
                this.session.DisableProvider(removedSource.EventSourceId);
                this.eventSources.Remove(removedSource);
            }
        }
        public void UpdateSession(IEnumerable<EventSourceSettings> updatedEventSources)
        {
            Guard.ArgumentNotNull(updatedEventSources, "updatedEventSources");
            var updatedSources = updatedEventSources as EventSourceSettings[] ?? updatedEventSources.ToArray();

            var eventSourceNameComparer = new EventSourceSettingsEqualityComparer(nameOnly: true);
            var eventSourceFullComparer = new EventSourceSettingsEqualityComparer(nameOnly: false);

            // updated sources
            foreach (var currentSource in this.eventSources.Intersect(updatedSources, eventSourceNameComparer).ToArray())
            {
                var updatedSource = updatedSources.Single(s => s.Name == currentSource.Name);
                if (!eventSourceFullComparer.Equals(currentSource, updatedSource))
                {
                    currentSource.CopyValuesFrom(updatedSource);
                    TraceEventUtil.EnableProvider(
                        this.session,
                        currentSource.EventSourceId,
                        currentSource.Level,
                        currentSource.MatchAnyKeyword,
                        currentSource.Arguments,
                        currentSource.ProcessNamesToFilter,
                        sendManifest: false);
                }
            }

            // new sources
            foreach (var newSource in updatedSources.Except(this.eventSources, eventSourceNameComparer).ToArray())
            {
                TraceEventUtil.EnableProvider(
                    this.session,
                    newSource.EventSourceId,
                    newSource.Level,
                    newSource.MatchAnyKeyword,
                    newSource.Arguments,
                    newSource.ProcessNamesToFilter,
                    sendManifest: true);
                this.eventSources.Add(newSource);
            }

            // removed sources
            foreach (var removedSource in this.eventSources.Except(updatedSources, eventSourceNameComparer).ToArray())
            {
                this.session.DisableProvider(removedSource.EventSourceId);
                this.eventSources.Remove(removedSource);
            }
        }
        private void OnFileChanged(object sender, FileSystemEventArgs e)
        {
            try
            {
                //// turn off events to avoid duplicates
                this.watcher.EnableRaisingEvents = false;

                //// Wait to reduce the chance for any transient IO error condition (file locks, etc) 
                Thread.Sleep(500);

                ////Reload updated file and compare configurations
                var updatedConfig = TraceEventServiceConfiguration.Load(e.FullPath, monitorChanges: false, createSinks: false);

                if (!updatedConfig.Settings.Equals(this.Settings))
                {
                    this.Settings.SessionNamePrefix = updatedConfig.Settings.SessionNamePrefix;
                    //// Shortcut for recycling service
                    return;
                }

                var sinkComparer = new SinkSettingsEqualityComparer();
                var eventSourceComparer = new EventSourceSettingsEqualityComparer();

                // removed sinks
                foreach (var removedSink in this.sinkSettings.Except(updatedConfig.SinkSettings, sinkComparer).ToArray())
                {
                    this.sinkSettings.Remove(removedSink);
                }

                // updated sinks
                foreach (var currentSink in this.sinkSettings.Intersect(updatedConfig.SinkSettings, sinkComparer).ToArray())
                {
                    var updatedSink = updatedConfig.SinkSettings.Single(s => s.Name == currentSink.Name);
                    if (updatedSink.SinkConfiguration != currentSink.SinkConfiguration)
                    {
                        // the sink definition was updated so remove/add 
                        this.sinkSettings.Remove(currentSink);
                        this.sinkSettings.Add(updatedSink);
                    }
                    else if (!updatedSink.EventSources.SequenceEqual(currentSink.EventSources, eventSourceComparer))
                    {
                        currentSink.EventSources = updatedSink.EventSources;
                        this.sinkSettings[this.sinkSettings.IndexOf(currentSink)] = currentSink;
                    }
                }

                // new sinks
                foreach (var newSink in updatedConfig.sinkSettings.Except(this.SinkSettings, sinkComparer).ToArray())
                {
                    this.sinkSettings.Add(newSink);
                }
            }
            catch (Exception exception)
            {
                this.OnFileError(sender, new ErrorEventArgs(exception));
            }
            finally
            {
                if (!this.disposed)
                {
                    if (this.watcherDisposed)
                    {
                        //// Regenerate watcher instance because it was disposed and we are still running.
                        this.StartConfigurationWatcher();
                    }
                    else
                    {
                        this.watcher.EnableRaisingEvents = true;
                    }
                }
            }
        }