Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
 public RetryResult(RetryContext context, TResult value) : base(context)
 {
     Value = value;
 }
Exemplo n.º 4
0
 public RetryException(RetryContext context)
     : base(string.Format(Resources.ExceptionMessage, context.Exceptions.Count, context.LastException.Message), context.LastException)
 {
     Context = context;
 }
Exemplo n.º 5
0
 public RetryException(RetryContext context)
     : base(string.Format(Resources.ExceptionMessage, context.Exceptions.Count, context.LastException.Message), context.LastException)
 {
     Context = context;
 }
Exemplo n.º 6
0
 public RetryConditionHandle(RetryContext context, RetryCondition condition)
 {
     Context   = context;
     Condition = condition;
 }
Exemplo n.º 7
0
 public RetryConditionHandle(RetryContext context, RetryCondition condition)
 {
     Context = context;
     Condition = condition;
 }
Exemplo n.º 8
0
 public RetryResult(RetryContext context)
 {
     Context = context;
 }