Exemplo n.º 1
0
        private void DataChunk(CancellationToken token, ReadSession session)
        {
            var chunk    = new List <Data>();
            var readTime = session.StopWatch();
            var realTime = DateTime.Now.TimeOfDay;

            foreach (var item in session.RawDataCollection.GetConsumingEnumerable(token))
            {
                if (item.Timestamp != readTime)
                {
                    if (!chunk.Any())
                    {
                        realTime = DateTime.Now.TimeOfDay;
                    }

                    if (DateTime.Now.TimeOfDay - realTime > TimeSpan.FromSeconds(1) && (
                            session.ChunkDataCollection.Count < 10 || chunk.Count > 20000))
                    {
                        realTime = DateTime.Now.TimeOfDay;
                        session.ChunkDataCollection.Add(chunk.ToList(), token);
                        chunk.Clear();
                    }

                    readTime = item.Timestamp;
                }

                var data = GetData(item);
                chunk.Add(data);
            }

            if (chunk.Any())
            {
                session.ChunkDataCollection.Add(chunk, token);
            }
        }
Exemplo n.º 2
0
        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);
                        }
                    }
        }
Exemplo n.º 3
0
 private void SetReadTime(ReadSession session, TimeSpan readTime)
 {
     dataFactory.Value.WithRepository <ISettingsRepository>(repo => repo.SetReadTime(readTime), true);
     session.ReadTime = readTime;
     logger.Value.TraceFormat("ReadTime: moved to {0}\tstopWatch: {1}", readTime, session.StopWatch());
 }