/// <summary>
 /// Called when the event was fired (processing completed).
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public override void FiredEvent(IEventTopicInfo eventTopic, IPublication publication, object sender, EventArgs e)
 {
     INamedItem namedItem = publication.Publisher as INamedItem;
     if (namedItem != null)
     {
         this.log.DebugFormat(
             CultureInfo.InvariantCulture,
             "Fired event '{0}'. Invoked by publisher '{1}' with name '{2}' with sender '{3}' and EventArgs '{4}'.",
             eventTopic.Uri,
             publication.Publisher,
             namedItem.EventBrokerItemName,
             sender,
             e);
     }
     else
     {
         this.log.DebugFormat(
             CultureInfo.InvariantCulture,
             "Fired event '{0}'. Invoked by publisher '{1}' with sender '{2}' and EventArgs '{3}'.",
             eventTopic.Uri,
             publication.Publisher,
             sender,
             e);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MissingMappingContext"/> class.
 /// </summary>
 /// <param name="eventTopic">The source event topic.</param>
 /// <param name="destinationTopic">The destination topic URI.</param>
 /// <param name="publication">The publication which triggered the event.</param>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="eventArgs">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 /// <param name="exception">The exception which contains information why the mapping was not possible.</param>
 public MissingMappingContext(IEventTopicInfo eventTopic, string destinationTopic, IPublication publication, object sender, EventArgs eventArgs, Exception exception)
 {
     this.Exception = exception;
     this.EventArgs = eventArgs;
     this.Sender = sender;
     this.Publication = publication;
     this.DestinationTopic = destinationTopic;
     this.EventTopic = eventTopic;
 }
Exemplo n.º 3
0
 public override void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper)
 {
     if (this.RunningOnUserInterfaceThread())
     {
         this.CallWithoutThreadSwitch(eventTopic, subscriber, delegateWrapper, sender, e);
     }
     else
     {
         this.CallWithThreadSwitch(eventTopic, subscriber, delegateWrapper, sender, e);
     }
 }
Exemplo n.º 4
0
 private void CallWithoutThreadSwitch(IEventTopicInfo eventTopic, object subscriber, IDelegateWrapper delegateWrapper, object sender, EventArgs e)
 {
     try
     {
         delegateWrapper.Invoke(subscriber, sender, e);
     }
     catch (TargetInvocationException exception)
     {
         this.HandleSubscriberMethodException(exception, eventTopic);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Called after the event was relayed from the publication to the subscribers.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 /// <param name="subscription">The subscription.</param>
 /// <param name="handler">The handler.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public override void RelayedEvent(IEventTopicInfo eventTopic, IPublication publication, ISubscription subscription, IHandler handler, object sender, EventArgs e)
 {
     Debug.WriteLine(
         "Relayed event '{6}' from publisher '{0}' [{1}] to subscriber '{2}' [{3}] with EventArgs '{4}' with handler '{5}'.",
         publication.Publisher,
         publication.Publisher is INamedItem ? ((INamedItem)publication.Publisher).EventBrokerItemName : string.Empty,
         subscription.Subscriber,
         subscription.Subscriber is INamedItem ? ((INamedItem)subscription.Subscriber).EventBrokerItemName : string.Empty,
         e,
         handler,
         eventTopic.Uri);
 }
Exemplo n.º 6
0
        public void IsCandidate_MustExecuteCandidateSelector()
        {
            bool            wasCalled   = false;
            IEventTopicInfo topicResult = null;

            var testee = CreateTestee(topic => { wasCalled = true; topicResult = topic; return(true); }, from => string.Empty);

            testee.IsCandidate(this.eventTopicInfo.Object);

            Assert.True(wasCalled, "CandidateSelector was not called!");
            Assert.Same(this.eventTopicInfo.Object, topicResult);
        }
        public EventBrokerLogExtensionTest()
        {
            this.testee = new EventBrokerLogExtension();

            this.log4Net = new Log4netHelper();

            this.eventTopicInfo = CreateEventTopicInfo();
            this.publication = CreatePublication();
            this.publicationWithNamedPublisher = CreatePublicationWithNamedPublisher();
            this.sender = CreateSender();
            this.eventArgs = CreateEventArgs();
        }
Exemplo n.º 8
0
        private void EventTopicFireHandler(IEventTopicInfo eventTopic, object sender, EventArgs e, IPublication publication)
        {
            if (this.Subscriber == null)
            {
                return;
            }

            this.extensionHost.ForEach(extension => extension.RelayingEvent(eventTopic, publication, this, this.handler, sender, e));

            this.handler.Handle(eventTopic, this.Subscriber, sender, e, this.delegateWrapper);

            this.extensionHost.ForEach(extension => extension.RelayedEvent(eventTopic, publication, this, this.handler, sender, e));
        }
Exemplo n.º 9
0
        public override void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper)
        {
            Ensure.ArgumentNotNull(delegateWrapper, "delegateWrapper");

            try
            {
                delegateWrapper.Invoke(subscriber, sender, e);
            }
            catch (TargetInvocationException ex)
            {
                this.HandleSubscriberMethodException(ex, eventTopic);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Called before an event is relayed from the publication to the subscribers.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 /// <param name="subscription">The subscription.</param>
 /// <param name="handler">The handler.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public override void RelayingEvent(IEventTopicInfo eventTopic, IPublication publication, ISubscription subscription, IHandler handler, object sender, EventArgs e)
 {
     this.log.DebugFormat(
         CultureInfo.InvariantCulture,
         "Relaying event '{6}' from publisher '{0}' [{1}] to subscriber '{2}' [{3}] with EventArgs '{4}' with handler '{5}'.",
         publication.Publisher,
         publication.Publisher is INamedItem ? ((INamedItem)publication.Publisher).EventBrokerItemName : string.Empty,
         subscription.Subscriber,
         subscription.Subscriber is INamedItem ? ((INamedItem)subscription.Subscriber).EventBrokerItemName : string.Empty,
         e,
         handler,
         eventTopic.Uri);
 }
Exemplo n.º 11
0
        public override void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper)
        {
            Guard.AgainstNullArgument(nameof(delegateWrapper), delegateWrapper);

            try
            {
                delegateWrapper.Invoke(subscriber, sender, e);
            }
            catch (TargetInvocationException ex)
            {
                this.HandleSubscriberMethodException(ex, eventTopic);
            }
        }
Exemplo n.º 12
0
        public void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper)
        {
            IEventScopeRegistry registry = this.scopeHolder.Current;

            if (registry != null)
            {
                registry.Register(() => this.handler.Handle(eventTopic, subscriber, sender, e, delegateWrapper));
            }
            else
            {
                this.handler.Handle(eventTopic, subscriber, sender, e, delegateWrapper);
            }
        }
Exemplo n.º 13
0
        public override void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper)
        {
            Ensure.ArgumentNotNull(delegateWrapper, "delegateWrapper");

            try
            {
                delegateWrapper.Invoke(subscriber, sender, e);
            }
            catch (TargetInvocationException ex)
            {
                this.HandleSubscriberMethodException(ex, eventTopic);
            }
        }
        public void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper)
        {
            IEventScopeRegistry registry = this.scopeHolder.Current;

            if (registry != null)
            {
                registry.Register(() => this.handler.Handle(eventTopic, subscriber, sender, e, delegateWrapper));
            }
            else
            {
                this.handler.Handle(eventTopic, subscriber, sender, e, delegateWrapper);
            }
        }
        /// <summary>
        /// Called after an event topic was disposed.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        public override void Disposed(IEventTopicInfo eventTopic)
        {
            base.Disposed(eventTopic);

            if (!this.Topics.Contains(eventTopic))
            {
                return;
            }

            lock (this.locker)
            {
                this.Topics.Remove(eventTopic);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Called after an event topic was disposed.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        public override void Disposed(IEventTopicInfo eventTopic)
        {
            base.Disposed(eventTopic);

            Ensure.ArgumentNotNull(eventTopic, "eventTopic");

            lock (this.locker)
            {
                string uri = eventTopic.Uri;

                if (this.topics.Contains(uri))
                {
                    this.topics.Remove(uri);
                }
            }
        }
        /// <summary>
        /// Called after an event topic was created.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        public override void CreatedTopic(IEventTopicInfo eventTopic)
        {
            base.CreatedTopic(eventTopic);

            this.AssertEventBrokerManaged();

            if (!this.TopicConvention.IsCandidate(eventTopic))
            {
                return;
            }

            lock (this.locker)
            {
                this.Topics.Add(eventTopic);
            }
        }
Exemplo n.º 18
0
 public override void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper)
 {
     this.syncContextHolder.SyncContext.Post(
         delegate(object data)
             {
                 try
                 {
                     ((IDelegateWrapper)data).Invoke(subscriber, sender, e);
                 }
                 catch (TargetInvocationException exception)
                 {
                     this.HandleSubscriberMethodException(exception, eventTopic);
                 }
             }, 
             delegateWrapper);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Handles a subscriber method exception by passing it to all extensions and re-throwing the inner exception in case that none of the
        /// extensions handled it.
        /// </summary>
        /// <param name="targetInvocationException">The targetInvocationException.</param>
        /// <param name="eventTopic">The event topic.</param>
        protected void HandleSubscriberMethodException(TargetInvocationException targetInvocationException, IEventTopicInfo eventTopic)
        {
            Ensure.ArgumentNotNull(targetInvocationException, "targetInvocationException");

            var innerException = targetInvocationException.InnerException;
            innerException.PreserveStackTrace();

            var context = new ExceptionHandlingContext();

            this.ExtensionHost.ForEach(extension => extension.SubscriberExceptionOccurred(eventTopic, innerException, context));
                
            if (!context.Handled)
            {
                throw innerException;
            }
        }
Exemplo n.º 20
0
 private void CallWithThreadSwitch(IEventTopicInfo eventTopic, object subscriber, IDelegateWrapper delegateWrapper, object sender, EventArgs e)
 {
     this.syncContextHolder.SyncContext.Send(
         delegate(object data)
     {
         try
         {
             ((IDelegateWrapper)data).Invoke(subscriber, sender, e);
         }
         catch (TargetInvocationException exception)
         {
             this.HandleSubscriberMethodException(exception, eventTopic);
         }
     },
         delegateWrapper);
 }
Exemplo n.º 21
0
 public override void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper)
 {
     this.syncContextHolder.SyncContext.Post(
         delegate(object data)
     {
         try
         {
             ((IDelegateWrapper)data).Invoke(subscriber, sender, e);
         }
         catch (TargetInvocationException exception)
         {
             this.HandleSubscriberMethodException(exception, eventTopic);
         }
     },
         delegateWrapper);
 }
Exemplo n.º 22
0
 public override void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper)
 {
     ThreadPool.QueueUserWorkItem(
         delegate(object state)
     {
         try
         {
             var args = (CallInBackgroundArguments)state;
             args.DelegateWrapper.Invoke(args.Subscriber, args.Sender, args.EventArgs);
         }
         catch (TargetInvocationException exception)
         {
             this.HandleSubscriberMethodException(exception, eventTopic);
         }
     },
         new CallInBackgroundArguments(subscriber, sender, e, delegateWrapper));
 }
