Ejemplo n.º 1
0
        private async Task<ResponseMessage> ExecuteActionFilterAsyncCore(ActionContext actionContext, CancellationToken cancellationToken, Func<Task<ResponseMessage>> continuation)
        {
            await OnActionExecutingAsync(actionContext);

            if (actionContext.Response != null)
            {
                return actionContext.Response;
            }

            return await CallOnActionExecutedAsync(actionContext, cancellationToken, continuation);
        }
Ejemplo n.º 2
0
 private async Task<ResponseMessage> CallOnActionExecutedAsync(ActionContext actionContext, CancellationToken cancellationToken, Func<Task<ResponseMessage>> continuation)
 {
     ResponseMessage response = null; ;
     try
     {
         response = await continuation();
     }
     catch (Exception ex)
     {
     }
     await OnActionExecutedAsync(actionContext, cancellationToken);
     return response;
     //throw new NotImplementedException();
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Controller controller = new Controller();
            MethodInfo actionMethod = typeof(Controller).GetMethod("Get");

            CancellationToken cancellationToken = new CancellationToken();

            List<IActionFilter> filters = new List<IActionFilter>() {
            new FirstActionFilter(),
            new SecondActionFilter()
            };
            ActionContext context = new ActionContext()
            {
                Controller = controller,
                Action = actionMethod,
                Arguments = new object[0]
            };
            ActionInvoker invoker = new ActionInvoker(context.Action);

            Func<Task<ResponseMessage>> result = () =>
            {
                return invoker.Invoke(context, cancellationToken);
            };

            for (int i = 0; i <= filters.Count - 1; i++)
            {
                IActionFilter filter = filters[i];

                Func<Func<Task<ResponseMessage>>, IActionFilter, Func<Task<ResponseMessage>>> chainContinuation =
                    (continuation, innerFilter) =>
                    {
                        return () =>
                        {
                            return innerFilter.ExecuteActionFilterAsync(context, cancellationToken, continuation);
                        };
                    };
                result = chainContinuation(result, filter);
            }
            //string res = continuation()().Result.Message;
            result.Invoke();
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        public Task<ResponseMessage> ExecuteActionFilterAsync(ActionContext actionContext, System.Threading.CancellationToken cancellationToken, Func<Task<ResponseMessage>> continuation)
        {
            return ExecuteActionFilterAsyncCore(actionContext, cancellationToken, continuation);

        }
Ejemplo n.º 5
0
 public Task OnActionExecutedAsync(ActionContext actionContext, CancellationToken cancellationToken)
 {
     OnActionExecuted(actionContext);
     return Task.FromResult<AsyncVoid>(default(AsyncVoid));
 }
Ejemplo n.º 6
0
        public Task OnActionExecutingAsync(ActionContext actionContext)
        {
            OnActionExecuting(actionContext);

            return Task.FromResult<AsyncVoid>(default(AsyncVoid));
        }
Ejemplo n.º 7
0
 public virtual void OnActionExecuted(ActionContext actionContext)
 {
 }
Ejemplo n.º 8
0
 public override void OnActionExecuting(ActionContext actionContext)
 {
     Console.WriteLine("FirstActionFilter Executing");
 }
Ejemplo n.º 9
0
 public async Task<ResponseMessage> Invoke(ActionContext context, CancellationToken cancellationToken)
 {
     return await executor(context.Controller, context.Arguments);
 }
Ejemplo n.º 10
0
 public override void OnActionExecuted(ActionContext actionContext)
 {
     Console.WriteLine("SecondActionFilter Executed");
 }