private void OnExecute(IActionResultHandler resultHandler) { try { if (FilterExecuting()) { try { Result = Handler.Invoke(Controller, HttpContext, ActionHandlerFactory, Parameters); } catch (Exception error) { Exception = error; } finally { FilterExecuted(); } if (Exception != null) { resultHandler.Error(Exception); } else { resultHandler.Success(Result); } } } catch (Exception e_) { resultHandler.Error(e_); } }
internal void Execute(IActionResultHandler resultHandler) { if (Handler.ValidateRPS()) { Handler.IncrementRequest(); if (Handler.ThreadQueue == null || Handler.ThreadQueue.Type == ThreadQueueType.None) { if (Handler.Async) { OnAsyncExecute(resultHandler); } else { OnExecute(resultHandler); } } else { ActionTask actionTask = new ActionTask(this, resultHandler); var queue = Handler.ThreadQueue.GetQueue(this.HttpContext); this.HttpContext.Queue = queue; queue.Enqueue(actionTask); } } else { Handler.IncrementError(); resultHandler.Error(new Exception($"{Handler.SourceUrl} process error,out of max rps!"), EventArgs.LogType.Warring, 509); } }
internal void Execute(IActionResultHandler resultHandler) { if (Handler.Async) { OnAsyncExecute(resultHandler); } else { OnExecute(resultHandler); } }
/// <summary> /// Creates and instance of <see cref="ExceptionHandlingMiddleware"/> /// </summary> /// <param name="next">Next <see cref="RequestDelegate"/> to be executed after <see cref="ExceptionHandlerDefinition"/> invocation.</param> /// <param name="exceptionManager"><see cref="IExceptionManager"/> added to the middleware</param> /// <param name="exceptionCodesDecider"><see cref="IExceptionCodesDecider"/> to be used in <see cref="ExceptionFilter"/></param> /// <param name="actionResultHandler"><see cref="IActionResultHandler"/> used to handle created <see cref="IExceptionManager"/></param> public ExceptionHandlingMiddleware( RequestDelegate next, IExceptionManager exceptionManager, IExceptionCodesDecider exceptionCodesDecider, IActionResultHandler actionResultHandler) { _next = next ?? throw new ArgumentNullException(nameof(next)); _exceptionManager = exceptionManager ?? throw new ArgumentNullException(nameof(exceptionManager)); _exceptionCodesDecider = exceptionCodesDecider ?? throw new ArgumentNullException(nameof(exceptionCodesDecider)); _actionResultHandler = actionResultHandler ?? throw new ArgumentException(nameof(actionResultHandler)); }
private async void OnAsyncExecute(IActionResultHandler resultHandler) { HttpContext.Server.RequestExecting(); try { if (FilterExecuting()) { try { var task = (Task)Handler.Invoke(Controller, HttpContext, ActionHandlerFactory, Parameters); await task; if (Handler.PropertyHandler != null) { Result = Handler.PropertyHandler.Get(task); } else { Result = null; } } catch (Exception error) { Exception = error; } finally { FilterExecuted(); } } if (Exception != null) { Handler.IncrementError(); resultHandler.Error(Exception); } else { resultHandler.Success(Result); } } catch (Exception e_) { Handler.IncrementError(); resultHandler.Error(e_); } finally { HttpContext.Server.RequestExecuted(); } }
internal void Execute(IActionResultHandler resultHandler) { if (Handler.ValidateRPS()) { Handler.IncrementRequest(); if (Handler.Async) { OnAsyncExecute(resultHandler); } else { OnExecute(resultHandler); } } else { Handler.IncrementError(); resultHandler.Error(new Exception($"{Handler.SourceUrl} process error,out of max rps!"), EventArgs.LogType.Warring, 509); } }
/// <summary> /// Injects Custom ASP.NET Core Application exception handling to <see cref="IExceptionHandlerFeature"/> /// </summary> /// <param name="applicationBuilder"><see cref="IExceptionHandlerFeature"/></param> /// <returns><see cref="IApplicationBuilder"/> instance</returns> public static IApplicationBuilder UseExceptionHandlingFilter(this IApplicationBuilder applicationBuilder) { applicationBuilder.UseExceptionHandler( options => { options.Run( async context => { var ex = context.Features.Get <IExceptionHandlerFeature>(); if (ex != null) { IActionResultHandler actionResultHandler = context.RequestServices.GetService(typeof(IActionResultHandler)) as IActionResultHandler; await actionResultHandler?.HandleActionResult(new ActionResultContext(context, ex.Error)); } }); } ); return(applicationBuilder); }
public ActionTask(ActionContext context, IActionResultHandler resultHandler) { Context = context; ResultHandler = resultHandler; }
public void Execute(IHttpContext context, IActionResultHandler handler, ValidationBase validation, ParameterInfo parameterInfo) { ActionResult actionResult = new ActionResult(validation.Code, validation.GetResultMessage(parameterInfo.Name)); handler.Success(actionResult); }