/// <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);
                }
            }
        }
        /// <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);
 }