/// <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); IPublication publication = this.factory.CreatePublication(eventTopic, publisher, ref publishedEvent, handlerRestriction, matchers); eventTopic.AddPublication(publication); }
/// <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); } }
/// <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); eventTopic.AddPublication( publisher, ref publishedEvent, handlerRestriction, matchers); }
/// <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); } }
/// <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); }
private void RegisterPropertyPublications(object item, ScanResult scanResult) { foreach (PropertyPublicationScanResult propertyPublication in scanResult.Publications) { var publicationMatchers = from publicationMatcherType in propertyPublication.PublicationMatcherTypes select this.factory.CreatePublicationMatcher(publicationMatcherType); IEventTopic eventTopic = this.eventTopicHost.GetEventTopic(propertyPublication.Topic); IPublication publication = this.factory.CreatePublication( eventTopic, item, propertyPublication.Event, propertyPublication.HandlerRestriction, publicationMatchers.ToList()); eventTopic.AddPublication(publication); } }
/// <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); } }