private void DataRead(CancellationToken token, ReadSession session) { using (var stream = File.OpenRead(readerConfig.Value.FileName)) using (var reader = new StreamReader(stream)) using (var csv = new CsvReader(reader, new CsvConfiguration { Delimiter = " " })) { while (csv.Read() && !session.Completed) { token.ThrowIfCancellationRequested(); var rawData = GetRawData(csv); if (session.Finish(rawData.Timestamp)) { break; } if (session.InPast(rawData.Timestamp)) { continue; } while (session.InFuture(rawData.Timestamp)) { if (!session.ChunkDataCollection.Any() && !session.RawDataCollection.Any()) { SetReadTime(session, session.StopWatch()); } if (token.WaitHandle.WaitOne(MathExtension.Min(TimeSpan.FromSeconds(1), session.FutureRealTime(rawData.Timestamp)))) { break; } } session.RawDataCollection.Add(rawData, token); } } }
public TimeSpan CalcShift(TimeSpan readTime) { var availibleTime = MathExtension.Min(readTime, StopWatch()); return(MathExtension.Min(CalcTime + window, availibleTime)); }