public async Task <List <ViewModel> > CheckServicesAsync() { var services = _dbService.GetServices(); List <ResponseServiceModel> responseServices = new List <ResponseServiceModel>(); foreach (var service in services) { responseServices.Add(await _httpService.CheckService(service)); } List <ViewModel> views = new List <ViewModel>(); foreach (var responseService in responseServices) { var view = new ViewModel { Id = responseService.ServiceId, Url = responseService.ServiceName, Availability = responseService.IsSuccessStatusCode ? Availability.Available.ToViewString() : Availability.NotAvailable.ToViewString(), Duration = responseService.Duration, FailCountPerDay = _requestDBService.GetFailCountPerTime(responseService.ServiceId, TimeSpan.FromHours(24)), FailCountPerHour = _requestDBService.GetFailCountPerTime(responseService.ServiceId, TimeSpan.FromHours(1)), }; var durationsHour = _requestDBService.GetDurationsPerTime(responseService.ServiceId, TimeSpan.FromHours(1)); var durationsDay = _requestDBService.GetDurationsPerTime(responseService.ServiceId, TimeSpan.FromHours(24)); if (responseService.Duration > _config.StandartDuration * 2f) { view.DurationDivClass = "text-error"; } if (durationsHour.Count() != 0) { if (durationsHour.Average() > _config.StandartDuration * 2f) { view.MaxHourDuration = durationsHour.Max(); } } if (durationsDay.Count() != 0) { if (durationsDay.Average() > _config.StandartDuration * 2f) { view.MaxDayDuration = durationsDay.Max(); } } views.Add(view); } return(views); }
private async void CheckServices(object state) { using (var scope = _serviceScopeFactory.CreateScope()) { IHttpService _httpService = scope.ServiceProvider.GetRequiredService <IHttpService>(); IDBService _dbService = scope.ServiceProvider.GetRequiredService <IDBService>(); IRequestDBService _requestDBService = scope.ServiceProvider.GetRequiredService <IRequestDBService>(); var services = _dbService.GetServices(); foreach (var service in services) { _requestDBService.SetData(await _httpService.CheckService(service)); } } }