/// <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); }
/// <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); }
/// <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)); } } }