Exemple #1
0
        /// <summary>
        /// Handles the publisher.
        /// </summary>
        /// <param name="publisher">The publisher.</param>
        /// <param name="register">true to register publications, false to unregister them.</param>
        /// <param name="eventInfo">The published event..</param>
        /// <param name="attr">The attribute</param>
        /// <param name="eventTopicHost">The event topic host.</param>
        private void HandlePublisher(
            object publisher,
            bool register,
            EventInfo eventInfo,
            EventPublicationAttribute attr,
            IEventTopicHost eventTopicHost)
        {
            IEventTopic topic = eventTopicHost.GetEventTopic(attr.Topic);

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

                topic.AddPublication(
                    publisher,
                    eventInfo,
                    attr.HandlerRestriction,
                    matchers);
            }
            else
            {
                topic.RemovePublication(publisher, eventInfo);
            }
        }
Exemple #2
0
        public void RemovePublication(string topic, object publisher, string eventName)
        {
            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            IPublication publication = eventTopic.RemovePublication(publisher, eventName);

            if (publication != null)
            {
                publication.Dispose();
            }
        }
Exemple #3
0
        /// <summary>
        /// Removes a publication. Publications added with <see cref="AddPublication(string,object,ref EventHandler,HandlerRestriction,IPublicationMatcher[])"/> have to be removed in order that the event broker can be disposed.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="publisher">The publisher.</param>
        /// <param name="publishedEvent">The published event.</param>
        public void RemovePublication <TEventArgs>(string topic, object publisher, ref EventHandler <TEventArgs> publishedEvent) where TEventArgs : EventArgs
        {
            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            IPublication publication = eventTopic.RemovePublication(publisher, CodePublication <TEventArgs> .EventNameOfCodePublication);

            var codePublication = publication as CodePublication <TEventArgs>;

            if (codePublication != null)
            {
                codePublication.Unregister(ref publishedEvent);
            }
        }
Exemple #4
0
        private void UnregisterPropertyPublications(object publisher, IEnumerable <PropertyPublicationScanResult> propertyPublications)
        {
            foreach (PropertyPublicationScanResult propertyPublication in propertyPublications)
            {
                IEventTopic topic = this.eventTopicHost.GetEventTopic(propertyPublication.Topic);

                IPublication publication = topic.RemovePublication(publisher, propertyPublication.Event.Name);

                if (publication != null)
                {
                    publication.Dispose();
                }
            }
        }
        /// <summary>
        /// Fires the specified topic directly on the <see cref="IEventBroker"/> without a real publisher.
        /// This is useful when temporarily created objects need to fire events.
        /// The event is fired globally but can be matched with <see cref="Matchers.ISubscriptionMatcher"/>.
        /// </summary>
        /// <param name="topic">The topic URI.</param>
        /// <param name="publisher">The publisher (for event flow and logging).</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="sender">The sender (passed to the event handler).</param>
        /// <param name="eventArgs">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public void Fire(string topic, object publisher, HandlerRestriction handlerRestriction, object sender, EventArgs eventArgs)
        {
            Ensure.ArgumentNotNull(eventArgs, "eventArgs");

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

            using (var spontaneousPublication = new SpontaneousPublication(eventTopic, publisher, eventArgs.GetType(), handlerRestriction, new List <IPublicationMatcher>()))
            {
                eventTopic.AddPublication(spontaneousPublication);

                eventTopic.Fire(sender, eventArgs, spontaneousPublication);

                eventTopic.RemovePublication(spontaneousPublication);
            }
        }
        /// <summary>
        /// Fires the specified topic directly on the <see cref="IEventBroker"/> without a real publisher.
        /// This is useful when temporarily created objects need to fire events.
        /// The event is fired globally but can be matched with <see cref="Matchers.ISubscriptionMatcher"/>.
        /// </summary>
        /// <param name="topic">The topic URI.</param>
        /// <param name="publisher">The publisher (for event flow and logging).</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="sender">The sender (passed to the event handler).</param>
        /// <param name="eventArgs">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public void Fire(string topic, object publisher, HandlerRestriction handlerRestriction, object sender, EventArgs eventArgs)
        {
            Guard.AgainstNullArgument(nameof(eventArgs), eventArgs);

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

            using (var spontaneousPublication = new SpontaneousPublication(eventTopic, publisher, eventArgs.GetType(), handlerRestriction, new List <IPublicationMatcher>()))
            {
                eventTopic.AddPublication(spontaneousPublication);

                eventTopic.Fire(sender, eventArgs, spontaneousPublication);

                eventTopic.RemovePublication(publisher, SpontaneousPublication.SpontaneousEventName);
            }
        }
Exemple #7
0
        /// <summary>
        /// Processes the publisher.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="publisher">The publisher.</param>
        /// <param name="eventName">Name of the event.</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="matchers">The matchers.</param>
        /// <param name="register">true to register publications, false to unregister them.</param>
        /// <param name="eventTopicHost">The event topic host.</param>
        public void ProcessPublisher(string topic, object publisher, string eventName, HandlerRestriction handlerRestriction, IList <IPublicationMatcher> matchers, bool register, IEventTopicHost eventTopicHost)
        {
            EventInfo eventInfo = publisher.GetType().GetEvent(eventName);

            if (eventInfo == null)
            {
                throw new PublisherEventNotFoundException(publisher.GetType(), eventName);
            }

            IEventTopic eventTopic = eventTopicHost.GetEventTopic(topic);

            if (register)
            {
                eventTopic.AddPublication(publisher, eventInfo, handlerRestriction, matchers);
            }
            else
            {
                eventTopic.RemovePublication(publisher, eventInfo);
            }
        }
        /// <summary>
        /// Removes a publication. Publications added with <see cref="AddPublication(string,object,ref EventHandler,HandlerRestriction,IPublicationMatcher[])"/> have to be removed in order that the event broker can be disposed.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="publisher">The publisher.</param>
        /// <param name="publishedEvent">The published event.</param>
        public void RemovePublication <TEventArgs>(string topic, object publisher, ref EventHandler <TEventArgs> publishedEvent) where TEventArgs : EventArgs
        {
            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            eventTopic.RemovePublication(publisher, ref publishedEvent);
        }
        /// <summary>
        /// Removes a publication. Publications added with <see cref="AddPublication(string,object,ref EventHandler,HandlerRestriction,IPublicationMatcher[])"/> have to be removed in order that the event broker can be disposed.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="publisher">The publisher.</param>
        /// <param name="publishedEvent">The published event.</param>
        public void RemovePublication(string topic, object publisher, ref EventHandler publishedEvent)
        {
            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            eventTopic.RemovePublication(publisher, ref publishedEvent);
        }