Ejemplo n.º 1
0
        /// <summary>
        /// Remove a delegate from local subscriptions in the list.
        /// </summary>
        /// <param name="type">The type of the notification.</param>
        /// <param name="handler">The handler for the notification.</param>
        public void Remove(Type type, NotificationHandler handler)
        {
            IList <Subscription> removeList = new List <Subscription>();

            lock (this)
            {
                // first the ones to remove
                foreach (Subscription subscription in subscribers)
                {
                    LocalSubscription localSubscription = subscription as LocalSubscription;
                    if (localSubscription != null)
                    {
                        if (localSubscription.NotificationType != null &&
                            localSubscription.NotificationType.Equals(type) &&
                            localSubscription.Handler.Equals(handler))
                        {
                            removeList.Add(localSubscription);
                        }
                    }
                }
            }

            // then remove separately
            foreach (Subscription subscription in removeList)
            {
                RemoveOne(subscription);
            }
        }
        /// <summary>
        /// Registers a notification subscription (including type, handlers and filters).
        /// </summary>
        /// <param name="type">The type of the message to register for.</param>
        /// <param name="handler">The handler to invoke when a message of the given type arrives.</param>
        /// <param name="filters">The filters that apply for this subscription so not to get certain messages.</param>
        public static void Register(Type type, NotificationHandler handler, IList <ISubscriptionFilter> filters)
        {
            LocalSubscription subscription = new LocalSubscription(type, handler, filters);

            lock (subscriptions)
            {
                subscriptions.Add(subscription);
            }
        }