/// <summary> /// The business implementation of the job /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public override async Task Process(CancellationToken cancellationToken) { string startTime = $"{DateTime.UtcNow:hh:mm:ss}"; try { var reqMessage = _httpService.CreateHttpRequestMessage(_job); var responseMessage = await _httpService.SendAsync(reqMessage); var response = await responseMessage.Content.ReadAsStringAsync(); if (responseMessage.IsSuccessStatusCode) { _logger.LogInformation($"EStartEmpExportJob run at {startTime} completed. Response details:\n{response}"); } else { _logger.LogError($"EStartEmpExportJob run at {startTime} failed. Response details:\n{response}"); } } catch (Exception ex) { _logger.LogError($"An exception occured in the EStartEmpExportJob run at {startTime}. Expection details:\n{ex.Message}\n{ex.StackTrace}"); } }
/// <summary> /// The business implementation of the job /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public override async Task Process(CancellationToken cancellationToken) { var startTime = $"{DateTime.UtcNow:hh:mm:ss}"; try { var timeDetails = await _timeService.GetTimeDetails(_filters); if (!timeDetails.Any()) { _logger.LogInformation($"EStart export run at {startTime} doesn't have any matching timezones with their current times close to either of {_eStartService.GetTimesOfDay(_filters)}."); return; } var exportRequests = _eStartService.GenerateExportRequests(timeDetails); List <HttpRequestMessage> requestMessages = (from r in exportRequests select _httpService .CreateHttpRequestMessage(_job, JsonConvert.SerializeObject(r)) ).ToList(); var responseMessages = await _httpService.SendAsync(requestMessages); if (responseMessages.All(x => x.IsSuccessStatusCode)) { responseMessages.ForEach(async msg => { var requestString = await msg.RequestMessage.Content.ReadAsStringAsync(); var responseString = await msg.Content.ReadAsStringAsync(); _logger.LogInformation($"Request - \n{requestString}\n Response - {responseString}\n"); }); _logger.LogInformation($"EStart export run at {startTime} completed."); } else if (responseMessages.All(x => !x.IsSuccessStatusCode)) { responseMessages.Where(x => x.IsSuccessStatusCode).ToList().ForEach(async msg => { var requestString = await msg.RequestMessage.Content.ReadAsStringAsync(); var responseString = await msg.Content.ReadAsStringAsync(); _logger.LogInformation($"Request - \n{requestString}\n Response - {responseString}\n"); }); _logger.LogError($"EStart export run at {startTime} failed."); await LogFailedRequests(startTime, responseMessages); } else { responseMessages.Where(x => x.IsSuccessStatusCode).ToList().ForEach(async msg => { var requestString = await msg.RequestMessage.Content.ReadAsStringAsync(); var responseString = await msg.Content.ReadAsStringAsync(); _logger.LogInformation($"Request - \n{requestString}\n Response - {responseString}\n"); }); _logger.LogInformation($"EStart export run at {startTime} processed partially."); await LogFailedRequests(startTime, responseMessages); } } catch (Exception ex) { _logger.LogError($"An exception occured in the EStartExport run at {startTime}. Expection details:\n{ex.Message}\n{ex.StackTrace}"); } }
public async Task <ICollection <Employee> > GetEmployees() { HttpResponseMessage result = await httpService.ExecuteRequest(httpService.CreateHttpRequestMessage("https://masglobaltestapi.azurewebsites.net/api/Employees", HttpMethod.Get, null)); string data = await result.Content.ReadAsStringAsync(); return(string.IsNullOrEmpty(data) ? default(List <Employee>) : JsonConvert.DeserializeObject <List <Employee> >(data)); }