コード例 #1
0
        private void RemoveSubscriptionInternal <TMessage>(TinyMessageSubscriptionToken subscriptionToken)
            where TMessage : class, ITinyMessage
        {
            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
            /// <summary>
            /// Initializes a new instance of the TinyMessageSubscription class.
            /// </summary>
            /// <param name="destination">Destination object</param>
            /// <param name="deliveryAction">Delivery action</param>
            /// <param name="messageFilter">Filter function</param>
            public StrongTinyMessageSubscription(TinyMessageSubscriptionToken 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
            /// <summary>
            /// Initializes a new instance of the WeakTinyMessageSubscription class.
            /// </summary>
            /// <param name="destination">Destination object</param>
            /// <param name="deliveryAction">Delivery action</param>
            /// <param name="messageFilter">Filter function</param>
            public WeakTinyMessageSubscription(TinyMessageSubscriptionToken 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 TinyMessageSubscriptionToken AddSubscriptionInternal <TMessage>(Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter, bool strongReference, ITinyMessageProxy proxy)
            where TMessage : class, ITinyMessage
        {
            if (deliveryAction == null)
            {
                throw new ArgumentNullException("deliveryAction");
            }

            if (messageFilter == null)
            {
                throw new ArgumentNullException("messageFilter");
            }

            if (proxy == null)
            {
                throw new ArgumentNullException("proxy");
            }

            lock (_SubscriptionsPadlock)
            {
                var subscriptionToken = new TinyMessageSubscriptionToken(this, typeof(TMessage));

                ITinyMessageSubscription subscription;
                if (strongReference)
                {
                    subscription = new StrongTinyMessageSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter);
                }
                else
                {
                    subscription = new WeakTinyMessageSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter);
                }

                _Subscriptions.Add(new SubscriptionItem(proxy, subscription));

                return(subscriptionToken);
            }
        }
コード例 #5
0
 public static void Unsubscribe(TinyMessageSubscriptionToken subscriptionToken)
 {
     Hub.Unsubscribe(subscriptionToken);
 }
コード例 #6
0
 public static void Unsubscribe <TMessage>(TinyMessageSubscriptionToken subscriptionToken) where TMessage : class, ITinyMessage
 {
     Hub.Unsubscribe(subscriptionToken);
 }
コード例 #7
0
 /// <summary>
 /// Unsubscribe from a particular message type.
 ///
 /// Does not throw an exception if the subscription is not found.
 /// </summary>
 /// <param name="subscriptionToken">Subscription token received from Subscribe</param>
 public void Unsubscribe(TinyMessageSubscriptionToken subscriptionToken)
 {
     RemoveSubscriptionInternal <ITinyMessage>(subscriptionToken);
 }
コード例 #8
0
 /// <summary>
 /// Unsubscribe from a particular message type.
 ///
 /// Does not throw an exception if the subscription is not found.
 /// </summary>
 /// <typeparam name="TMessage">Type of message</typeparam>
 /// <param name="subscriptionToken">Subscription token received from Subscribe</param>
 public void Unsubscribe <TMessage>(TinyMessageSubscriptionToken subscriptionToken) where TMessage : class, ITinyMessage
 {
     RemoveSubscriptionInternal <TMessage>(subscriptionToken);
 }