Exemplo n.º 1
0
        private async Task <bool> IsNewDownloadLink(string downloadLink, CancellationToken cancellationToken)
        {
            var previousState = await _stateStore.GetStateAsync(StateKeyDownloadLink, cancellationToken);

            return(string.IsNullOrEmpty(previousState) ||
                   !previousState.Equals(downloadLink, StringComparison.InvariantCultureIgnoreCase));
        }
Exemplo n.º 2
0
        public async Task ProcessChangesAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Getting last date UKRLP was checked");
            var lastCheckedState = await _stateStore.GetStateAsync("LastChecked", cancellationToken);

            DateTime lastChecked;

            if (string.IsNullOrEmpty(lastCheckedState))
            {
                lastChecked = DateTime.Today;
                _logger.LogInformation("Never checked UKRLP for changes before. Starting from {ChangedSinceDate}",
                                       lastChecked.ToString("O"));
            }
            else
            {
                lastChecked = DateTime.Parse(lastCheckedState);
                _logger.LogInformation("Getting changes since {ChangedSinceDate}",
                                       lastChecked.ToString("O"));
            }

            var changedProviders = await _ukrlpApiClient.GetProvidersChangedSinceAsync(lastChecked, cancellationToken);

            _logger.LogInformation("Found {NumberOfProvidersChanged} changed providers since {ChangedSinceDate}",
                                   changedProviders.Length, lastChecked);

            lastChecked = DateTime.Now;

            foreach (var provider in changedProviders)
            {
                await _ukrlpDataReceiver.SendDataAsync(provider, cancellationToken);
            }

            await _stateStore.SetStateAsync("LastChecked", lastChecked.ToString("O"), cancellationToken);
        }