示例#1
0
        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;
        }
示例#2
0
        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);
        }
示例#3
0
        protected RequestHandlerResult Rollback(RequestHandlerResult result)
        {
            this.Context.Response = result;

            this._pipeline.ExecuteRollback(this._rollbackIndex, this._request);

            return(result);
        }
示例#4
0
        private RequestHandlerResult ExecuteFinallyHandler(TRequest request)
        {
            RequestHandlerResult result = null;

            if (this._finallyRequestHandler != null)
            {
                result = ((RequestHandler <TContext, TRequest>) this._finallyRequestHandler).Execute(request);
            }

            return(result);
        }
示例#5
0
        private RequestHandlerResult ExecuteFinallyHandler(TRequest request)
        {
            RequestHandlerResult result = null;

            if (this._finallyRequestHandler != null)
            {
                result = this._finallyRequestHandler.HandleRequest(request);
            }

            return(result);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
 public PipelinePolicyException(RequestHandlerResult result)
 {
     this.Result = result;
 }