示例#1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            FileInfo[] files   = null;
            int        counter = 0;


            _logger.LogInformation($"MeterMonitor executing at: {DateTimeOffset.Now}");

            GetFilesList(ref files);

            while (!stoppingToken.IsCancellationRequested)
            {
                SetSourceToFiles(files, ref counter);

                _telegram = await _meterReader.ReadAsStreamAsync();

                _logger.LogInformation($"Extracted data from {_meterReader.Source} - {_telegram.MeterTimestamp}");
                _logger.LogInformation($"Consumption (high/low):\t{_telegram.PowerConsumptionTariff2}/{_telegram.PowerConsumptionTariff1}");
                _logger.LogInformation($"Production (high/low): \t{_telegram.PowerProductionTariff2}/{_telegram.PowerProductionTariff1}");
                _logger.LogDebug($"Calculated CRC: {_telegram.ComputeChecksum()}");

                if (_telegram.ComputeChecksum() != _telegram.CRC)
                {
                    _logger.LogError("Telegram not extracted correctly. Calculated CRC not equal to stored CRC ");
                }

                SaveDataToFile();
                SaveDataToStorageTable();

                await Task.Delay(_config.ReadInterval, stoppingToken);
            }
        }