20 using System.Collections;
21 using System.Collections.Generic;
31 private readonly IEnumerator<BaseData> _underlyingEnumerator;
32 private readonly IEnumerator<DateTime> _scheduledTimes;
34 private readonly DateTimeZone _scheduleTimeZone;
35 private BaseData _underlyingCandidateDataPoint;
36 private bool _scheduledTimesEnded;
43 object IEnumerator.Current =>
Current;
54 IEnumerable<DateTime> scheduledTimes,
56 DateTimeZone scheduleTimeZone,
59 _scheduleTimeZone = scheduleTimeZone;
60 _frontierTimeProvider = frontierTimeProvider;
61 _underlyingEnumerator = underlyingEnumerator;
62 _scheduledTimes = scheduledTimes.GetEnumerator();
64 MoveScheduleForward(startTime);
75 if (_scheduledTimesEnded)
82 if (_underlyingCandidateDataPoint ==
null)
84 if (_underlyingEnumerator.Current !=
null && _underlyingEnumerator.Current.EndTime <= _scheduledTimes.Current)
86 _underlyingCandidateDataPoint = _underlyingEnumerator.Current;
92 _underlyingCandidateDataPoint =
Current.
Clone(fillForward:
true);
97 if (_underlyingEnumerator.Current ==
null
98 || _underlyingEnumerator.Current.EndTime < _scheduledTimes.Current)
104 if (!_underlyingEnumerator.MoveNext())
106 if (_underlyingCandidateDataPoint !=
null)
115 if (_underlyingEnumerator.Current !=
null)
117 if (_underlyingEnumerator.Current.EndTime <= _scheduledTimes.Current)
123 _underlyingCandidateDataPoint = _underlyingEnumerator.Current;
125 else if (_underlyingCandidateDataPoint ==
null)
128 _underlyingCandidateDataPoint = _underlyingEnumerator.Current;
129 MoveScheduleForward();
135 if (_underlyingCandidateDataPoint !=
null
138 && _scheduledTimes.Current.ConvertToUtc(_scheduleTimeZone) <= GetUtcNow())
140 Current = _underlyingCandidateDataPoint;
149 MoveScheduleForward();
150 _underlyingCandidateDataPoint =
null;
163 _underlyingEnumerator.Reset();
171 _scheduledTimes.Dispose();
172 _underlyingEnumerator.Dispose();
179 private DateTime GetUtcNow()
181 if (_frontierTimeProvider !=
null)
183 return _frontierTimeProvider.GetUtcNow();
185 return DateTime.MaxValue;
188 private void MoveScheduleForward(DateTime? frontier =
null)
192 _scheduledTimesEnded = !_scheduledTimes.MoveNext();
194 while (!_scheduledTimesEnded && frontier.HasValue && _scheduledTimes.Current < frontier.Value);