Пример #1
0
        public async Task FetchUpdatesAndStoreAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("Current {count} existing {type}s", _storage.All.Count(), typeof(T).Name);
            var maxUpdate = _storage.All.Max(_updateSelector);

            if (!maxUpdate.HasValue)
            {
                maxUpdate = new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero);
            }

            _logger.LogInformation("Loading new {type}s", typeof(T).Name);
            var products = await _fetcher.GetUpdatedSinceAsync(maxUpdate.Value, stoppingToken);

            if (stoppingToken.IsCancellationRequested)
            {
                return;
            }

            await _storage.AddRange(products);

            _logger.LogInformation("Storing newly fetched {type}s", typeof(T).Name);

            await _filesWriter.StoreFilesAsync(Path.Combine(_optionsAccessor.Value.GetFilePath(), _folder),
                                               stoppingToken);
        }