private async Task UploadSamplePrintResponseFile() { var samplePrintResponse = new BatchData() { BatchNumber = 1, BatchDate = DateTime.Parse("2020-01-31T13:30:00.0000000Z"), PostalContactCount = 22, TotalCertificateCount = 48, ProcessedDate = DateTime.Parse("2020-02-03T15:30:00.0000000Z") }; var filename = "PrintBatchResponse-001-3101201330.json"; var path = $"{_printResponseDirectory}/Samples/{filename}"; await _blobFileTransferClient.UploadFile(JsonConvert.SerializeObject(samplePrintResponse), path); }
public async Task <List <CertificatePrintStatusUpdateMessage> > Execute() { Schedule schedule = null; List <CertificatePrintStatusUpdateMessage> printStatusUpdateMessages = null; try { _logger.LogInformation("PrintRequestCommand - Started"); schedule = await _scheduleService.Get(); if (schedule == null) { _logger.LogInformation("There is no print schedule which allows printing at this time"); return(null); } await _scheduleService.Start(schedule); var nextBatchReadyToPrint = await _batchService.BuildPrintBatchReadyToPrint(schedule.RunTime, _options.AddReadyToPrintLimit); if (nextBatchReadyToPrint != null) { if ((nextBatchReadyToPrint.Certificates?.Count ?? 0) == 0) { _logger.LogInformation("There are certificates ready to print at this time"); } else { nextBatchReadyToPrint.Status = CertificateStatus.SentToPrinter; nextBatchReadyToPrint.BatchCreated = DateTime.UtcNow; nextBatchReadyToPrint.CertificatesFileName = GetCertificatesFileName(nextBatchReadyToPrint.BatchNumber, nextBatchReadyToPrint.BatchCreated); var printOutput = _printCreator.Create(nextBatchReadyToPrint.BatchNumber, nextBatchReadyToPrint.Certificates); var fileContents = JsonConvert.SerializeObject(printOutput); nextBatchReadyToPrint.NumberOfCertificates = printOutput.Batch.TotalCertificateCount; nextBatchReadyToPrint.NumberOfCoverLetters = printOutput.Batch.PostalContactCount; nextBatchReadyToPrint.FileUploadStartTime = DateTime.UtcNow; var uploadDirectory = _options.Directory; var uploadPath = $"{uploadDirectory}/{nextBatchReadyToPrint.CertificatesFileName}"; await _externalFileTransferClient.UploadFile(fileContents, uploadPath); var archiveDirectory = _options.ArchiveDirectory; var archivePath = $"{archiveDirectory}/{nextBatchReadyToPrint.CertificatesFileName}"; await _internalFileTransferClient.UploadFile(fileContents, archivePath); nextBatchReadyToPrint.FileUploadEndTime = DateTime.UtcNow; printStatusUpdateMessages = await _batchService.Update(nextBatchReadyToPrint); await _notificationService.SendPrintRequest( nextBatchReadyToPrint.BatchNumber, nextBatchReadyToPrint.Certificates, nextBatchReadyToPrint.CertificatesFileName); } } await _scheduleService.Save(schedule); } catch (Exception ex) { try { _logger.LogError(ex, "PrintRequestCommand - Failed"); } finally { if (schedule != null && schedule.Id != Guid.Empty) { await _scheduleService.Fail(schedule); } } throw; } return(printStatusUpdateMessages); }