예제 #1
0
        public RetryResult With(Action <RetryContext> target)
        {
            var context = new RetryContext(this);

            do
            {
                context.DidExceptionOnLastRun = false;

                try
                {
                    target(context);
                    var anyConditionsMet = CheckAndUpdateFilterConditions(context);

                    if (!anyConditionsMet)
                    {
                        return(new RetryResult(context));
                    }
                }
                catch (Exception ex)
                {
                    context.DidExceptionOnLastRun = true;
                    context.Exceptions.Push(ex);

                    var anyConditionsMet = CheckAndUpdateFilterConditions(context);
                    if (!anyConditionsMet)
                    {
                        throw ex;
                    }
                }
            } while (context.KeepRetrying);

            throw new RetryException(context);
        }
예제 #2
0
        private bool CheckAndUpdateFilterConditions(RetryContext context)
        {
            var handlesForFilterConditionsMet = context.FilteredConditionHandles.Where(handle => handle.Condition.FilterCondition(handle));

            if (handlesForFilterConditionsMet.Count() > 0)
            {
                foreach (var handle in handlesForFilterConditionsMet)
                {
                    handle.Occurences = handle.Occurences + 1;

                    if (handle.Occurences == 1)
                    {
                        handle.FirstOccured = DateTimeOffset.Now;
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
 public RetryResult(RetryContext context, TResult value) : base(context)
 {
     Value = value;
 }
예제 #4
0
 public RetryException(RetryContext context)
     : base(string.Format(Resources.ExceptionMessage, context.Exceptions.Count, context.LastException.Message), context.LastException)
 {
     Context = context;
 }
예제 #5
0
 public RetryException(RetryContext context)
     : base(string.Format(Resources.ExceptionMessage, context.Exceptions.Count, context.LastException.Message), context.LastException)
 {
     Context = context;
 }
예제 #6
0
 public RetryConditionHandle(RetryContext context, RetryCondition condition)
 {
     Context   = context;
     Condition = condition;
 }
예제 #7
0
 public RetryConditionHandle(RetryContext context, RetryCondition condition)
 {
     Context = context;
     Condition = condition;
 }
예제 #8
0
 public RetryResult(RetryContext context)
 {
     Context = context;
 }