Exemplo n.º 23
0
 public override void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper)
 {
     ThreadPool.QueueUserWorkItem(
         delegate(object state)
             {
                 try
                 {
                     var args = (CallInBackgroundArguments)state;
                     args.DelegateWrapper.Invoke(args.Subscriber, args.Sender, args.EventArgs);
                 }
                 catch (TargetInvocationException exception)
                 {
                     this.HandleSubscriberMethodException(exception, eventTopic);
                 }
             },
         new CallInBackgroundArguments(subscriber, sender, e, delegateWrapper));
 }
Exemplo n.º 24
0
        /// <summary>
        /// Called after a subscription was added to an event topic.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        /// <param name="subscription">The subscription.</param>
        public override void AddedSubscription(IEventTopicInfo eventTopic, ISubscription subscription)
        {
            using (TextWriter writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                foreach (ISubscriptionMatcher subscriptionMatcher in subscription.SubscriptionMatchers)
                {
                    subscriptionMatcher.DescribeTo(writer);
                    writer.Write(", ");
                }

                Debug.WriteLine(
                    "Added subscription '{0}.{1}' to topic '{2}' with matchers '{3}'.",
                    subscription.Subscriber != null ? subscription.Subscriber.GetType().FullName : "-",
                    subscription.HandlerMethodName,
                    eventTopic.Uri,
                    writer);
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Called after a publication was added to an event topic.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        /// <param name="publication">The publication.</param>
        public override void AddedPublication(IEventTopicInfo eventTopic, IPublication publication)
        {
            using (TextWriter writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                foreach (IPublicationMatcher publicationMatcher in publication.PublicationMatchers)
                {
                    publicationMatcher.DescribeTo(writer);
                    writer.Write(", ");
                }

                Debug.WriteLine(
                    "Added publication '{0}.{1}' to topic '{2}' with matchers '{3}'.",
                    publication.Publisher != null ? publication.Publisher.GetType().FullName : "-",
                    publication.EventName,
                    eventTopic.Uri,
                    writer);
            }
        }
        /// <summary>
        /// Called after a subscription was added to an event topic.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        /// <param name="subscription">The subscription.</param>
        public override void AddedSubscription(IEventTopicInfo eventTopic, ISubscription subscription)
        {
            using (TextWriter writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                foreach (ISubscriptionMatcher subscriptionMatcher in subscription.SubscriptionMatchers)
                {
                    subscriptionMatcher.DescribeTo(writer);
                    writer.Write(", ");
                }

                Console.WriteLine(
                    "Added subscription '{0}.{1}' to topic '{2}' with matchers '{3}'.",
                    subscription.Subscriber != null ? subscription.Subscriber.GetType().FullName : "-",
                    subscription.HandlerMethodName,
                    eventTopic.Uri,
                    writer);
            }
        }
        /// <summary>
        /// Called after a publication was added to an event topic.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        /// <param name="publication">The publication.</param>
        public override void AddedPublication(IEventTopicInfo eventTopic, IPublication publication)
        {
            using (TextWriter writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                foreach (IPublicationMatcher publicationMatcher in publication.PublicationMatchers)
                {
                    publicationMatcher.DescribeTo(writer);
                    writer.Write(", ");
                }

                Console.WriteLine(
                    "Added publication '{0}.{1}' to topic '{2}' with matchers '{3}'.",
                    publication.Publisher != null ? publication.Publisher.GetType().FullName : "-",
                    publication.EventName,
                    eventTopic.Uri,
                    writer);
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// Called when the event was fired (processing completed).
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public override void FiredEvent(IEventTopicInfo eventTopic, IPublication publication, object sender, EventArgs e)
 {
     INamedItem namedItem = publication.Publisher as INamedItem;
     if (namedItem != null)
     {
         Debug.WriteLine(
             "Fired event '{0}'. Invoked by publisher '{1}' with name '{2}' with sender '{3}' and EventArgs '{4}'.",
             eventTopic.Uri,
             publication.Publisher,
             namedItem.EventBrokerItemName,
             sender,
             e);
     }
     else
     {
         Debug.WriteLine(
             "Fired event '{0}'. Invoked by publisher '{1}' with sender '{2}' and EventArgs '{3}'.",
             eventTopic.Uri,
             publication.Publisher,
             sender,
             e);
     }
 }
Exemplo n.º 29
0
        /// <summary>
        /// Called when a publication or subscription matcher did not match and the event was not relayed to a subscription.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        /// <param name="publication">The publication.</param>
        /// <param name="subscription">The subscription.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void SkippedEvent(IEventTopicInfo eventTopic, IPublication publication, ISubscription subscription, object sender, EventArgs e)
        {
            List <IMatcher> matchers = new List <IMatcher>();

            var publicationMatchers  = from matcher in publication.PublicationMatchers where !matcher.Match(publication, subscription, e) select matcher;
            var subscriptionMatchers = from matcher in subscription.SubscriptionMatchers where !matcher.Match(publication, subscription, e) select matcher;

            matchers.AddRange(publicationMatchers);
            matchers.AddRange(subscriptionMatchers);

            StringBuilder sb = new StringBuilder();

            using (TextWriter writer = new StringWriter(sb, CultureInfo.InvariantCulture))
            {
                foreach (IMatcher matcher in matchers)
                {
                    matcher.DescribeTo(writer);
                    writer.Write(", ");
                }
            }

            if (sb.Length > 0)
            {
                sb.Length -= 2;
            }

            this.log.DebugFormat(
                CultureInfo.InvariantCulture,
                "Skipped event '{0}' from publisher '{1}' [{2}] to subscriber '{3}' [{4}] with EventArgs '{5}' because the matchers '{6}' did not match.",
                eventTopic.Uri,
                publication.Publisher,
                publication.Publisher is INamedItem ? ((INamedItem)publication.Publisher).EventBrokerItemName : string.Empty,
                subscription.Subscriber,
                subscription.Subscriber is INamedItem ? ((INamedItem)subscription.Subscriber).EventBrokerItemName : string.Empty,
                e,
                sb);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Called when the event was fired (processing completed).
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        /// <param name="publication">The publication.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void FiredEvent(IEventTopicInfo eventTopic, IPublication publication, object sender, EventArgs e)
        {
            INamedItem namedItem = publication.Publisher as INamedItem;

            if (namedItem != null)
            {
                Debug.WriteLine(
                    "Fired event '{0}'. Invoked by publisher '{1}' with name '{2}' with sender '{3}' and EventArgs '{4}'.",
                    eventTopic.Uri,
                    publication.Publisher,
                    namedItem.EventBrokerItemName,
                    sender,
                    e);
            }
            else
            {
                Debug.WriteLine(
                    "Fired event '{0}'. Invoked by publisher '{1}' with sender '{2}' and EventArgs '{3}'.",
                    eventTopic.Uri,
                    publication.Publisher,
                    sender,
                    e);
            }
        }
 public override void SubscriberExceptionOccurred(IEventTopicInfo eventTopic, Exception exception, ExceptionHandlingContext context)
 {
     context.SetHandled();
 }
Exemplo n.º 32
0
 /// <summary>
 /// Determines whether the specified event topic is a candidate to process.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <returns>
 /// <c>true</c> if the specified event topic is candidate; otherwise, <c>false</c>.
 /// </returns>
 public bool IsCandidate(IEventTopicInfo eventTopic)
 {
     return StartsWith(eventTopic, EventTopicUriInput);
 }
Exemplo n.º 33
0
 /// <summary>
 /// Called when an exception occurred during event handling by a subscriber.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="exception">The exception.</param>
 /// <param name="context">The context providing information whether the exception is handled by an extension or is re-thrown.</param>
 public override void SubscriberExceptionOccurred(IEventTopicInfo eventTopic, Exception exception, ExceptionHandlingContext context)
 {
     this.log.Error(
         string.Format("An exception was thrown during handling the topic '{0}'", eventTopic.Uri),
         exception);
 }
Exemplo n.º 34
0
 /// <summary>
 /// Called after the event was relayed from the publication to the subscribers.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 /// <param name="subscription">The subscription.</param>
 /// <param name="handler">The handler.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public override void RelayedEvent(IEventTopicInfo eventTopic, IPublication publication, ISubscription subscription, IHandler handler, object sender, EventArgs e)
 {
     this.log.DebugFormat(
         "Relayed event '{6}' from publisher '{0}' [{1}] to subscriber '{2}' [{3}] with EventArgs '{4}' with handler '{5}'.",
         publication.Publisher,
         publication.Publisher is INamedItem ? ((INamedItem)publication.Publisher).EventBrokerItemName : string.Empty,
         subscription.Subscriber,
         subscription.Subscriber is INamedItem ? ((INamedItem)subscription.Subscriber).EventBrokerItemName : string.Empty,
         e,
         handler,
         eventTopic.Uri);
 }
Exemplo n.º 35
0
 /// <summary>
 /// Called after a publication was removed from an event topic.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 public override void RemovedPublication(IEventTopicInfo eventTopic, IPublication publication)
 {
     this.log.DebugFormat(
             "Removed publication '{0}.{1}' from topic '{2}'.",
             publication.Publisher != null ? publication.Publisher.GetType().FullName : "-",
             publication.EventName,
             eventTopic.Uri);
 }
Exemplo n.º 36
0
 /// <summary>
 /// Called when an event is fired.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public override void FiringEvent(IEventTopicInfo eventTopic, IPublication publication, object sender, EventArgs e)
 {
     this.log.DebugFormat(
         "Firing event '{0}'. Invoked by publisher '{1}' with EventArgs '{2}'.",
         eventTopic.Uri,
         sender,
         e);
 }
Exemplo n.º 37
0
 /// <summary>
 /// Called after a publication was created.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 public override void CreatedPublication(IEventTopicInfo eventTopic, IPublication publication)
 {
 }
Exemplo n.º 38
0
 /// <summary>
 /// Called after a publication was removed from an event topic.
 /// </summary>
 /// <param name="eventTopic">The event topic. Null if removed by code.</param>
 /// <param name="publication">The publication.</param>
 public virtual void RemovedPublication(IEventTopicInfo eventTopic, IPublication publication)
 {
 }
Exemplo n.º 39
0
 public abstract void Handle(IEventTopicInfo eventTopic, object subscriber, object sender, EventArgs e, IDelegateWrapper delegateWrapper);
        public override void FiringEvent(IEventTopicInfo eventTopic, IPublication publication, object sender, EventArgs e)
        {
            base.FiringEvent(eventTopic, publication, sender, e);

            this.interceptedPublication = publication;
        }
        /// <summary>
        /// Called after an event topic was disposed.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        public override void Disposed(IEventTopicInfo eventTopic)
        {
            base.Disposed(eventTopic);

            Ensure.ArgumentNotNull(eventTopic, "eventTopic");

            lock (this.locker)
            {
                string uri = eventTopic.Uri;

                if (this.topics.Contains(uri))
                {
                    this.topics.Remove(uri);
                }
            }
        }
        /// <summary>
        /// Called after an event topic was created.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        public override void CreatedTopic(IEventTopicInfo eventTopic)
        {
            base.CreatedTopic(eventTopic);

            Ensure.ArgumentNotNull(eventTopic, "eventTopic");

            if (!this.SelectionStrategy.SelectTopic(eventTopic))
            {
                return;
            }

            var publicationsWithNotAllowedRestrictions = eventTopic.Publications.Where(p => p.HandlerRestriction != HandlerRestriction.Asynchronous).ToList();

            if (publicationsWithNotAllowedRestrictions.Any())
            {
                string message = BuildPublicationsWithNotAllowedHandlerRestrictionsMessage(publicationsWithNotAllowedRestrictions);

                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Only asynchronous handling of events is allowed! The wrong publications are: {0}", message));
            }

            lock (this.locker)
            {
                this.topics.Add(eventTopic.Uri);
            }
        }
Exemplo n.º 43
0
 /// <summary>
 /// Called after a subscription was created.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="subscription">The subscription.</param>
 public virtual void CreatedSubscription(IEventTopicInfo eventTopic, ISubscription subscription)
 {
 }
Exemplo n.º 44
0
 /// <summary>
 /// Called after an event topic was disposed.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 public virtual void Disposed(IEventTopicInfo eventTopic)
 {
 }
Exemplo n.º 45
0
 /// <summary>
 /// Called after an event topic was created.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 public override void CreatedTopic(IEventTopicInfo eventTopic)
 {
     this.log.DebugFormat("Topic created: '{0}'.", eventTopic.Uri);
 }
Exemplo n.º 46
0
 /// <summary>
 /// Called when an exception occurred during event handling by a subscriber.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="exception">The exception.</param>
 /// <param name="context">The context providing information whether the exception is handled by an extension or is re-thrown.</param>
 public virtual void SubscriberExceptionOccurred(IEventTopicInfo eventTopic, Exception exception, ExceptionHandlingContext context)
 {
 }
Exemplo n.º 47
0
 /// <summary>
 /// Called after a subscription was created.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="subscription">The subscription.</param>
 public override void CreatedSubscription(IEventTopicInfo eventTopic, ISubscription subscription)
 {
 }
Exemplo n.º 48
0
 /// <summary>
 /// Called after the event was relayed from the publication to the subscribers.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 /// <param name="subscription">The subscription.</param>
 /// <param name="handler">The handler.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public virtual void RelayedEvent(IEventTopicInfo eventTopic, IPublication publication, ISubscription subscription, IHandler handler, object sender, EventArgs e)
 {
 }
Exemplo n.º 49
0
        /// <summary>
        /// Called after a publication was added to an event topic.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        /// <param name="publication">The publication.</param>
        public override void AddedPublication(IEventTopicInfo eventTopic, IPublication publication)
        {
            using (TextWriter writer = new StringWriter())
            {
                foreach (IPublicationMatcher publicationMatcher in publication.PublicationMatchers)
                {
                    publicationMatcher.DescribeTo(writer);
                    writer.Write(", ");
                }

                this.log.DebugFormat(
                    "Added publication '{0}.{1}' to topic '{2}' with matchers '{3}'.",
                    publication.Publisher != null ? publication.Publisher.GetType().FullName : "-",
                    publication.EventName,
                    eventTopic.Uri,
                    writer);
            }
        }
Exemplo n.º 50
0
 /// <summary>
 /// Called when a publication or subscription matcher did not match and the event was not relayed to a subscription.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 /// <param name="subscription">The subscription.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public virtual void SkippedEvent(IEventTopicInfo eventTopic, IPublication publication, ISubscription subscription, object sender, EventArgs e)
 {
 }
Exemplo n.º 51
0
 /// <summary>
 /// Called after a subscription was removed from an event topic.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="subscription">The subscription.</param>
 public override void RemovedSubscription(IEventTopicInfo eventTopic, ISubscription subscription)
 {
     this.log.DebugFormat(
             "Removed subscription '{0}.{1}' from topic '{2}'.",
             subscription.Subscriber != null ? subscription.Subscriber.GetType().FullName : "-",
             subscription.HandlerMethodName,
             eventTopic.Uri);
 }
Exemplo n.º 52
0
 /// <summary>
 /// Called when the event was fired (processing completed).
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public virtual void FiredEvent(IEventTopicInfo eventTopic, IPublication publication, object sender, EventArgs e)
 {
 }
Exemplo n.º 53
0
        /// <summary>
        /// Called when a publication or subscription matcher did not match and the event was not relayed to a subscription.
        /// </summary>
        /// <param name="eventTopic">The event topic.</param>
        /// <param name="publication">The publication.</param>
        /// <param name="subscription">The subscription.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void SkippedEvent(IEventTopicInfo eventTopic, IPublication publication, ISubscription subscription, object sender, EventArgs e)
        {
            List<IMatcher> matchers = new List<IMatcher>();
            
            var publicationMatchers = from matcher in publication.PublicationMatchers where !matcher.Match(publication, subscription, e) select matcher;
            var subscriptionMatchers = from matcher in subscription.SubscriptionMatchers where !matcher.Match(publication, subscription, e) select matcher;
            matchers.AddRange(publicationMatchers);
            matchers.AddRange(subscriptionMatchers);
            
            StringBuilder sb = new StringBuilder();
            using (TextWriter writer = new StringWriter(sb))
            {
                foreach (IMatcher matcher in matchers)
                {
                    matcher.DescribeTo(writer);
                    writer.Write(", ");
                }
            }

            if (sb.Length > 0)
            {
                sb.Length -= 2;
            }

            this.log.DebugFormat(
                "Skipped event '{0}' from publisher '{1}' [{2}] to subscriber '{3}' [{4}] with EventArgs '{5}' because the matchers '{6}' did not match.",
                eventTopic.Uri,
                publication.Publisher,
                publication.Publisher is INamedItem ? ((INamedItem)publication.Publisher).EventBrokerItemName : string.Empty,
                subscription.Subscriber,
                subscription.Subscriber is INamedItem ? ((INamedItem)subscription.Subscriber).EventBrokerItemName : string.Empty,
                e,
                sb);
        }
Exemplo n.º 54
0
 /// <summary>
 /// Called after an event topic was created.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 public virtual void CreatedTopic(IEventTopicInfo eventTopic)
 {
 }
Exemplo n.º 55
0
 /// <summary>
 /// Determines whether the topics URI starts with start.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="start">The start of the topic.</param>
 /// <returns><see langword="true"/> if the topic URI starts with start;
 /// otherwise <see langword="false"/>.</returns>
 private static bool StartsWith(IEventTopicInfo eventTopic, string start)
 {
     return eventTopic.Uri.StartsWith(start, StringComparison.Ordinal);
 }
Exemplo n.º 56
0
 /// <summary>
 /// Called after a publication was created.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <param name="publication">The publication.</param>
 public virtual void CreatedPublication(IEventTopicInfo eventTopic, IPublication publication)
 {
 }
Exemplo n.º 57
0
        /// <summary>
        /// Handles a subscriber method exception by passing it to all extensions and re-throwing the inner exception in case that none of the
        /// extensions handled it.
        /// </summary>
        /// <param name="targetInvocationException">The targetInvocationException.</param>
        /// <param name="eventTopic">The event topic.</param>
        protected void HandleSubscriberMethodException(TargetInvocationException targetInvocationException, IEventTopicInfo eventTopic)
        {
            Ensure.ArgumentNotNull(targetInvocationException, "targetInvocationException");

            var innerException = targetInvocationException.InnerException;

            innerException.PreserveStackTrace();

            var context = new ExceptionHandlingContext();

            this.ExtensionHost.ForEach(extension => extension.SubscriberExceptionOccurred(eventTopic, innerException, context));

            if (!context.Handled)
            {
                throw innerException;
            }
        }
Exemplo n.º 58
0
 /// <summary>
 /// Determines whether the specified event topic is a candidate to process.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <returns>
 /// <c>true</c> if the specified event topic is candidate; otherwise, <c>false</c>.
 /// </returns>
 public bool IsCandidate(IEventTopicInfo eventTopic)
 {
     return(StartsWith(eventTopic, EventTopicUriInput));
 }
 /// <summary>
 /// Determines whether the specified event topic is a candidate to process.
 /// </summary>
 /// <param name="eventTopic">The event topic.</param>
 /// <returns>
 /// <c>true</c> if the specified event topic is candidate; otherwise, <c>false</c>.
 /// </returns>
 /// <remarks>The mapped side must also be included!</remarks>
 public bool IsCandidate(IEventTopicInfo eventTopic)
 {
     return this.candidateSelector(eventTopic);
 }
Exemplo n.º 60
0
 public override void SubscriberExceptionOccurred(IEventTopicInfo eventTopic, Exception exception, ExceptionHandlingContext context)
 {
     context.SetHandled();
 }