Example #1
0
        public async Task InitializeDatabase(CancellationToken cancellationToken = default)
        {
            await using var xml = await LoadData(_config.HistoricalDataUri);

            var xmlData = EnvelopeParser.Parse(xml);
            var total   = xmlData.Data.Value.Count * 32;
            var data    = ExchangeRatesConverter.Convert(xmlData);

            await InsertData(total, data, cancellationToken);
        }
Example #2
0
        public async Task LoadFreshData(CancellationToken cancellationToken = default)
        {
            var xmlLoadingTask      = LoadData(_config.FreshDataUri);
            var lastDateLoadingTask = _dbContext.Rates
                                      .OrderByDescending(x => x.Date)
                                      .Select(x => x.Date)
                                      .FirstAsync(cancellationToken);
            var       xml                = await xmlLoadingTask;
            var       xmlData            = EnvelopeParser.Parse(xml);
            const int numberOfCurrencies = 32;
            var       total              = xmlData.Data.Value.Count * numberOfCurrencies;
            var       data               = ExchangeRatesConverter.Convert(xmlData);
            var       lastDate           = await lastDateLoadingTask;

            await InsertData(total, data.TakeWhile(x => x.Date > lastDate), cancellationToken);
        }