/// <summary> /// Initializes a new instance of the <see cref="PrintingEngineResult" /> class. /// </summary> /// <param name="uniqueFile">The <see cref="UniqueFile" /> that was printed.</param> /// <param name="filePrintResult">The <see cref="FilePrintResult" />.</param> /// <param name="jobStartTime">The time when the <see cref="PrintingEngine" /> began processing the print request.</param> /// <param name="jobEndTime">The time when the <see cref="PrintingEngine" /> finished processing the print request.</param> internal PrintingEngineResult(UniqueFile uniqueFile, FilePrintResult filePrintResult, DateTimeOffset jobStartTime, DateTimeOffset jobEndTime) { UniqueFileName = uniqueFile.Name; UniqueFileId = uniqueFile.Id; JobStartTime = jobStartTime; JobEndTime = jobEndTime; PrintStartTime = filePrintResult.PrintStartTime; PrintEndTime = filePrintResult.PrintEndTime; }
/// <summary> /// Prints the specified file to the specified <see cref="PrintQueue" />. /// </summary> /// <param name="file">The file to print.</param> /// <param name="printQueue">The <see cref="PrintQueue" /> to print the file to.</param> /// <param name="fileId">The <see cref="Guid" /> to use for the unique file name.</param> /// <returns>A <see cref="PrintingEngineResult" /> object representing the outcome of the print operation.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="file" /> is null. /// <para>or</para> /// <paramref name="printQueue" /> is null. /// </exception> public PrintingEngineResult Print(FileInfo file, PrintQueue printQueue, Guid fileId) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (printQueue == null) { throw new ArgumentNullException(nameof(printQueue)); } UniqueFile uniqueFile = null; try { LogStatus($"Printing {file.Name} to {printQueue.FullName}"); // Create a uniquely named file to identify the print job uniqueFile = UniqueFile.Create(file, fileId); // Create the file printer FilePrinter filePrinter = FilePrinterFactory.Create(uniqueFile); filePrinter.StatusChanged += (s, e) => StatusChanged?.Invoke(s, e); // Print the file and return the result DateTimeOffset jobStart = DateTimeOffset.Now; FilePrintResult printResult = filePrinter.Print(printQueue, PrintOptions); DateTimeOffset jobEnd = DateTimeOffset.Now; LogStatus($"Finished printing {file.Name}"); return(new PrintingEngineResult(uniqueFile, printResult, jobStart, jobEnd)); } finally { Task.Factory.StartNew(() => DeleteTemporaryFile(uniqueFile)); } }