public IEnumerable<object> RobustEnumeration(IEnumerator<object> input, IndexingFunc func) { using (var wrapped = new StatefulEnumerableWrapper<dynamic>(input)) { 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); } } }
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 { context.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); } } } }
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); }
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; }
protected IEnumerable<object> RobustEnumeration(IEnumerable<object> input, IndexingFunc func, DocumentStorageActions 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); }
private bool? MoveNext(IEnumerator en, StatefulEnumerableWrapper<object> innerEnumerator, WorkContext context, DocumentStorageActions actions) { try { actions.IncrementIndexingAttempt(); var moveNext = en.MoveNext(); if (moveNext == false) actions.DecrementIndexingAttempt(); return moveNext; } catch (Exception e) { actions.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; }
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 static bool? MoveNext(IEnumerator en, StatefulEnumerableWrapper<object> innerEnumerator, ICollection<string> errors) { try { return en.MoveNext(); } catch (Exception e) { errors.Add(String.Format("Doc '{0}', Error: {1}", TryGetDocKey(innerEnumerator.Current), e.Message)); } return null; }