/// <summary>
        /// Initializes a new instance of the <see cref="PropertyPublication"/> class.
        /// </summary>
        /// <param name="topic">The event topic this publication belongs to.</param>
        /// <param name="publisher">The publisher.</param>
        /// <param name="eventInfo">The <see cref="EventInfo"/> of the publisher that registers this event topic.</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="publicationMatchers">The publication matchers.</param>
        public PropertyPublication(
            IEventTopic topic,
            object publisher,
            EventInfo eventInfo,
            HandlerRestriction handlerRestriction,
            IList <IPublicationMatcher> publicationMatchers) :
            base(topic, publisher, handlerRestriction, publicationMatchers)
        {
            this.eventInfo = eventInfo;

            if (this.eventInfo.EventHandlerType == null)
            {
                throw new EventBrokerException("EventHandlerType on published event must not be null (internal EventBroker failure).");
            }

            ThrowIfInvalidEventHandler(this.eventInfo);
            ThrowIfEventIsStatic(this.eventInfo);

            this.eventArgsType = this.eventInfo.EventHandlerType == typeof(EventHandler)
                                     ? typeof(EventArgs)
                                     : this.eventInfo.EventHandlerType.GetGenericArguments()[0];

            Delegate handler = Delegate.CreateDelegate(
                this.eventInfo.EventHandlerType,
                this,
                this.GetType().GetMethod("PublicationHandler"));

            this.eventInfo.AddEventHandler(publisher, handler);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyPublication"/> class.
        /// </summary>
        /// <param name="topic">The event topic this publication belongs to.</param>
        /// <param name="publisher">The publisher.</param>
        /// <param name="eventInfo">The <see cref="EventInfo"/> of the publisher that registers this event topic.</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="publicationMatchers">The publication matchers.</param>
        public PropertyPublication(
            IEventTopic topic,
            object publisher,
            EventInfo eventInfo,
            HandlerRestriction handlerRestriction,
            IList<IPublicationMatcher> publicationMatchers) : 
                base(topic, publisher, handlerRestriction, publicationMatchers)
        {
            this.eventInfo = eventInfo;

            if (this.eventInfo.EventHandlerType == null)
            {
                throw new Exception("EventHandlerType on published event must not be null (internal EventBroker failure).");
            }

            ThrowIfInvalidEventHandler(this.eventInfo);
            ThrowIfEventIsStatic(this.eventInfo);

            this.eventArgsType = this.eventInfo.EventHandlerType == typeof(EventHandler)
                                     ? typeof(EventArgs)
                                     : this.eventInfo.EventHandlerType.GetGenericArguments()[0];

            Delegate handler = Delegate.CreateDelegate(
                this.eventInfo.EventHandlerType,
                this,
                GetType().GetMethod("PublicationHandler"));
            this.eventInfo.AddEventHandler(publisher, handler);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventPublicationAttribute"/> class.
 /// </summary>
 /// <param name="topic">The topic.</param>
 /// <param name="handlerRestriction">The handler restriction.</param>
 /// <param name="matcherTypes">The matcher types.</param>
 public EventPublicationAttribute(string topic, HandlerRestriction handlerRestriction, params Type[] matcherTypes)
 {
     this.topic = topic;
     this.handlerRestriction = handlerRestriction;
     if (matcherTypes != null && matcherTypes.Length > 0)
     {
         this.matcherTypes.AddRange(matcherTypes);
     }
 }
Ejemplo n.º 4
0
        /// <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="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public void Fire(string topic, object publisher, HandlerRestriction handlerRestriction, object sender, EventArgs e)
        {
            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            eventTopic.Fire(
                sender,
                e,
                new SpontaneousPublication(eventTopic, publisher, e.GetType(), handlerRestriction, new List <IPublicationMatcher>()));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventPublicationAttribute"/> class.
 /// </summary>
 /// <param name="topic">The topic.</param>
 /// <param name="handlerRestriction">The handler restriction.</param>
 /// <param name="matcherTypes">The matcher types.</param>
 public EventPublicationAttribute(string topic, HandlerRestriction handlerRestriction, params Type[] matcherTypes)
 {
     this.topic = topic;
     this.handlerRestriction = handlerRestriction;
     if (matcherTypes != null && matcherTypes.Length > 0)
     {
         this.matcherTypes.AddRange(matcherTypes);
     }
 }
 /// <summary>
 /// Creates a new publication.
 /// </summary>
 /// <typeparam name="TEventArgs">The type of the event arguments.</typeparam>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publisher">The publisher.</param>
 /// <param name="eventHandler">The event handler.</param>
 /// <param name="handlerRestriction">The handler restriction.</param>
 /// <param name="publicationMatchers">The matchers.</param>
 /// <returns>A newly created publication</returns>
 public virtual IPublication CreatePublication <TEventArgs>(
     IEventTopicExecuter eventTopic,
     object publisher,
     ref EventHandler <TEventArgs> eventHandler,
     HandlerRestriction handlerRestriction,
     IList <IPublicationMatcher> publicationMatchers) where TEventArgs : EventArgs
 {
     return(new CodePublication <TEventArgs>(eventTopic, publisher, ref eventHandler, handlerRestriction, publicationMatchers));
 }
 /// <summary>
 /// Creates a new publication
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publisher">The publisher.</param>
 /// <param name="eventInfo">The event info.</param>
 /// <param name="handlerRestriction">The handler restriction.</param>
 /// <param name="publicationMatchers">The publication matchers.</param>
 /// <returns>A newly created publication</returns>
 public virtual IPublication CreatePublication(
     IEventTopicExecuter eventTopic,
     object publisher,
     EventInfo eventInfo,
     HandlerRestriction handlerRestriction,
     IList <IPublicationMatcher> publicationMatchers)
 {
     return(new PropertyPublication(eventTopic, publisher, eventInfo, handlerRestriction, publicationMatchers));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new publication.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publisher">The publisher.</param>
 /// <param name="eventHandler">The event handler.</param>
 /// <param name="handlerRestriction">The handler restriction.</param>
 /// <param name="publicationMatchers">The matchers.</param>
 /// <returns>A newly created publication</returns>
 public virtual IPublication CreatePublication(
     IEventTopic eventTopic,
     object publisher,
     ref EventHandler eventHandler,
     HandlerRestriction handlerRestriction,
     IList <IPublicationMatcher> publicationMatchers)
 {
     return(new CodePublication <EventArgs>(eventTopic, publisher, ref eventHandler, handlerRestriction, publicationMatchers));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Registers the event as publication.
        /// </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>
        public void RegisterEvent(string topic, object publisher, string eventName, HandlerRestriction handlerRestriction, params IPublicationMatcher[] matchers)
        {
            if (publisher == null)
            {
                throw new ArgumentNullException("publisher", "publisher must not be null.");
            }

            this.eventInspector.ProcessPublisher(topic, publisher, eventName, handlerRestriction, matchers, true, this.eventTopicHost);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a publication to the topic.
        /// </summary>
        /// <typeparam name="TEventArgs">The type of the event arguments of the event handler.</typeparam>
        /// <param name="publisher">The object that publishes the event that will fire the topic.</param>
        /// <param name="eventHandler">The event handler that will fire the topic.</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="matchers">The matchers.</param>
        public void AddPublication <TEventArgs>(
            object publisher,
            ref EventHandler <TEventArgs> eventHandler,
            HandlerRestriction handlerRestriction,
            IList <IPublicationMatcher> matchers) where TEventArgs : EventArgs
        {
            IPublication publication = this.factory.CreatePublication(this, publisher, ref eventHandler, handlerRestriction, matchers);

            this.Clean();
            this.AddPublication(publication);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EventPublicationAttribute"/> class.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="matcherTypes">The matcher types.</param>
        public EventPublicationAttribute(string topic, HandlerRestriction handlerRestriction, params Type[] matcherTypes)
        {
            Ensure.ArgumentNotNullOrEmpty(topic, "topic");

            this.topic = topic;
            this.handlerRestriction = handlerRestriction;
            if (matcherTypes != null && matcherTypes.Length > 0)
            {
                this.matcherTypes.AddRange(matcherTypes);
            }
        }
Ejemplo n.º 12
0
 protected Publication(
     IEventTopicExecuter topic,
     object publisher,
     HandlerRestriction handlerRestriction,
     IList <IPublicationMatcher> publicationMatchers)
 {
     this.topic               = topic;
     this.publisher           = new WeakReference(publisher);
     this.handlerRestriction  = handlerRestriction;
     this.publicationMatchers = publicationMatchers;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="EventPublicationAttribute"/> class.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="matcherTypes">The matcher types.</param>
        public EventPublicationAttribute(string topic, HandlerRestriction handlerRestriction, params Type[] matcherTypes)
        {
            Guard.AgainstNullOrEmpty(nameof(topic), topic);

            this.topic = topic;
            this.handlerRestriction = handlerRestriction;
            if (matcherTypes != null && matcherTypes.Length > 0)
            {
                this.matcherTypes.AddRange(matcherTypes);
            }
        }
Ejemplo n.º 14
0
 protected Publication(
     IEventTopicExecuter topic,
     object publisher,
     HandlerRestriction handlerRestriction,
     IList<IPublicationMatcher> publicationMatchers)
 {
     this.topic = topic;
     this.publisher = new WeakReference(publisher);
     this.handlerRestriction = handlerRestriction;
     this.publicationMatchers = publicationMatchers;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="EventPublicationAttribute"/> class.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="matcherTypes">The matcher types.</param>
        public EventPublicationAttribute(string topic, HandlerRestriction handlerRestriction, params Type[] matcherTypes)
        {
            Ensure.ArgumentNotNullOrEmpty(topic, "topic");

            this.topic = topic;
            this.handlerRestriction = handlerRestriction;
            if (matcherTypes != null && matcherTypes.Length > 0)
            {
                this.matcherTypes.AddRange(matcherTypes);
            }
        }
 public PropertyPublicationScanResult(
     string topic,
     EventInfo @event,
     HandlerRestriction handlerRestriction,
     IEnumerable <Type> publicationMatcherTypes)
 {
     this.Topic = topic;
     this.Event = @event;
     this.HandlerRestriction      = handlerRestriction;
     this.PublicationMatcherTypes = publicationMatcherTypes;
 }
 public PropertyPublicationScanResult(
     string topic, 
     EventInfo @event, 
     HandlerRestriction handlerRestriction, 
     IEnumerable<Type> publicationMatcherTypes)
 {
     this.Topic = topic;
     this.Event = @event;
     this.HandlerRestriction = handlerRestriction;
     this.PublicationMatcherTypes = publicationMatcherTypes;
 }
Ejemplo n.º 18
0
        public CodePublication(
            IEventTopicExecuter topic,
            object publisher,
            ref EventHandler <TEventArgs> eventHandler,
            HandlerRestriction handlerRestriction,
            IList <IPublicationMatcher> publicationMatchers) :
            base(topic, publisher, handlerRestriction, publicationMatchers)
        {
            eventHandler += this.PublicationHandler;

            this.eventArgsType = eventHandler.GetType().GetGenericArguments()[0];
        }
Ejemplo n.º 19
0
        public CodePublication(
            IEventTopicExecuter topic,
            object publisher,
            ref EventHandler eventHandler,
            HandlerRestriction handlerRestriction,
            IList <IPublicationMatcher> publicationMatchers) :
            base(topic, publisher, handlerRestriction, publicationMatchers)
        {
            eventHandler += this.PublicationHandler;

            this.eventArgsType = typeof(EventArgs);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Adds a publication to the topic.
        /// </summary>
        /// <param name="publisher">The object that publishes the event that will fire the topic.</param>
        /// <param name="eventInfo">The <see cref="EventInfo"/> of the publisher that registers this event topic.</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="matchers">Matchers for publication.</param>
        public void AddPublication(
            object publisher,
            EventInfo eventInfo,
            HandlerRestriction handlerRestriction,
            IList <IPublicationMatcher> matchers)
        {
            IPublication publication = this.factory.CreatePublication(this, publisher, eventInfo, handlerRestriction, matchers);

            this.Clean();
            this.ThrowIfRepeatedPublication(publisher, eventInfo.Name);
            this.AddPublication(publication);
        }
Ejemplo n.º 21
0
        /// <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);
            }
        }
Ejemplo n.º 22
0
        /// <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);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Registers the event as publication.
        /// </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>
        public void AddPublication(string topic, object publisher, string eventName, HandlerRestriction handlerRestriction, params IPublicationMatcher[] matchers)
        {
            Ensure.ArgumentNotNull(publisher, "publisher");

            EventInfo eventInfo = this.eventInspector.ScanPublisherForEvent(publisher, eventName);

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

            IPublication publication = this.factory.CreatePublication(
                eventTopic,
                publisher,
                eventInfo,
                handlerRestriction,
                matchers);

            eventTopic.AddPublication(publication);
        }
Ejemplo n.º 24
0
        public void FiringEvent_MustAcquireMessageWithMessageFactory()
        {
            this.SetupManagedEventBroker();

            CancelEventArgs          cancelEventArgs    = new CancelEventArgs(true);
            const HandlerRestriction HandlerRestriction = HandlerRestriction.Asynchronous;
            const string             SimpleTopic        = "topic://Simple";
            const string             SerializedTopic    = "SomeData";

            var serializer     = this.GetSerializer();
            var messageFactory = this.GetMessageFactory();
            var message        = new Mock <IEventFired>();

            message.SetupAllProperties();

            var eventTopic = new Mock <IEventTopicInfo>();

            eventTopic.SetupGet(topic => topic.Uri).Returns(SimpleTopic);

            var publication = new Mock <IPublication>();

            publication.SetupGet(p => p.HandlerRestriction).Returns(HandlerRestriction);

            serializer.Setup(s => s.Serialize(It.IsAny <CancelEventArgs>())).Returns(SerializedTopic);

            messageFactory
            .Setup(f => f.CreateEventFiredMessage(It.IsAny <Action <IEventFired> >()))
            .Callback((Action <IEventFired> initialization) => initialization(message.Object))
            .Returns(message.Object);

            this.SetupTopicAcceptedByStrategy(eventTopic);

            this.testee.FiringEvent(eventTopic.Object, publication.Object, this, cancelEventArgs);

            Assert.Equal(HandlerRestriction, message.Object.HandlerRestriction);
            Assert.Equal(SimpleTopic, message.Object.Topic);
            Assert.Equal(SerializedTopic, message.Object.EventArgs);
            Assert.Equal(cancelEventArgs.GetType().AssemblyQualifiedName, message.Object.EventArgsType);
            Assert.Equal(this.testee.TestHostedEventBrokerIdentification, message.Object.EventBrokerIdentification);
            Assert.Equal(this.distributedEventBrokerIdentification, message.Object.DistributedEventBrokerIdentification);
        }
Ejemplo n.º 25
0
        public void HandleMessage_MustRefireEventOnHostedEventBroker()
        {
            const string             ExpectedTopic      = "topic://testtopic";
            const HandlerRestriction HandlerRestriction = HandlerRestriction.Asynchronous;
            CancelEventArgs          cancelEventArgs    = new CancelEventArgs(true);

            var serializer = this.GetSerializer();
            var eventFired = new Mock <IEventFired>();

            eventFired.SetupAllProperties();

            eventFired.Object.EventArgsType      = typeof(CancelEventArgs).AssemblyQualifiedName;
            eventFired.Object.Topic              = ExpectedTopic;
            eventFired.Object.HandlerRestriction = HandlerRestriction;

            serializer.Setup(s => s.Deserialize(typeof(CancelEventArgs), It.IsAny <string>())).Returns(cancelEventArgs);

            this.SetupManagedEventBroker();

            this.testee.TestHandleMessage(eventFired.Object);

            this.eventBroker.Verify(eb => eb.Fire(ExpectedTopic, this.testee, HandlerRestriction, this.testee, cancelEventArgs));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Adds a publication. Use this to register publications 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="publisher">The publisher.</param>
        /// <param name="publishedEvent">The published event.</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="matchers">The matchers.</param>
        public void AddPublication <TEventArgs>(string topic, object publisher, ref EventHandler <TEventArgs> publishedEvent, HandlerRestriction handlerRestriction, params IPublicationMatcher[] matchers) where TEventArgs : EventArgs
        {
            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            eventTopic.AddPublication(
                publisher,
                ref publishedEvent,
                handlerRestriction,
                matchers);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Adds a publication. Use this to register publications by code instead of using attributes.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="publisher">The publisher.</param>
        /// <param name="publishedEvent">The published event of the <paramref name="publisher"/>.</param>
        /// <param name="handlerRestriction">The handler restriction.</param>
        /// <param name="matchers">The matchers.</param>
        public void AddPublication(string topic, object publisher, ref EventHandler publishedEvent, HandlerRestriction handlerRestriction, params IPublicationMatcher[] matchers)
        {
            IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(topic);

            IPublication publication = this.factory.CreatePublication(eventTopic, publisher, ref publishedEvent, handlerRestriction, matchers);

            eventTopic.AddPublication(publication);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventPublicationAttribute"/> class.
 /// </summary>
 /// <param name="topic">The topic URI.</param>
 /// <param name="handlerRestriction">The handler restriction.</param>
 public EventPublicationAttribute(string topic, HandlerRestriction handlerRestriction)
     : this(topic, handlerRestriction, null)
 {
 }
Ejemplo n.º 29
0
 public SpontaneousPublication(IEventTopicExecuter topic, object publisher, Type eventArgsType, HandlerRestriction handlerRestriction, IList<IPublicationMatcher> publicationMatchers) :
     base(topic, publisher, handlerRestriction, publicationMatchers)
 {
     this.eventArgsType = eventArgsType;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventPublicationAttribute"/> class.
 /// </summary>
 /// <param name="topic">The topic URI.</param>
 /// <param name="handlerRestriction">The handler restriction.</param>
 public EventPublicationAttribute(string topic, HandlerRestriction handlerRestriction)
     : this(topic, handlerRestriction, null)
 {
 }
Ejemplo n.º 31
0
        /// <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(publisher, SpontaneousPublication.SpontaneousEventName);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SpontaneousPublication"/> class.
 /// </summary>
 /// <param name="topic">The topic.</param>
 /// <param name="publisher">The publisher.</param>
 /// <param name="eventArgsType">Type of the event args.</param>
 /// <param name="handlerRestriction">The handler restriction.</param>
 /// <param name="publicationMatchers">The publication matchers.</param>
 public SpontaneousPublication(IEventTopic topic, object publisher, Type eventArgsType, HandlerRestriction handlerRestriction, IList <IPublicationMatcher> publicationMatchers) :
     base(topic, publisher, handlerRestriction, publicationMatchers)
 {
     this.eventArgsType = eventArgsType;
 }
Ejemplo n.º 33
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);
            }
        }