public IEnumerable <object> RobustEnumeration(IEnumerable <object> input, IndexingFunc func) { using (var wrapped = new StatefulEnumerableWrapper <dynamic>(input.GetEnumerator())) { IEnumerator <dynamic> en; using (en = func(wrapped).GetEnumerator()) { int maxNumberOfConsecutiveErrors = numberOfConsecutiveErrors; do { var moveSuccessful = MoveNext(en, wrapped); if (moveSuccessful == false) { yield break; } if (moveSuccessful == true) { maxNumberOfConsecutiveErrors = numberOfConsecutiveErrors; yield return(en.Current); } else { // we explictly do not dispose the enumerator, since that would not allow us // to continue on with the next item in the list. // Not actually a problem, because we are iterating only over in memory data // en.Dispose(); en = func(wrapped).GetEnumerator(); maxNumberOfConsecutiveErrors--; } } while (maxNumberOfConsecutiveErrors > 0); } } }
private bool?MoveNext(IEnumerator en, StatefulEnumerableWrapper <object> innerEnumerator, WorkContext context, IStorageActionsAccessor actions) { try { actions.Indexing.IncrementIndexingAttempt(); var moveNext = en.MoveNext(); if (moveNext == false) { actions.Indexing.DecrementIndexingAttempt(); } return(moveNext); } catch (Exception e) { actions.Indexing.IncrementIndexingFailure(); context.AddError(name, TryGetDocKey(innerEnumerator.Current), e.Message ); log.WarnFormat(e, "Failed to execute indexing function on {0} on {1}", name, GetDocId(innerEnumerator)); } return(null); }
public IEnumerable <object> RobustEnumeration(IEnumerator <object> input, IEnumerable <IndexingFunc> funcs) { var onlyIterateOverEnumableOnce = new List <object>(); try { while (input.MoveNext()) { onlyIterateOverEnumableOnce.Add(input.Current); } } catch (Exception e) { OnError(e, null); yield break; } foreach (var func in funcs) { using (var wrapped = new StatefulEnumerableWrapper <dynamic>(onlyIterateOverEnumableOnce.GetEnumerator())) { IEnumerator <dynamic> en; using (en = func(wrapped).GetEnumerator()) { int maxNumberOfConsecutiveErrors = numberOfConsecutiveErrors; do { cancellationToken.ThrowIfCancellationRequested(); var moveSuccessful = MoveNext(en, wrapped); if (moveSuccessful == false) { break; } if (moveSuccessful == true) { maxNumberOfConsecutiveErrors = numberOfConsecutiveErrors; yield return(en.Current); } else { // we explicitly do not dispose the enumerator, since that would not allow us // to continue on with the next item in the list. // Not actually a problem, because we are iterating only over in memory data // en.Dispose(); en = func(wrapped).GetEnumerator(); maxNumberOfConsecutiveErrors--; } } while (maxNumberOfConsecutiveErrors > 0); } } } }
private static object GetDocId(StatefulEnumerableWrapper <object> currentInnerEnumerator) { var dictionary = currentInnerEnumerator.Current as IDictionary <string, object>; if (dictionary == null) { return(null); } object docId; dictionary.TryGetValue("__document_id", out docId); return(docId); }
private bool?MoveNext(IEnumerator en, StatefulEnumerableWrapper <object> innerEnumerator) { try { BeforeMoveNext(); var moveNext = en.MoveNext(); if (moveNext == false) { CancelMoveNext(); } return(moveNext); } catch (Exception e) { OnError(e, innerEnumerator.Current); } return(null); }
public IEnumerable <object> RobustEnumeration(IEnumerable <object> input, IndexingFunc func) { var wrapped = new StatefulEnumerableWrapper <dynamic>(input.GetEnumerator()); IEnumerator <object> en = func(wrapped).GetEnumerator(); do { var moveSuccessful = MoveNext(en, wrapped); if (moveSuccessful == false) { yield break; } if (moveSuccessful == true) { yield return(en.Current); } else { en = func(wrapped).GetEnumerator(); } } while (true); }
protected IEnumerable <object> RobustEnumeration(IEnumerable <object> input, IndexingFunc func, IStorageActionsAccessor actions, WorkContext context) { var wrapped = new StatefulEnumerableWrapper <dynamic>(input.GetEnumerator()); IEnumerator <object> en = func(wrapped).GetEnumerator(); do { var moveSuccessful = MoveNext(en, wrapped, context, actions); if (moveSuccessful == false) { yield break; } if (moveSuccessful == true) { yield return(en.Current); } else { en = func(wrapped).GetEnumerator(); } } while (true); }
public StatefulbEnumeratorWrapper(IEnumerator <T> inner, StatefulEnumerableWrapper <T> statefulEnumerableWrapper) { this.inner = inner; this.statefulEnumerableWrapper = statefulEnumerableWrapper; }