private void InterceptAsync(IInvocation invocation, IEnumerable <AbpAuthorizeAttribute> authorizeAttributes)
 {
     if (invocation.Method.ReturnType == typeof(Task))
     {
         invocation.ReturnValue = InternalAsyncHelper
                                  .AwaitTaskWithPreActionAndPostActionAndFinally(
             () =>
         {
             invocation.Proceed();
             return((Task)invocation.ReturnValue);
         },
             preAction: () => AuthorizeAsync(authorizeAttributes)
             );
     }
     else //Task<TResult>
     {
         invocation.ReturnValue = InternalAsyncHelper
                                  .CallAwaitTaskWithPreActionAndPostActionAndFinallyAndGetResult(
             invocation.Method.ReturnType.GenericTypeArguments[0],
             () =>
         {
             invocation.Proceed();
             return(invocation.ReturnValue);
         },
             preAction: async() => await AuthorizeAsync(authorizeAttributes)
             );
     }
 }
Exemplo n.º 2
0
 private void InterceptAsyncMethod(IInvocation invocation)
 {
     if (invocation.Method.ReturnType == typeof(Task))
     {
         invocation.ReturnValue = _abpInterceptor.InterceptAsync(new CastleAbpMethodInvocationAdapter(invocation));
     }
     else
     {
         var interceptResult   = _abpInterceptor.InterceptAsync(new CastleAbpMethodInvocationAdapter(invocation));
         var actualReturnValue = invocation.ReturnValue;
         invocation.ReturnValue = InternalAsyncHelper.CallAwaitTaskWithPreActionAndPostActionAndFinallyAndGetResult(
             invocation.Method.ReturnType.GenericTypeArguments[0],
             () => actualReturnValue,
             () => interceptResult
             );
     }
 }