Beispiel #1
0
        private void RemoveSubscription(
            string eventName,
            Subscription subsToRemove
            )
        {
            if (subsToRemove == null)
            {
                return;
            }

            // a necessidade da reatribuição abaixo é justificada pelo uso desta lista durante o consumo.
            // se a mesma for modificada, será gerada uma exceção de coleção modificada no consumo de mensagens.
            _handlers[eventName] = new List <Subscription>(_handlers[eventName]);
            _handlers[eventName].Remove(subsToRemove);

            if (_handlers[eventName].Any())
            {
                return;
            }

            _handlers.Remove(eventName);
            if (OnEventRemoved != null)
            {
                OnEventRemoved.Invoke(this, new EventEventArgs(eventName));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TEvent"></typeparam>
        /// <typeparam name="TEventHandler"></typeparam>
        public void RemoveSubscription <TEvent, TEventHandler>()
            where TEventHandler : IEventHandler <TEvent>
        {
            var eventName = GetEventKey <TEvent>();

            if (!HasSubscriptions(eventName))
            {
                return;
            }

            var handlerType  = typeof(TEventHandler);
            var eventHandler = eventHandlers[eventName].SingleOrDefault(_ => _ == handlerType);

            if (eventHandler == null)
            {
                return;
            }

            eventHandlers[eventName].Remove(eventHandler);
            if (!eventHandlers[eventName].Any())
            {
                eventHandlers.Remove(eventName);
                eventTypes.Remove(eventName);

                OnEventRemoved.Invoke(this, eventName);
            }
        }
Beispiel #3
0
        public void RemoveSubscription <TEvent, TEventHandler>()
            where TEvent : Event
            where TEventHandler : IEventHandler <TEvent>
        {
            var eventName           = GetEventKey <TEvent>();
            var handlerToRemoveType = typeof(TEventHandler);
            var handlerToRemove     = _handlers[eventName].SingleOrDefault(eventHandler => eventHandler.GetType() == handlerToRemoveType);

            if (handlerToRemove != null)
            {
                _handlers[eventName].Remove(handlerToRemove);
                if (!_handlers[eventName].Any())
                {
                    _handlers.Remove(eventName);
                    var eventType = _eventTypes.SingleOrDefault(e => e.Name == eventName);
                    if (eventType != null)
                    {
                        _eventTypes.Remove(eventType);
                    }

                    OnEventRemoved.Invoke(this, eventName);
                }
            }
        }
Beispiel #4
0
 private void RaiseOnEventRemoved(string eventName)
 {
     OnEventRemoved?.Invoke(this, eventName);
 }
 protected void RaiseOnEventRemoved(string eventName)
 {
     OnEventRemoved?.Invoke(this, eventName);
 }
Beispiel #6
0
        private void RemoveEvent(string eventName)
        {
            _eventHandlers.Remove(eventName);

            OnEventRemoved?.Invoke(this, eventName);
        }