private void ProcessJobNotification(JobNotification jobNotification) { JobNotificationTypeEnum notificationType = jobNotification.NotificationType; String jobName = jobNotification.JobName; SpooledJob spooledJob = spoolMonitor.FindSpooledJob(jobName); ManagedPrintJob managedJob = null; if (spooledJob != null) { managedJob = new ManagedPrintJob(jobName); } if (notificationType == JobNotificationTypeEnum.JobCreated) { //if (!managedJob.IsPaused()) // managedJob.Pause(); } if (notificationType == JobNotificationTypeEnum.JobChanged) { // Verifica se terminou o spooling para então processar os dados do job if (!managedJob.IsSpooling() && !spooledJob.Processed) { // spooledJob.CopyFiles(@"C:\tempSpool\" + jobName.Split(new char[] { ',' })[0]); String jobInfo = PrintJobContext.GetJobInfo(spooledJob); WriteToLog(jobInfo); spooledJob.Processed = true; } } }
private void MenuItem1Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.InitialDirectory = DeviceHandler.GetSpoolDirectory(); fileDialog.Filter = "Spool Shadow File (*.shd)|*.shd|Todos os arquivos (*.*)|*.*"; // Exibe a caixa de seleção de arquivo e verifica o resultado da interação do usuário DialogResult openFileResult = fileDialog.ShowDialog(); if (openFileResult == DialogResult.Cancel) { return; } String shadowFilename = fileDialog.FileName; if (File.Exists(shadowFilename)) { SpooledJob spooledJob = new SpooledJob(shadowFilename, this); String jobName = spooledJob.ShadowFile.PrinterName + ", " + spooledJob.ShadowFile.JobId.ToString(); ManagedPrintJob managedJob = new ManagedPrintJob(jobName); String jobInfo = GetJobInfo(spooledJob, managedJob); jobInfoBox.Invoke(new PerformTextOutputDelegate(LogJobInfo), jobInfo); } }
private String GetJobInfo(SpooledJob spooledJob, ManagedPrintJob managedJob) { Dictionary <String, Object> jobSummary = PrintJobContext.GetJobSummary(spooledJob); if (jobSummary == null) { return(String.Empty); } String jobInfo = "Print Job (" + managedJob.Name + " ) " + "Status: " + (JobStatusEnum)managedJob.StatusMask + Environment.NewLine + "Hora: " + DateFormat.Adjust((DateTime)jobSummary["jobTime"], true) + Environment.NewLine + "UserName: "******"userName"] + Environment.NewLine + "PrinterName: " + jobSummary["printerName"] + Environment.NewLine + "DocumentName: " + '\"' + jobSummary["documentName"] + '\"' + Environment.NewLine + "Page Count: " + jobSummary["pageCount"] + Environment.NewLine + "Copy Count: " + jobSummary["copyCount"] + Environment.NewLine + "Duplex: " + jobSummary["duplex"] + Environment.NewLine + "Color: " + jobSummary["color"] + Environment.NewLine + "File size: " + jobSummary["spoolFileSize"] + Environment.NewLine; return(jobInfo); }