Contains information for the executed action.
상속: Flatwhite.Core.MethodInvocationContext
예제 #1
0
        /// <summary>
        /// This will be called via Reflection
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="filterAttributes"></param>
        /// <param name="exceptionFilterAttributes"></param>
        /// <param name="methodExecutingContext"></param>
        /// <returns></returns>
        private async Task <TResult> HandleAsyncWithType <TResult>(IReadOnlyList <MethodFilterAttribute> filterAttributes, IReadOnlyList <ExceptionFilterAttribute> exceptionFilterAttributes, MethodExecutingContext methodExecutingContext)
        {
            foreach (var f in filterAttributes)
            {
                try
                {
                    if (methodExecutingContext.Result == null)
                    {
                        await f.OnMethodExecutingAsync(methodExecutingContext).ConfigureAwait(false);
                    }
                }
                catch (Exception ex)
                {
                    var exContext = new MethodExceptionContext(ex, methodExecutingContext);
                    await HandleExceptionAsync(exceptionFilterAttributes, exContext);

                    if (!exContext.Handled)
                    {
                        throw;
                    }
                }
            }

            var reversedFilterAttributes = filterAttributes.Reverse();
            var methodExecutedContext    = new MethodExecutedContext(methodExecutingContext);

            foreach (var f in reversedFilterAttributes)
            {
                try
                {
                    await f.OnMethodExecutedAsync(methodExecutedContext).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    var exContext = new MethodExceptionContext(ex, methodExecutedContext);
                    await HandleExceptionAsync(exceptionFilterAttributes, exContext);

                    if (!exContext.Handled)
                    {
                        throw;
                    }
                }
            }

            if (methodExecutedContext.Result != null && methodExecutedContext.Result is TResult result)
            {
                return(result);
            }
            return(default(TResult));
        }
예제 #2
0
        private void HandleSync(IReadOnlyList <MethodFilterAttribute> filterAttributes, IReadOnlyList <ExceptionFilterAttribute> exceptionFilterAttributes, MethodExecutingContext methodExecutingContext)
        {
            foreach (var f in filterAttributes)
            {
                try
                {
                    if (methodExecutingContext.Result == null)
                    {
                        f.OnMethodExecuting(methodExecutingContext);
                    }
                }
                catch (Exception ex)
                {
                    var exContext = new MethodExceptionContext(ex, methodExecutingContext);
                    HandleException(exceptionFilterAttributes, exContext);
                    if (!exContext.Handled)
                    {
                        throw;
                    }
                }
            }

            var reversedFilterAttributes = filterAttributes.Reverse();
            var methodExecutedContext    = new MethodExecutedContext(methodExecutingContext);

            foreach (var f in reversedFilterAttributes)
            {
                try
                {
                    f.OnMethodExecuted(methodExecutedContext);
                }
                catch (Exception ex)
                {
                    var exContext = new MethodExceptionContext(ex, methodExecutedContext);
                    HandleException(exceptionFilterAttributes, exContext);
                    if (!exContext.Handled)
                    {
                        throw;
                    }
                }
            }
        }
예제 #3
0
 public virtual Task OnMethodExecutedAsync(MethodExecutedContext methodExecutedContext)
 {
     OnMethodExecuted(methodExecutedContext);
     return(Task.CompletedTask);
 }
예제 #4
0
 public virtual void OnMethodExecuted(MethodExecutedContext methodExecutedContext)
 {
 }