private async Task ProcessEachFileToUploadThenDelete(string fileToProcess) { var stringBatchResponse = _fileTransferClient.DownloadFile(fileToProcess); var batchResponse = JsonConvert.DeserializeObject <BatchResponse>(stringBatchResponse); if (batchResponse?.Batch == null || batchResponse.Batch.BatchDate == DateTime.MinValue) { _aggregateLogger.LogInfo($"Could not process downloaded file to correct format [{fileToProcess}]"); return; } batchResponse.Batch.DateOfResponse = DateTime.UtcNow; var batchNumber = batchResponse.Batch.BatchNumber; var batchLogResponse = await _assessorServiceApi.GetGetBatchLogByBatchNumber(batchNumber); if (batchLogResponse?.Id == null) { _aggregateLogger.LogInfo($"Could not match an existing batch Log Batch Number [{batchNumber}]"); return; } if (!int.TryParse(batchNumber, out int batchNumberToInt)) { _aggregateLogger.LogInfo($"The Batch Number is not an integer [{batchNumber}]"); return; } var batch = new BatchData { BatchNumber = batchNumberToInt, BatchDate = batchResponse.Batch.BatchDate, PostalContactCount = batchResponse.Batch.PostalContactCount, TotalCertificateCount = batchResponse.Batch.TotalCertificateCount, PrintedDate = batchResponse.Batch.PrintedDate, PostedDate = batchResponse.Batch.PostedDate, DateOfResponse = batchResponse.Batch.DateOfResponse }; await _assessorServiceApi.UpdateBatchDataInBatchLog((Guid)batchLogResponse.Id, batch); _fileTransferClient.DeleteFile(fileToProcess); }