예제 #1
0
        public PolicyResult <TResult> ExecuteAndCapture(Func <Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            try
            {
                TResult result = Execute(action, context, cancellationToken);

                if (ResultPredicates.AnyMatch(result))
                {
                    return(PolicyResult <TResult> .Failure(result, context));
                }

                return(PolicyResult <TResult> .Successful(result, context));
            }
            catch (Exception exception)
            {
                return(PolicyResult <TResult> .Failure(exception, GetExceptionType(ExceptionPredicates, exception), context));
            }
        }
        public async Task <PolicyResult <TResult> > ExecuteAndCaptureAsync(Func <Context, CancellationToken, Task <TResult> > action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            try
            {
                TResult result = await ExecuteAsync(action, context, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext);

                if (ResultPredicates.AnyMatch(result))
                {
                    return(PolicyResult <TResult> .Failure(result, context));
                }

                return(PolicyResult <TResult> .Successful(result, context));
            }
            catch (Exception exception)
            {
                return(PolicyResult <TResult> .Failure(exception, GetExceptionType(ExceptionPredicates, exception), context));
            }
        }