Exemple #1
0
        /// <summary>
        /// Handles the subscriber.
        /// </summary>
        /// <param name="subscriber">The subscriber.</param>
        /// <param name="register">true to register subscriptions, false to unregister them.</param>
        /// <param name="methodInfo">The handler method.</param>
        /// <param name="attr">The subscription attribute.</param>
        /// <param name="eventTopicHost">The event topic host.</param>
        private void HandleSubscriber(
            object subscriber,
            bool register,
            MethodInfo methodInfo,
            EventSubscriptionAttribute attr,
            IEventTopicHost eventTopicHost)
        {
            IEventTopic topic = eventTopicHost.GetEventTopic(attr.Topic);

            if (register)
            {
                List <ISubscriptionMatcher> matchers = new List <ISubscriptionMatcher>();
                foreach (Type type in attr.MatcherTypes)
                {
                    matchers.Add(this.factory.CreateSubscriptionMatcher(type));
                }

                topic.AddSubscription(
                    subscriber,
                    methodInfo,
                    this.factory.CreateHandler(attr.HandlerType),
                    matchers);
            }
            else
            {
                topic.RemoveSubscription(subscriber, methodInfo);
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds a subscription. Use this to register subscriptions by code instead of using attributes.
        /// </summary>
        /// <typeparam name="TEventArgs">The type of the event arguments.</typeparam>
        /// <param name="topic">The topic.</param>
        /// <param name="subscriber">The subscriber.</param>
        /// <param name="handlerMethod">The handler method.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="matchers">The subscription matchers.</param>
        public void AddSubscription <TEventArgs>(string topic, object subscriber, EventHandler <TEventArgs> handlerMethod, IHandler handler, params ISubscriptionMatcher[] matchers) where TEventArgs : EventArgs
        {
            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            eventTopic.AddSubscription(
                subscriber,
                handlerMethod.Method,
                handler,
                matchers != null ? new List <ISubscriptionMatcher>(matchers) : new List <ISubscriptionMatcher>());
        }
        /// <summary>
        /// Adds a subscription. Use this to register subscriptions by code instead of using attributes.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="subscriber">The subscriber.</param>
        /// <param name="handlerMethod">The handler method.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="matchers">The subscription matchers.</param>
        public void AddSubscription(string topic, object subscriber, EventHandler handlerMethod, IHandler handler, params ISubscriptionMatcher[] matchers)
        {
            Ensure.ArgumentNotNull(handlerMethod, "handlerMethod");

            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            eventTopic.AddSubscription(
                subscriber,
                handlerMethod.Method,
                handler,
                matchers != null ? new List <ISubscriptionMatcher>(matchers) : new List <ISubscriptionMatcher>());
        }
Exemple #4
0
        /// <summary>
        /// Handles the subscriber.
        /// </summary>
        /// <param name="eventTopicHost">The event topic host.</param>
        /// <param name="topic">The topic.</param>
        /// <param name="register">if set to <c>true</c> [register].</param>
        /// <param name="subscriber">The subscriber.</param>
        /// <param name="handlerMethod">The handler method.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="matchers">The matchers.</param>
        private void HandleSubscriber(IEventTopicHost eventTopicHost, string topic, bool register, object subscriber, MethodInfo handlerMethod, IHandler handler, ISubscriptionMatcher[] matchers)
        {
            IEventTopic eventTopic = eventTopicHost.GetEventTopic(topic);

            if (register)
            {
                eventTopic.AddSubscription(subscriber, handlerMethod, handler, matchers);
            }
            else
            {
                eventTopic.RemoveSubscription(subscriber, handlerMethod);
            }
        }
Exemple #5
0
        private void AddSubscription(string topic, object subscriber, IHandler handler, IEnumerable <ISubscriptionMatcher> matchers, MethodInfo methodInfo)
        {
            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            handler.Initialize(subscriber, methodInfo, this.extensionHost);

            DelegateWrapper delegateWrapper = GetDelegateWrapper(methodInfo);
            ISubscription   subscription    = this.factory.CreateSubscription(
                subscriber,
                delegateWrapper,
                handler,
                matchers != null ? new List <ISubscriptionMatcher>(matchers) : new List <ISubscriptionMatcher>());

            eventTopic.AddSubscription(subscription);
        }
Exemple #6
0
        private void RegisterPropertySubscriptions(object item, ScanResult scanResult)
        {
            foreach (PropertySubscriptionScanResult propertySubscription in scanResult.Subscription)
            {
                IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(propertySubscription.Topic);

                var subscriptionMatchers = from subscriptionMatcherType in propertySubscription.SubscriptionMatcherTypes
                                           select this.factory.CreateSubscriptionMatcher(subscriptionMatcherType);

                var handler = this.factory.CreateHandler(propertySubscription.HandlerType);
                handler.Initialize(item, propertySubscription.Method, this.extensionHost);

                DelegateWrapper delegateWrapper = GetDelegateWrapper(propertySubscription.Method);
                ISubscription   subscription    = this.factory.CreateSubscription(item, delegateWrapper, handler, subscriptionMatchers.ToList());

                eventTopic.AddSubscription(subscription);
            }
        }
Exemple #7
0
        /// <summary>
        /// Adds a subscription. Use this to register subscriptions by code instead of using attributes.
        /// </summary>
        /// <typeparam name="TEventArgs">The type of the event arguments.</typeparam>
        /// <param name="topic">The topic.</param>
        /// <param name="subscriber">The subscriber.</param>
        /// <param name="handlerMethod">The handler method.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="matchers">The subscription matchers.</param>
        public void AddSubscription <TEventArgs>(string topic, object subscriber, EventHandler <TEventArgs> handlerMethod, IHandler handler, params ISubscriptionMatcher[] matchers) where TEventArgs : EventArgs
        {
            Ensure.ArgumentNotNull(handler, "handler");
            Ensure.ArgumentNotNull(handlerMethod, "handlerMethod");

            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            handler.Initialize(subscriber, handlerMethod.Method, this.extensionHost);

            DelegateWrapper delegateWrapper = GetDelegateWrapper(handlerMethod.Method);
            ISubscription   subscription    = this.factory.CreateSubscription(
                subscriber,
                delegateWrapper,
                handler,
                matchers != null ? new List <ISubscriptionMatcher>(matchers) : new List <ISubscriptionMatcher>());

            eventTopic.AddSubscription(subscription);
        }