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