示例#1
0
        public void Post <T>(TrackingEvent trackingEvent)
        {
            if (trackingEvent.ValueType != typeof(T))
            {
                throw new ArgumentException("The posted type must match the event type", nameof(trackingEvent));
            }

            recordedEvents.Add(trackingEvent);

            if (!Enabled)
            {
                return;
            }

            try
            {
                PostedEventHandler handler = eventHandlers[typeof(T)];
                handler.Invoke(trackingEvent);
                trackingEvent.Handle();
            }
            catch (KeyNotFoundException)
            {
                // If we get here, it means we don't have a handler registered for this type.
                // This is fine, however.
                InformationDispatcher.Default.Dispatch($"No registered handler for the event with type { trackingEvent.ValueType.Name }", DebugLogContext.Current, InformationKind.Warning);
            }
        }
示例#2
0
 public void Register <T>(PostedEventHandler eventHandler)
 {
     eventHandlers[typeof(T)] = eventHandler;
 }