Пример #1
0
 /// <summary>
 /// 取消订阅
 /// </summary>
 /// <param name="handler"></param>
 public void Unsubscribe(EventMessageHandler handler)
 {
     if (_handlers.ContainsKey(handler.Id))
     {
         _handlers[handler.Id].Remove(handler);
     }
 }
Пример #2
0
        internal void Unsubscribe(EventMessageHandler eventMessageHandler)
        {
            var eventAggergators = new List <EventAggregator>(_eventAggregators.Values);

            foreach (EventAggregator eventAggergator in eventAggergators)
            {
                if (eventAggergator.ContainsHandlers(eventMessageHandler.Id))
                {
                    eventAggergator.Unsubscribe(eventMessageHandler);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 订阅
        /// </summary>
        /// <param name="subscribeId"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        public EventMessageHandler Subscribe(string subscribeId, Action <EventMessage> handler)
        {
            var eventMessageHandler = new EventMessageHandler(subscribeId, handler);

            if (_handlers.ContainsKey(subscribeId))
            {
                _handlers[subscribeId].Add(eventMessageHandler);
            }
            else
            {
                _handlers.Add(subscribeId, new List <EventMessageHandler>
                {
                    eventMessageHandler
                });
            }

            return(eventMessageHandler);
        }
Пример #4
0
 public static void Unsubscribe(this object eventSource, EventHub eventHub,
                                EventMessageHandler eventMessageHandler)
 {
     eventHub.Unsubscribe(eventMessageHandler);
 }