Esempio n. 1
0
        /// <summary>
        /// Occurs when the message dispatcher has finished dispatching the message.
        /// </summary>
        /// <param name="e">The event data.</param>
        protected virtual void OnDispatched(MessageDispatchEventArgs e)
        {
            var temp = this.Dispatched;

            if (temp != null)
            {
                temp(this, e);
            }
        }
Esempio n. 2
0
        public virtual void DispatchMessage <T>(T message)
        {
            Type messageType = typeof(T);

            if (_handlers.ContainsKey(messageType))
            {
                var messageHandlers = _handlers[messageType];
                foreach (var messageHandler in messageHandlers)
                {
                    var dynMessageHandler = (IHandler <T>)messageHandler;
                    var eventArgs         = new MessageDispatchEventArgs(message, messageHandler.GetType(), messageHandler);
                    this.OnDispatching(eventArgs);
                    try
                    {
                        dynMessageHandler.Handle(message);
                        this.OnDispatched(eventArgs);
                    }
                    catch
                    {
                        this.OnDispatchFailed(eventArgs);
                    }
                }
            }
        }