示例#1
0
        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));
            }
        }
示例#2
0
            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;
            }
示例#3
0
            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);
            }
示例#4
0
        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);
        }
示例#5
0
 public void Unsubscribe <TMessage>(BusSubscriptionToken subscriptionToken)
     where TMessage : class, IBusMessage
 {
     RemoveSubscriptionInternal <TMessage>(subscriptionToken);
 }