/// <summary> /// Cancels print job /// </summary> /// <param name="printJob"></param> private void CancelJob(PrintJobData printJob) { if (printJob == null) { return; } SetStatus("Cancelling print job"); //PrintHelper.CancelPrintJob(printJob); PrintHelper.CancelAllPrintJobs(printJob); Close(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mewPrintJobs_EventSet(object sender, System.Management.EventArrivedEventArgs e) { if (!_doWatching) { return; } try { // get arrived print job ManagementBaseObject printJob = (ManagementBaseObject)e.NewEvent.Properties["TargetInstance"].Value; if (printJob == null) { return; } PrintJobData printJobData = new PrintJobData(printJob, _host); LogHelper.LogDebug(_host + " : " + printJobData.PrintJobTitle + " | " + printJobData.JobStatus); if (CanSkip(printJobData)) { if (printJobData.JobStatus.JobStatus.HasFlag(PrintJobStatusEnum.Deleting) || printJobData.JobStatus.JobStatus == (PrintJobStatusEnum.Deleting | PrintJobStatusEnum.Error)) { //LogHelper.LogDebug(_host + " : Reset Skip " + printJobData.PrintJobTitle); //ResetSkip(printJobData); } return; } if (ConfigData.Config_InterceptPrintJobAndCancel) { PrintHelper.CancelAllPrintJobs(printJob, _host); } else { if (printJobData.JobStatus.JobStatus == PrintJobStatusEnum.Paused || printJobData.JobStatus.JobStatus == PrintJobStatusEnum.Printing || printJobData.JobStatus.JobStatus == (PrintJobStatusEnum.Paused | PrintJobStatusEnum.Printing)) { XXX(printJobData, true); } } } catch (Exception ex) { LogHelper.LogDebug(ex); } }
/// <summary> /// Print event arrived /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mewPrintJobs_JobArrived(object sender, EventArrivedEventArgs e) { if (!_doWatching) { return; } try { // get arrived print job ManagementBaseObject printJob = (ManagementBaseObject)e.NewEvent.Properties["TargetInstance"].Value; if (printJob == null) { return; } PrintJobData printJobData = new PrintJobData(printJob, _host); LogHelper.LogDebug(_host + " : " + printJobData.PrintJobTitle + " | " + printJobData.JobStatus); if (CanSkip(printJobData, false)) { //ResetSkip(printJobData); //OnPrintJobStarted(new PrintJobDataEventArgs(printJobData)); return; } foreach (var _printerToPauseAndShow in _printersToPauseAndShow) { if (IsSamePrinter(_printerToPauseAndShow, printJobData.PrintJobTitle.PrinterName, _jobHost)) { if (ConfigData.Config_InterceptPrintJobAndCancel) { if (printJobData.PrintJobTitle.TotalPages > 0) { LogHelper.LogDebug(_host + " : TotalPages " + printJobData.PrintJobTitle.TotalPages); } // this job has to be intercepted //PrintHelper.CancelPrintJob(printJob); PrintHelper.CancelAllPrintJobs(printJob, _host); OnPrintJobCancelled(new PrintJobDataEventArgs(printJobData)); //if (_host != "ADSERVER") //WPFNotifier.Warning(string.Format("You are not allowed to choose this printer.{0}You have to use {1} or {2} instead.{0}Printing cancelled.", Environment.NewLine, ConfigData.PrinterName, ConfigData.PrinterName2)); return; } else { PrintHelper.PausePrintJob(printJob, _host); } } } /* * // this job has to be intercepted * PrintHelper.CancelPrintJob(printJob); * WPFNotifier.Warning(string.Format("You are not allowed to choose this printer.{0}You have to use {1} instead.{0}Printing cancelled.", Environment.NewLine, ConfigData.PrinterName));*/ } catch (Exception ex) { WPFNotifier.Error(ex); } }