private void enumeratePartialAndClose(PipelineContext ctx, MappedObjectEnumerator e, int N) { try { //ctx.ImportLog.Log("enumeratePartial e={0}", e.GetType().Name); int startedExpCount = base.cnt_added; if (this.undupper == null) //Easy case without undupper? { ctx.ImportLog.Log(_LogType.ltTimerStart, "-- enum partial[{0}]: count=unknown (not undupping)", N); while (true) { var obj = e.GetNext(); if (obj == null) { break; } PassThrough(ctx, obj); } numAfterSort += cnt_added - startedExpCount; ctx.ImportLog.Log(_LogType.ltTimerStop, "-- enum done. Forwarded {0} recs, skipped 0 recs.", cnt_added - startedExpCount); goto EXIT_RTN; } //More complex case with undupper List <JObject> list = e.GetAll(); int cnt = list.Count; if (cnt == 0) { goto EXIT_RTN; } numAfterSort += cnt; ctx.ImportLog.Log(_LogType.ltTimerStart, "-- enum partial[{0}]: count={1}", N, cnt); JObject prev = list[0]; JToken[] prevKeys = undupper.GetKeys(prev); int prevIdx = 0; ctx.ActionFlags = _ActionFlags.None; for (int i = 1; i < list.Count; i++) { JObject cur = list[i]; JToken[] keys = undupper.GetKeys(cur); if (undupper.CompareKeys(prevKeys, keys) == 0) { continue; } if (undupActions != null) { undupActions.ProcessRecords(ctx, list, prevIdx, i - prevIdx); } if ((ctx.ActionFlags & _ActionFlags.Skip) == 0) { PassThrough(ctx, prev); } prevIdx = i; prev = cur; prevKeys = keys; } if (prevIdx < list.Count) { if (undupActions != null) { undupActions.ProcessRecords(ctx, list, prevIdx, list.Count - prevIdx); } if ((ctx.ActionFlags & _ActionFlags.Skip) == 0) { PassThrough(ctx, prev); } } int exp = base.cnt_added - startedExpCount; ctx.ImportLog.Log(_LogType.ltTimerStop, "-- enum done. Forwarded {0} recs, skipped {1} recs.", exp, cnt - exp); EXIT_RTN :; } finally { e.Close(); } }
private void enumeratePartialAndClose(PipelineContext ctx, MappedObjectEnumerator e) { if (e == null) { return; } try { List <JObject> list = e.GetAll(); int cnt = list.Count; if (cnt == 0) { goto EXIT_RTN; } if (beforeSort != null) { list = (List <JObject>)beforeSort.Execute(ctx, list); } list.Sort(this.Sorter); if (this.Undupper == null && this.afterSort == null) { goto EXPORT_ALL; } if (afterSort != null) { list = (List <JObject>)afterSort.Execute(ctx, list); } if (this.Undupper == null) { goto EXPORT_ALL; } JObject prev = list[0]; JToken[] prevKeys = Undupper.GetKeys(prev); int prevIdx = 0; for (int i = 1; i < list.Count; i++) { JObject cur = list[i]; JToken[] keys = Undupper.GetKeys(cur); if (Undupper.CompareKeys(prevKeys, keys) == 0) { continue; } if (undupActions != null) { undupActions.ProcessRecords(ctx, list, prevIdx, i - prevIdx); } PassThrough(ctx, prev); prevIdx = i; prev = cur; prevKeys = keys; } if (prevIdx < list.Count) { if (undupActions != null) { undupActions.ProcessRecords(ctx, list, prevIdx, list.Count - prevIdx); } PassThrough(ctx, prev); } goto EXIT_RTN; EXPORT_ALL: for (int i = 0; i < list.Count; i++) { PassThrough(ctx, list[i]); } EXIT_RTN: numAfterSort += cnt; } finally { e.Close(); } }