예제 #1
0
        internal void StopEvent(string requestId, EventBase eventToStop)
        {
            if (!HasReceiver() || string.IsNullOrWhiteSpace(requestId))
            {
                return;
            }

            var eventKey = new EventKey(requestId, eventToStop);

            // Locate the same name event in the EventsInProgress map
            EventBase eventStarted = null;

            if (EventsInProgress.ContainsKey(eventKey))
            {
                eventStarted = EventsInProgress[eventKey];
            }

            // If we did not get anything back from the dictionary, most likely its a bug that StopEvent
            // was called without a corresponding StartEvent
            if (null == eventStarted)
            {
                // Stop Event called without a corresponding start_event.
                return;
            }

            // Set execution time properties on the event adn increment the event count.
            eventToStop.Stop();
            IncrementEventCount(requestId, eventToStop);

            if (!CompletedEvents.ContainsKey(requestId))
            {
                // if this is the first event associated to this
                // RequestId we need to initialize a new List to hold
                // all of sibling events
                var events = new List <EventBase>
                {
                    eventToStop
                };
                CompletedEvents.TryAdd(requestId, events);
            }
            else
            {
                // if this event shares a RequestId with other events
                // just add it to the List
                if (CompletedEvents.TryGetValue(requestId, out List <EventBase> events))
                {
                    events.Add(eventToStop);
                }
            }

            // Mark this event as no longer in progress
            EventsInProgress.TryRemove(eventKey, out var dummy);
        }
        public void StopEvent(EventBase eventToStop)
        {
            if (!IsMatsConfigured)
            {
                return;
            }

            var eventKey = new EventKey(eventToStop);

            // Locate the same name event in the EventsInProgress map
            _eventsInProgress.TryGetValue(eventKey, out EventBase eventStarted);

            // If we did not get anything back from the dictionary, most likely its a bug that StopEvent
            // was called without a corresponding StartEvent
            if (null == eventStarted)
            {
                // Stop Event called without a corresponding start_event.
                return;
            }

            // Set execution time properties on the event and increment the event count.
            eventToStop.Stop();

            IncrementEventCount(eventToStop);

            if (_completedEvents.TryGetValue(eventToStop.CorrelationId, out List <EventBase> events))
            {
                events.Add(eventToStop);
            }
            else
            {
                _completedEvents.TryAdd(
                    eventToStop.CorrelationId,
                    new List <EventBase>
                {
                    eventToStop
                });
            }

            // Mark this event as no longer in progress
            _eventsInProgress.TryRemove(eventKey, out _);

            // Store the most recent API event we've stopped.
            if (eventToStop.TryGetValue(MsalTelemetryBlobEventNames.ApiIdConstStrKey, out _))
            {
                lock (_mostRecentStoppedApiEventLockObj)
                {
                    _mostRecentStoppedApiEvent = eventToStop;
                }
            }
        }
        public void StopEvent(EventBase eventToStop)
        {
            if (!HasReceiver())
            {
                return;
            }

            var eventKey = new EventKey(eventToStop);

            // Locate the same name event in the EventsInProgress map
            EventBase eventStarted = null;

            EventsInProgress.TryGetValue(eventKey, out eventStarted);

            // If we did not get anything back from the dictionary, most likely its a bug that StopEvent
            // was called without a corresponding StartEvent
            if (null == eventStarted)
            {
                // Stop Event called without a corresponding start_event.
                return;
            }

            // Set execution time properties on the event adn increment the event count.
            eventToStop.Stop();
            IncrementEventCount(eventToStop);

            if (CompletedEvents.TryGetValue(eventToStop.TelemetryCorrelationId, out List <EventBase> events))
            {
                events.Add(eventToStop);
            }
            else
            {
                CompletedEvents.TryAdd(
                    eventToStop.TelemetryCorrelationId,
                    new List <EventBase>
                {
                    eventToStop
                });
            }

            // Mark this event as no longer in progress
            EventsInProgress.TryRemove(eventKey, out var dummy);
        }