private string Execute(TRequest request, string nextRequestHandlerId, ref RequestHandlerResult result) { string lastRequestHandlerId; try { this._requestHandler.Context.Request = request; result = RequestHandlerOrchestrator .ExecuteHandler(request, (RequestHandler<TContext, TRequest>)this._requestHandler, nextRequestHandlerId); } catch(PipelinePolicyException px) { result = px.Result; } catch (Exception ex) { //faz nada } finally { lastRequestHandlerId = this._requestHandler.Context.CurrentRequestHandleId; result = ExecuteFinallyHandler(request) ?? result; } return lastRequestHandlerId; }
private string Execute(TRequest request, string nextRequestHandlerId, ref RequestHandlerResult result) { string lastRequestHandlerId; try { this._requestHandler.Context.Request = request; result = RequestHandlerOrchestrator .ExecuteHandler(request, (RequestHandler <TContext, TRequest>) this._requestHandler, nextRequestHandlerId); } catch (PipelinePolicyException px) { result = px.Result; } catch (Exception ex) { if (Log.Logger != null) { using (LogContext.PushProperty("RequestKey", this._requestKey)) { Log.Logger.Error(ex, string.Concat("Error - ", this._requestHandler.Context.CurrentRequestHandleId)); } } } finally { lastRequestHandlerId = this._requestHandler.Context.CurrentRequestHandleId; result = ExecuteFinallyHandler(request) ?? result; } return(lastRequestHandlerId); }
protected RequestHandlerResult Rollback(RequestHandlerResult result) { this.Context.Response = result; this._pipeline.ExecuteRollback(this._rollbackIndex, this._request); return(result); }
private RequestHandlerResult ExecuteFinallyHandler(TRequest request) { RequestHandlerResult result = null; if (this._finallyRequestHandler != null) { result = ((RequestHandler <TContext, TRequest>) this._finallyRequestHandler).Execute(request); } return(result); }
private RequestHandlerResult ExecuteFinallyHandler(TRequest request) { RequestHandlerResult result = null; if (this._finallyRequestHandler != null) { result = this._finallyRequestHandler.HandleRequest(request); } return(result); }
internal RequestHandlerResult Execute() { //_request = request; RequestHandlerResult result = null; if (this.Policy != null) { this.Policy.Execute(() => { result = HandleRequest(); }); } else if (this.PolicyRequestHandler != null) { result = this.PolicyRequestHandler.Execute(() => { if (this.Context.Response != null && this.Context.Response.IsSuccess() == false && this.Context.Response.RequestHandlerId != this.RequestHandleId()) { throw new PipelinePolicyException(this.Context.Response); } return(HandleRequest()); }); if (result.IsSuccess() == false) { throw new PipelinePolicyException(this.Context.Response); } } else { result = HandleRequest(); } return(result); }
public RequestHandlerResult Execute(TRequest request, string idempotencyKey) { if (this._validator != null) { var validateResult = this._validator.Validate(request); if (validateResult.IsValid == false) { var errors = (validateResult.Errors.Select(p => new ErrorResult(null, p.ErrorMessage, p.PropertyName))).ToList(); return(new RequestHandlerResult(errors, 400)); } } if (this._requestHandler == null) { throw new ArgumentNullException("No started handlers"); } RequestHandlerResult result = null; var lastRequestHandlerId = string.Empty; var nextRequestHandlerId = string.Empty; TContext context = null; var hash = idempotencyKey == string.Empty ? request.GenerateHash() : idempotencyKey; if (this._useReuseRequisitionHash) { var snapshot = this._cacheProvider.Get <PipelineSnapshot>(hash).Result; if (snapshot != null) { if (snapshot.Success) { result = snapshot.Context.Response; result.SetStatusCode(200); return(result); } else { context = (TContext)snapshot.Context; context.Request = request; nextRequestHandlerId = snapshot.LastRequestHandlerId; this._requestHandler.UpdateContext(context); } } } lastRequestHandlerId = Execute(request, nextRequestHandlerId, ref result); if (this._useReuseRequisitionHash) { var sucess = result?.IsSuccess() ?? false; var snapshot = new PipelineSnapshot(sucess, lastRequestHandlerId, this._requestHandler.Context); this._cacheProvider.Add <PipelineSnapshot>(snapshot, hash); } return(result); }
public PipelinePolicyException(RequestHandlerResult result) { this.Result = result; }