/// <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> /// Uploads a unique (GUID appended) copy of the file to JetAdvantage /// Will throw an exception if the file is not confirmed at destination /// </summary> private void UploadUniqueFile(FileInfo fileInfo, PluginExecutionData data) { JetAdvantageUploadLog log = new JetAdvantageUploadLog(data); TitanAPI titanApi = new TitanAPI(_jetAdvantageProxy, _jetAdvantageURL); TitanUser user = new TitanUser(_activityData.LoginId, _activityData.LoginPassword); UniqueFile uniqueFile = UniqueFile.Create(fileInfo); UpdateStatus(string.Format("Created file {0}", uniqueFile.FullName)); FileInfo fi = uniqueFile.FileInfo; DateTime jobStart = DateTime.Now; log.CompletionStatus = "Starting"; log.DestinationUrl = _jetAdvantageProxy; log.FileName = uniqueFile.FullName; log.FileSentDateTime = jobStart; log.FileSizeSentBytes = fi.Length; log.FileType = fi.Extension; log.LoginId = user.EmailAddress; ExecutionServices.DataLogger.Submit(log); //bool success = titanApi.CheckJetAdvantageAvailability(_jetAdvantageURL, _jetAdvantageProxy); // test that the server is available by trying to access the destination var existingDocs = titanApi.GetPrintQueue(user); UpdateStatus(string.Format("Verified that we can access JetAdvantage servers {0}, {1}", _jetAdvantageProxy, _jetAdvantageURL)); try { var receivedDoc = titanApi.UploadDocument(user, uniqueFile); DateTime jobEnd = DateTime.Now; UpdateStatus(string.Format("Uploaded file {0}", uniqueFile.FullName)); log.CompletionStatus = "Success"; log.FileSizeReceivedBytes = receivedDoc.size; log.FileReceivedDateTime = jobEnd; log.CompletionDateTime = DateTime.Now; UpdateStatus("Submitting log info."); ExecutionServices.DataLogger.Update(log); UpdateStatus("After submitting log info."); } catch (Exception ex) { log.CompletionStatus = "Failed"; log.CompletionDateTime = System.DateTime.Now; ExecutionServices.DataLogger.Update(log); throw ex; } }
/// <summary> /// Parses the STF PrintJobId <see cref="Guid"/> out of the ePrint job file name. /// </summary> /// <param name="jobFileName"></param> /// <returns>STF PrintJobId <see cref="Guid"/></returns> private static Guid ParsePrintJobId(string jobFileName) { try { return(UniqueFile.ExtractId(jobFileName)); } catch (FormatException) { //TraceFactory.Logger.Error(ex); } return(Guid.Empty); }
private void LogPrintJobData(UniqueFile printJob, EPrintActivityData activityData) { PrintJobClientLog printJobClientLog = new PrintJobClientLog(_executionData, printJob, activityData.PrinterEmail, "ePrint", printJob.Id); try { ExecutionServices.DataLogger.Submit(printJobClientLog); } catch (Exception ex) { ExecutionServices.SystemTrace.LogError("Failed to log PrintJobClientLog data.", ex); } }
/// <summary> /// Initializes a new instance of the <see cref="VirtualPrinterJobLog" /> class. /// </summary> /// <param name="jobInfo">The <see cref="VirtualPrinterJobInfo" />.</param> /// <exception cref="ArgumentNullException"><paramref name="jobInfo" /> is null.</exception> public VirtualPrinterJobLog(VirtualPrinterJobInfo jobInfo) { if (jobInfo == null) { throw new ArgumentNullException(nameof(jobInfo)); } VirtualPrinterJobId = SequentialGuid.NewGuid(); PrintJobClientId = UniqueFile.ExtractId(jobInfo.PjlHeader.JobName); PjlJobName = jobInfo.PjlHeader.JobName; PjlLanguage = jobInfo.PjlHeader.Language; FirstByteReceivedDateTime = jobInfo.FirstByteReceived; LastByteReceivedDateTime = jobInfo.LastByteReceived; BytesReceived = jobInfo.BytesReceived; }
private static void DeleteTemporaryFile(UniqueFile file) { if (file != null) { try { Retry.WhileThrowing(() => File.Delete(file.FileInfo.FullName), 100, TimeSpan.FromSeconds(3), new[] { typeof(UnauthorizedAccessException), typeof(IOException) }); } catch (Exception ex) { // Don't allow the parent thread to crash if the delete is unsuccessful. LogWarn($"Unable to delete temporary file {file.FileInfo.FullName}: {ex.Message}"); } } }
private void LogPrintJob(PrintJobData job) { Guid printJobClientId = Guid.Empty; // If extracting the ID fails, then do not report data on this job try { if (!string.IsNullOrEmpty(job.Document)) { printJobClientId = UniqueFile.ExtractId(job.Document.ToUpperInvariant()); } } catch (FormatException) { TraceFactory.Logger.Warn("Bad document name: " + job.Document); // Do nothing. return; } if (printJobClientId == Guid.Empty) { return; } PrintServerJobLog logger = null; MonitoredQueueInfoCache printQueue = GetQueueInfo(job.PrinterName); if (printQueue != null) { logger = new PrintServerJobLog(printJobClientId, job, printQueue); } else { logger = new PrintServerJobLog(printJobClientId, job); } try { _dataLogger.SubmitAsync(logger); TraceFactory.Logger.Debug("Data posted to data log service."); } catch (Exception ex) { TraceFactory.Logger.Error("Error posting data to the data log service.", ex); } }
private List <UniqueFile> PrepareDocuments(int numberOf) { List <UniqueFile> attachments = new List <UniqueFile>(); for (int i = 0; i < numberOf; i++) { Document document = _executionData.Documents.GetRandom(); if (document != null) { FileInfo fileInfo = ExecutionServices.FileRepository.GetFile(document); //Create a Print Job attachments.Add(UniqueFile.Create(fileInfo)); } } return(attachments); }
/// <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)); } }