private void RemoveSubscriptionInternal <TMessage>(BusSubscriptionToken subscriptionToken) where TMessage : class, IBusMessage { if (subscriptionToken == null) { throw new ArgumentNullException("subscriptionToken"); } lock (_SubscriptionsPadlock) { var currentlySubscribed = (from sub in _Subscriptions where object.ReferenceEquals(sub.Subscription.SubscriptionToken, subscriptionToken) select sub).ToList(); currentlySubscribed.ForEach(sub => _Subscriptions.Remove(sub)); } }
public StrongBusSubscription(BusSubscriptionToken subscriptionToken, Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter) { if (subscriptionToken == null) { throw new ArgumentNullException("subscriptionToken"); } if (deliveryAction == null) { throw new ArgumentNullException("deliveryAction"); } if (messageFilter == null) { throw new ArgumentNullException("messageFilter"); } _SubscriptionToken = subscriptionToken; _DeliveryAction = deliveryAction; _MessageFilter = messageFilter; }
public WeakBusSubscription(BusSubscriptionToken subscriptionToken, Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter) { if (subscriptionToken == null) { throw new ArgumentNullException("subscriptionToken"); } if (deliveryAction == null) { throw new ArgumentNullException("deliveryAction"); } if (messageFilter == null) { throw new ArgumentNullException("messageFilter"); } _SubscriptionToken = subscriptionToken; _DeliveryAction = new WeakReference(deliveryAction); _MessageFilter = new WeakReference(messageFilter); }
private BusSubscriptionToken AddSubscriptionInternal <TMessage>(Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter, bool strongReference, IBusProxy proxy) where TMessage : class, IBusMessage { if (deliveryAction == null) { throw new ArgumentNullException("deliveryAction"); } if (messageFilter == null) { throw new ArgumentNullException("messageFilter"); } if (proxy == null) { throw new ArgumentNullException("proxy"); } var subscriptionToken = new BusSubscriptionToken(this, typeof(TMessage)); IBusSubscription subscription; if (strongReference) { subscription = new StrongBusSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter); } else { subscription = new WeakBusSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter); } lock (_SubscriptionsPadlock) { _Subscriptions.Add(new SubscriptionItem(proxy, subscription)); } return(subscriptionToken); }
public void Unsubscribe <TMessage>(BusSubscriptionToken subscriptionToken) where TMessage : class, IBusMessage { RemoveSubscriptionInternal <TMessage>(subscriptionToken); }