Ejemplo n.º 1
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            var msg = message as DispatchCommand;

            if (msg != null)
            {
                try
                {
                    _method.MakeGenericMethod(msg.Command.GetType()).Invoke(this, new object[] { msg.Command });
                    context.SendUpstream(new CommandCompleted(msg));
                }
                catch (Exception err)
                {
                    msg.AddFailedAttempt();
                    context.SendUpstream(new CommandFailed(msg, err));
                    return;
                }

                return;
            }

            context.SendDownstream(message);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Dispatch a single command
        /// </summary>
        private bool DispatchCommand()
        {
            DispatchCommand command;

            if (!_commands.TryDequeue(out command))
            {
                return(false);
            }

            try
            {
                _context.SendDownstream(command);
            }
            catch (Exception err)
            {
                _context.SendUpstream(new PipelineFailure(this, command, "AsyncHandler failed to dispatch commands.",
                                                          err));
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Send a message to the domainEvent handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public virtual void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            var dispatchMsg = message as DispatchEvent;

            if (dispatchMsg != null)
            {
                try
                {
                    _method.MakeGenericMethod(dispatchMsg.DomainEvent.GetType()).Invoke(this,
                                                                                        new object[]
                                                                                        { dispatchMsg.DomainEvent });

                    return;
                }
                catch (Exception err)
                {
                    context.SendUpstream(new EventFailed(dispatchMsg, err));
                }
            }
        }