/// <summary> /// 是否包含了指定订阅标识 /// </summary> /// <param name="token"></param> /// <returns></returns> public virtual bool Contains(SubscriptionToken token) { lock (Subscriptions) { IMsgSubscription subscription = Subscriptions.FirstOrDefault(evt => evt.SubscriptionToken == token); return(subscription != null); } }
/// <summary> /// 取消匹配的第一个订阅 /// </summary> /// <param name="subscriber"></param> public virtual void Unsubscribe(Action <MessageSender, TMessage> subscriber) { lock (Subscriptions) { IMsgSubscription eventSubscription = Subscriptions.Cast <MsgSubscription <TMessage> >().FirstOrDefault(evt => evt.Action == subscriber); if (eventSubscription != null) { Subscriptions.Remove(eventSubscription); } } }
/// <summary> /// 取消订阅 /// </summary> /// <param name="token">订阅标识</param> public virtual void Unsubscribe(SubscriptionToken token) { lock (Subscriptions) { IMsgSubscription subscription = Subscriptions.FirstOrDefault(evt => evt.SubscriptionToken == token); if (subscription != null) { Subscriptions.Remove(subscription); } } }
protected virtual SubscriptionToken InternalSubscribe(IMsgSubscription msgSubscription) { if (msgSubscription == null) { throw new System.ArgumentNullException("msgSubscription"); } msgSubscription.SubscriptionToken = new SubscriptionToken(Unsubscribe); lock (Subscriptions) { Subscriptions.Add(msgSubscription); } return(msgSubscription.SubscriptionToken); }