示例#1
0
 public DataReader(PIPointsProvider pointsProvider, BlockingCollection <DataPacket> writeQueue, CancellationToken token)
 {
     _pointsProvider    = pointsProvider;
     _writeQueue        = writeQueue;
     _timeOffset        = TimeSpan.FromDays(Settings.General.Default.ReplayTimeOffsetDays);
     _cancellationToken = token;
 }
示例#2
0
        /// <summary>
        /// todo: needs refactoring to remove the if and separate the logic between backfill and not backfill
        /// </summary>
        /// <param name="provider"></param>
        /// <returns></returns>
        private List <AFTimeRange> GetTimeRanges(PIPointsProvider provider)
        {
            DateTime startTime;
            DateTime endTime;

            // when backfilling, we will get the oldest timestamp in the snapshot
            if (_backfill)
            {
                startTime = DateTime.MaxValue;
                int i = 0;
                foreach (var tagChunk in provider.GetPointsByChunks(Settings.General.Default.BackfillTagsChunkSize))
                {
                    i++;
                    _logger.InfoFormat("Looking for minimum snapshot time in the data for tag chunk: {0} - chunk size: {1}", i, Settings.General.Default.BackfillTagsChunkSize);
                    var pointsList = new PIPointList(tagChunk);
                    var time       = pointsList.CurrentValue().Min(v => v.Timestamp.LocalTime);
                    startTime = time < startTime ? time : startTime;
                }


                if (startTime < DateTime.Now - TimeSpan.FromDays(Settings.General.Default.ReplayTimeOffsetDays))
                {
                    startTime = Settings.General.Default.BackfillDefaultStartTime;
                }


                endTime        = DateTime.Now.ToLocalTime();
                _nextStartTime = endTime.AddSeconds(1);

                _logger.InfoFormat("Backfill start time: {0:G} - end time: {1:G}", startTime.ToLocalTime(), endTime.ToLocalTime());
            }
            else
            {
                startTime      = _nextStartTime;
                endTime        = DateTime.Now;
                _nextStartTime = endTime.AddSeconds(1);
            }


            var timeRanges =
                TimeStampsGenerator.GetAfTimeRanges(
                    TimeSpan.FromHours(Settings.General.Default.BackFillHoursPerDataChunk)
                    , startTime - _timeOffset
                    , endTime - _timeOffset);

            return(timeRanges);
        }
示例#3
0
        public void Run(string server, string pointsQuery)
        {
            var connection = new PIConnection(server);


            _mainTask = Task.Run(() =>
            {
                WaitForServerToBeAvailable(connection);

                var pointsProvier = new PIPointsProvider(pointsQuery, connection.GetPiServer());

                _dataReader = new DataReader(pointsProvier, _queue, _cancellationTokenSource.Token);
                _dataWriter = new DataWriter(_queue, connection.GetPiServer());
                _dataWriter.Run();

                _dataReader.RunBackfill();
                _logger.Info("Starting the normal operations process");
                _dataReader.Run(General.Default.NormalDataCollectionFrequencySeconds);
            }, _cancellationTokenSource.Token);
        }