Exemplo n.º 1
0
        private async Task <List <FederalStateResponseModel> > HandleFederalStates(
            IReadOnlyCollection <Severity> severities,
            bool awaitSave,
            DateTime dateTime,
            CancellationToken cancellationToken)
        {
            List <FederalStateResponseModel> federalStates;

            try
            {
                federalStates = await _rkiWebService.GetFederalStates(cancellationToken);

                var statesConfig = await _statesConfigStorageService.GetEntry(cancellationToken);

                federalStates.ForEach(model =>
                {
                    model.InformationUrl = statesConfig.FirstOrDefault(x => x.StateId.ToString() == model.StateId)?.InformationUrl;
                    model.Severity       = model.CalculateSeverity(severities);
                });

                _logger.LogInformation($"FederalStates retrieved [{federalStates.Count}]");
            }
            catch (Exception ex)
            {
                throw new EbolappException("Error while retrieving federal state.", ex);
            }

            var task = _federalStateStorageService.AddEntry("DEU", federalStates, dateTime, cancellationToken);

            if (awaitSave)
            {
                await task;
            }

            return(federalStates);
        }
Exemplo n.º 2
0
        private async Task <List <DistrictResponseModel> > HandleDistricts(
            IReadOnlyCollection <Severity> severities,
            bool awaitSave,
            DateTime dateTime,
            CancellationToken cancellationToken)
        {
            List <DistrictResponseModel> districts;

            try
            {
                districts = await _rkiWebService.GetDistricts(cancellationToken);

                var areasConfig = await _areasConfigStorageService.GetEntry(cancellationToken);

                districts.ForEach(model =>
                {
                    model.InformationUrl = areasConfig.FirstOrDefault(x => x.AreaCode == model.AreaId)?.InformationUrl;
                    model.Severity       = model.CalculateSeverity(severities);
                });

                _logger.LogInformation($"Districts retrieved [{districts.Count}]");
            }
            catch (Exception ex)
            {
                throw new EbolappException("Error while retrieving districts.", ex);
            }

            var task = _districtStorageService.AddEntry("DEU", districts, dateTime, cancellationToken);

            if (awaitSave)
            {
                await task;
            }

            return(districts);
        }