Пример #1
0
        private async Task Process(CarNotificationEventData eventBusData)
        {
            var eventName = eventBusData.GetType().Name;

            if (HasSubscriptionsForEvent(eventName))
            {
                var subscriptions = _handler[eventName];

                foreach (var subscription in subscriptions)
                {
                    var eventType    = GetEventTypeByName(eventName);
                    var handler      = _service.GetService(subscription);
                    var concreteType = typeof(IEventHandler <>).MakeGenericType(eventType);

                    await(Task) concreteType.GetMethod("EventHandle").Invoke(handler, new object[] { eventBusData });
                }
            }
        }
Пример #2
0
        private void DoRemoveHandler(CarNotificationEventData eventData, Type subsToRemove)
        {
            if (subsToRemove != null)
            {
                var eventName = eventData.GetType().Name;

                _handler[eventName].Remove(subsToRemove);
                if (!_handler[eventName].Any())
                {
                    _handler.Remove(eventName);
                    var eventType = _eventTypes.SingleOrDefault(e => e == eventName.GetType());
                    if (eventType != null)
                    {
                        _eventTypes.Remove(eventType);
                    }
                    RaiseOnEventRemoved(eventData);
                }
            }
        }