public void Intercept(IInvocation invocation) { try { invocation.Proceed(); if (AsyncHelper.IsAsyncMethod(invocation.Method)) { invocation.ReturnValue = ExtendedAsyncHelper.CallAwaitTaskWithFinallyAndGetResult( invocation.Method.ReturnType.GenericTypeArguments[0], invocation.ReturnValue, exception => HandleExceptionAsync(invocation, exception)); } } catch (ApiKeyNullException ex) { if (AsyncHelper.IsAsyncMethod(invocation.Method)) { HandleExceptionAsync(invocation, ex); } } catch (MaximumCharacterLimitException ex) { if (AsyncHelper.IsAsyncMethod(invocation.Method)) { HandleExceptionAsync(invocation, ex); } } catch (WebException ex) { if (AsyncHelper.IsAsyncMethod(invocation.Method)) { HandleExceptionAsync(invocation, ex); } } catch (Exception ex) { HandleException(invocation, ex); } }
private void PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options) { var uow = _unitOfWorkManager.Begin(options); invocation.Proceed(); if (invocation.Method.ReturnType == typeof(Task)) { invocation.ReturnValue = ExtendedAsyncHelper.AwaitTaskWithPostActionAndFinally( (Task)invocation.ReturnValue, async() => await uow.CompleteAsync(), exception => uow.Dispose() ); } else //Task<TResult> { invocation.ReturnValue = ExtendedAsyncHelper.CallAwaitTaskWithPostActionAndFinallyAndGetResult( invocation.Method.ReturnType.GenericTypeArguments[0], invocation.ReturnValue, async() => await uow.CompleteAsync(), exception => uow.Dispose() ); } }