private async Task ExecutePostHandleBehaviorsAsync(CommandBehaviorResult result, CommandResponse <TResponse> response) { var behaviors = new List <ICommandBehavior>(this.behaviors.Safe().Reverse()); // TODO: order! foreach (var behavior in behaviors) // build up the behaviors chain { behavior.SetNext(behaviors.NextOf(behavior)); } this.Logger.LogDebug($"{{LogKey:l}} command behaviors chain: post={behaviors.Select(e => e.GetType().PrettyName()).ToString("|")}", LogKeys.AppCommand); if (behaviors.Count > 0) // execute all chained behaviors { await this.behaviors.First().ExecutePostHandleAsync(response, result).AnyContext(); } }
private async Task <CommandBehaviorResult> ExecutePreHandleBehaviorsAsync(TCommand request) { var behaviors = new List <ICommandBehavior>(this.behaviors.Safe()); // TODO: order! foreach (var behavior in behaviors) // build up the behaviors chain { behavior.SetNext(behaviors.NextOf(behavior)); } this.Logger.LogDebug($"{{LogKey:l}} command behaviors chain: pre={behaviors.Select(e => e.GetType().PrettyName()).ToString("|")}", LogKeys.AppCommand); var result = new CommandBehaviorResult(); if (behaviors.Count > 0) // execute all chained behaviors { await this.behaviors.First().ExecutePreHandleAsync(request, result).AnyContext(); } return(result); }
public async Task ExecutePostHandleAsync <TResponse>(CommandResponse <TResponse> response, CommandBehaviorResult result) { if (!result.Cancelled && this.next != null) { await this.next.ExecutePostHandleAsync(response, result).AnyContext(); } }
/// <summary> /// Executes this behavior for the specified command. /// </summary> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="request">The command.</param> public async Task ExecutePreHandleAsync <TResponse>(Command <TResponse> request, CommandBehaviorResult result) { EnsureArg.IsNotNull(request); var validationResult = request.Validate(); if (!validationResult.IsValid) { // TODO: log validation errors if (this.throwOnNotIsValid) { throw new ValidationException($"{request.GetType().Name} has validation errors: " + validationResult.Errors.Safe().Select(e => $"{e.PropertyName}={e}").ToString(", "), validationResult.Errors); } else { result.SetCancelled($"{request.GetType().Name} has validation errors: " + validationResult.Errors.Safe().Select(e => $"{e.PropertyName}={e}").ToString(", ")); } } if (!result.Cancelled && this.next != null) { await this.next.ExecutePreHandleAsync(request, result).AnyContext(); } // terminate here }
/// <summary> /// Executes this behavior for the specified command. /// </summary> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="request">The command.</param> public async Task ExecutePreHandleAsync <TResponse>(Command <TResponse> request, CommandBehaviorResult result) { EnsureArg.IsNotNull(request); //ISpan parentSpan = null; //if (request.Properties.ContainsKey(CommandPropertyKeys.TraceId) && request.Properties.ContainsKey(CommandPropertyKeys.ParentSpanId)) //{ // // dehydrate parent span // parentSpan = new Span(request.Properties.GetValueOrDefault(CommandPropertyKeys.TraceId) as string, request.Properties.GetValueOrDefault(CommandPropertyKeys.ParentSpanId) as string); //} //this.scope = this.tracer?.BuildSpan( // $"command {request.GetType().PrettyName()}".ToLowerInvariant(), // LogKeys.AppCommand, // SpanKind.Consumer, // parentSpan).Activate(this.logger); if (!result.Cancelled && this.next != null) { await this.next.ExecutePreHandleAsync(request, result).AnyContext(); } else { //this.scope?.Dispose(); } // terminate here }
/// <summary> /// Executes this behavior for the specified command. /// </summary> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="request">The command.</param> public async Task ExecutePreHandleAsync <TResponse>(Command <TResponse> request, CommandBehaviorResult result) { EnsureArg.IsNotNull(request); this.logger.LogJournal(LogKeys.AppCommand, $"send (name={request.GetType().PrettyName()}, id={request.Id})", LogPropertyKeys.TrackSendCommand); if (!result.Cancelled && this.next != null) { await this.next.ExecutePreHandleAsync(request, result).AnyContext(); } // terminate here }
/// <summary> /// Executes this behavior for the specified command. /// </summary> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="request">The command.</param> public async Task ExecutePreHandleAsync <TResponse>(Command <TResponse> request, CommandBehaviorResult result) { EnsureArg.IsNotNull(request); // TODO: implement // - check if command exists in repo/filestorage // - if not add to repo, return CommandBehaviorResult if (!result.Cancelled && this.next != null) { await this.next.ExecutePreHandleAsync(request, result).AnyContext(); } // terminate here }