Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Publication"/> class
        /// </summary>
        public Publication(EventTopic topic, object publisher, string eventName, WorkItem workItem, PublicationScope scope)
        {
            this.topic = topic;
            this.wrPublisher = new WeakReference(publisher);
            this.scope = scope;
            this.eventName = eventName;
            this.wrWorkItem = new WeakReference(workItem);

            EventInfo publishedEvent =
                publisher.GetType().GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

            if (publishedEvent == null)
            {
                throw new EventBrokerException(String.Format(CultureInfo.CurrentCulture,
                    Properties.Resources.CannotFindPublishedEvent, eventName));
            }

            ThrowIfInvalidEventHandler(publishedEvent);
            ThrowIfEventIsStatic(publishedEvent);

            Delegate handler = Delegate.CreateDelegate(publishedEvent.EventHandlerType, this, this.GetType().GetMethod("PublicationHandler"));
            publishedEvent.AddEventHandler(publisher, handler);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Publication"/> class
        /// </summary>
        public Publication(EventTopic topic, object publisher, string eventName, WorkItem workItem, PublicationScope scope)
        {
            this.topic       = topic;
            this.wrPublisher = new WeakReference(publisher);
            this.scope       = scope;
            this.eventName   = eventName;
            this.wrWorkItem  = new WeakReference(workItem);

            EventInfo publishedEvent =
                publisher.GetType().GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

            if (publishedEvent == null)
            {
                throw new EventBrokerException(String.Format(CultureInfo.CurrentCulture,
                                                             Properties.Resources.CannotFindPublishedEvent, eventName));
            }

            ThrowIfInvalidEventHandler(publishedEvent);
            ThrowIfEventIsStatic(publishedEvent);

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

            publishedEvent.AddEventHandler(publisher, handler);
        }
 /// <summary>
 /// Initializes a new instance with the specified list of exceptions.
 /// </summary>
 /// <param name="exceptions">The list of exceptions that occurred during the subscribers invocation.</param>
 /// <param name="topic">The <see cref="EventTopic"/> instance whose subscribers incurred into an exception.</param>
 public EventTopicException(EventTopic topic, ReadOnlyCollection <Exception> exceptions)
     : base(String.Format(CultureInfo.CurrentCulture, Resources.EventTopicFireException, topic.Name))
 {
     this.topic      = topic;
     this.exceptions = exceptions;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance with the specified list of exceptions.
 /// </summary>
 /// <param name="exceptions">The list of exceptions that occurred during the subscribers invocation.</param>
 /// <param name="topic">The <see cref="EventTopic"/> instance whose subscribers incurred into an exception.</param>
 public EventTopicException(EventTopic topic, ReadOnlyCollection<Exception> exceptions)
     : base(String.Format(CultureInfo.CurrentCulture, Resources.EventTopicFireException, topic.Name))
 {
     this.topic = topic;
     this.exceptions = exceptions;
 }