/// <summary>
        /// Constructor. Real Printer Mode.
        /// </summary>
        /// <param name="data">print job data</param>
        public PrintingControlModel(PrintJobData data)
        {
            IsBlockedMode = true;
            PSFileName    = null;
            PrintJobData  = data;
            Title         = PrintJobData.PrintJobTitle;
            if (Title == null)
            {
                Title = new PrintJobTitle(null, "unknown", null, null, -1);
            }

            NumberOfPages = Title.TotalPages;

            // set the chosen printer accordingly
            ChosenPrinter             = new Printer();
            ChosenPrinter.Name        = Title.PrinterName;
            ChosenPrinter.DisplayName = Title.PrinterName;
            IsControlsEnabled         = true;
            SelectedPrinterIndex      = -1;
            Printers = new Printers();
            //Printers.Add(ChosenPrinter);

            // initialize timer
            timerAllowedToPrint          = new System.Windows.Forms.Timer();
            timerAllowedToPrint.Enabled  = false;
            timerAllowedToPrint.Interval = ConfigData.Interval_TimerAllowedToResumeJob;
            timerAllowedToPrint.Tick    += timerAllowedToPrint_Tick;

            UpdateDataDevMode();
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="printJobData"></param>
 /// <param name="raise"></param>
 private void XXX(PrintJobData printJobData, bool raise)
 {
     LogHelper.LogDebug(_host + " : " + "printersToPauseAndShow : " + _printersToPauseAndShow.Count);
     foreach (var _printerToPauseAndShow in _printersToPauseAndShow)
     {
         LogHelper.LogDebug(_printerToPauseAndShow);
         if (IsSamePrinter(printJobData.PrintJobTitle.PrinterName, _printerToPauseAndShow, _jobHost))
         {
             LogHelper.LogDebug(_host + " : " + "Same printer, pages " + printJobData.PrintJobTitle.TotalPages.ToString());
             if (printJobData.PrintJobTitle.TotalPages > 0)
             {
                 lock (_titlesProcessed)
                 {
                     if (!_titlesProcessed.HasTitleAndMorePages(printJobData))
                     {
                         _titlesProcessed.RemoveTitle(printJobData.PrintJobTitle);
                         _titlesProcessed.Add(printJobData.PrintJobTitle);
                         LogHelper.LogDebug(_host + " : " + "titlesProcessed : " + _titlesProcessed.Count);
                         //PrintHelper.PausePrintJob(printJobData.PrintJob, _host);
                         if (raise)
                         {
                             OnPrintJobPaused(new PrintJobDataEventArgs(printJobData));
                         }
                     }
                 }
             }
             return;
         }
     }
 }
Example #3
0
        public void LaunchPrintControl(PrintJobData printJob)
        {
            LogHelper.LogDebug("Launch Form " + printJob.PrintJobTitle);
            _printJob = printJob;

            /*
             * try
             * {
             *  MainForm.BeginInvoke((MethodInvoker)delegate
             *  {
             *      foreach (var f in listF)
             *      {
             *          LogHelper.LogDebug("Seek Form");
             *          if (f.PrintJobData.PrintJobTitle.Equals(printJob.PrintJobTitle))
             *          {
             *              LogHelper.LogDebug("Form found");
             *              f.UpdateData(printJob);
             *              return;
             *          }
             *      }
             *
             *      if (!PrintHelper.HasPrintJob(printJob.ServerHost, printJob.PrintJobTitle))
             *          return;
             *
             *      PrintingControlForm form = new PrintingControlForm(_printJob);
             *      listF.Add(form);
             *      form.Closed += form_Closed;
             *      form.ShowDialog(MainForm);
             *  });
             * }
             * catch (Exception ex)
             * {
             *  Notifier.Error(ex);
             * }*/
        }
Example #4
0
        /// <summary>
        /// Updates print job data with the new data.
        /// </summary>
        /// <param name="data">new data</param>
        public void UpdateData(PrintJobData data)
        {
            // update data
            _model.UpdateData(data);

            // update UI
            Update();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="host"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static bool UpdateJobData(string host, ref PrintJobData data)
        {
            if (data == null)
            {
                return(false);
            }

            if (data.PrintJobTitle == null)
            {
                return(false);
            }

            if (String.IsNullOrWhiteSpace(data.PrintJobTitle.PrinterName))
            {
                return(false);
            }

            bool updated = false;

            try
            {
                string printerName = data.PrintJobTitle.PrinterName;
                if (!String.IsNullOrWhiteSpace(host))
                {
                    printerName = data.PrintJobTitle.PrinterName.Replace(host, "").Trim();
                    if (printerName[0] == '\\')
                    {
                        printerName = printerName.Substring(1);
                    }

                    LogHelper.LogDebug("MAIN " + host + " printerName " + printerName);
                }
                else
                {
                    LogHelper.LogDebug("MAIN local printerName " + printerName);
                }

                updated = UpdateJobData(ref data, printerName, host);

                /*
                 * if (!updated)
                 * {
                 *  int pos = data.PrintJobTitle.PrinterName.LastIndexOf("\"");
                 *  string nnn = null;
                 *  if (pos > 0)
                 *      nnn = data.PrintJobTitle.PrinterName.Substring(pos + 1);
                 *  LogHelper.LogDebug("nnn " + nnn);
                 *  updated = UpdateJobData(ref data, nnn, host);
                 * }*/
            }
            catch (Exception ex)
            {
                WPFNotifier.Error(ex);
            }

            return(updated);
        }
        public static bool CancelAllPrintJobs(PrintJobData printJob)
        {
            if (printJob == null)
            {
                return(false);
            }

            return(CancelAllPrintJobs(printJob.PrintJobTitle, printJob.ServerHost));
        }
        /// LogPrint
        #region LogPrint

        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="printJob"></param>
        public static void LogPrint(string fileName, PrintJobData printJob)
        {
            if (printJob == null)
            {
                return;
            }

            LogPrint(fileName, printJob.PrintJobTitle.PrinterName, printJob.PrintJobTitle.Document, printJob.Color, 1, printJob.Duplex);
        }
        /// UpdateJobData
        #region UpdateJobData

        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="printerName"></param>
        /// <param name="host"></param>
        /// <returns></returns>
        private static bool UpdateJobData(ref PrintJobData data, string printerName, string host)
        {
            bool updated = false;

            try
            {
                LogHelper.LogDebug("INNER START " + printerName);
                PrintQueue queue = GetPrintQueue(printerName, host);
                if (queue == null)
                {
                    return(false);
                }

                queue.Refresh();
                if (queue.NumberOfJobs > 0)
                {
                    bool quit = false;
                    while (!quit)
                    {
                        try
                        {
                            LogHelper.LogDebug("jobs " + queue.GetPrintJobInfoCollection().Count() + " | " + queue.NumberOfJobs);
                            foreach (PrintSystemJobInfo info in queue.GetPrintJobInfoCollection())
                            {
                                info.Refresh();
                                string docName       = info.Name;
                                int    NumberOfPages = info.NumberOfPages;
                                int    xxx           = info.NumberOfPagesPrinted;
                                LogHelper.LogDebug("Printing " + info.IsPrinting + " | Paused " + info.IsPaused + " | Spooling " + info.IsSpooling + " | IsDeleting " + info.IsDeleting);
                                LogHelper.LogDebug("pages " + NumberOfPages + " printed " + xxx);
                                if (data.PrintJobTitle.Document == docName && data.PrintJobTitle.TotalPages < xxx)
                                {
                                    data.PrintJobTitle.TotalPages = xxx;
                                    updated = true;
                                }
                            }

                            quit = true;
                        }
                        catch (Exception ex)
                        {
                            queue.Refresh();
                            LogHelper.LogDebug("refresh");
                            WPFNotifier.Error(ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WPFNotifier.Error(ex);
            }

            LogHelper.LogDebug("INNER END " + printerName);
            return(updated);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="printJob"></param>
 private void ResumeJob(PrintJobData printJob)
 {
     SetStatus("Printing");
     MainController.Singleton.AddWatcher(printJob);
     MainController.Singleton.SkipDocument(printJob.PrintJobTitle);
     PrintHelper.ResumePrintJob(printJob, printJob.ServerHost);
     PrintHelper.LogPrint(ConfigData.FilePath_PrintLog, printJob);
     PrintJobData = null;
     Close();
 }
        /// <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();
        }
 private void PrintJobFinished(Guid printJobId, PrintJobData printJobData, AutoResetEvent autoResetEvent)
 {
     TraceFactory.Logger.Debug("PrintMonitorService.PrintJobFinished Current JobId = " + printJobData.Document + " - Passed in Job Id = " + printJobId);
     TraceFactory.Logger.Debug("PrintMonitorService.PrintJobFinished In the PrintMonitorService.PrintJobFinished at " + DateTime.Now.ToString());
     if (!string.IsNullOrEmpty(printJobData.Document) && printJobData.Document.Contains(printJobId.ToString()))
     {
         TraceFactory.Logger.Debug("Getting ready to call Set in the PrintMonitorService.PrintJobFinished at " + DateTime.Now.ToString());
         autoResetEvent.Set();
         TraceFactory.Logger.Debug("After the to call Set in the PrintMonitorService.PrintJobFinished at " + DateTime.Now.ToString());
     }
     TraceFactory.Logger.Debug("Finished with the PrintMonitorService.PrintJobFinished at " + DateTime.Now.ToString());
 }
        /// <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);
            }
        }
Example #13
0
        bool IVirtualPrinterClient.PrintJob(PrintJobData printJobData)
        {
            DialogResult dlgRes = mainFrm.ShowDialog();

            if (dlgRes != DialogResult.OK)
            {
                return(false);
            }
            Encoding enc = Encoding.Unicode;

            printJobData.UserData = enc.GetBytes(mainFrm.GetData());

            // Or false to abort the printing
            return(true);
        }
        /// Methods
        #region Methods

        /// <summary>
        /// Checks if the watcher is watching specified job
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool IsWatchingThisJob(PrintJobData data)
        {
            if (data == null)
            {
                return(false);
            }

            //if (_printJob.PrintJobTitle.PrinterName == data.PrintJobTitle.PrinterName && _printJob.PrintJobTitle.Document == data.PrintJobTitle.Document)
            if (PrintJobTitle.Equals(data.PrintJobTitle))
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Resets skip data
        /// </summary>
        /// <param name="data">data to be clear</param>
        public void ResetSkip(PrintJobData data)
        {
            if (data == null)
            {
                return;
            }

            if (data.PrintJobTitle == null)
            {
                return;
            }

            LogHelper.Log("ResetSkip : " + data.PrintJobTitle.ToString());
            ResetSkip(data.PrintJobTitle.PrinterName, data.PrintJobTitle.Document, data.PrintJobTitle.Owner, data.PrintJobTitle.Host, data.PrintJobTitle.JobID);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="printJob"></param>
        private void ResumeJob(PrintJobData printJob)
        {
            // check if it's Demo mode
            if (IsTestMode)
            {
                return;
            }

            SetStatus("Printing");
            MainController.Singleton.AddWatcher(printJob);
            MainController.Singleton.SkipDocument(printJob.PrintJobTitle);
            PrintHelper.ResumePrintJob(printJob, printJob.ServerHost);
            PrintHelper.LogPrint(ConfigData.FilePath_PrintLog, printJob);
            PrintJobData = null;
            Close();
        }
Example #17
0
        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 bool CanSkip2(PrintJobData printJobData, bool raise = false)
        {
            // check printer of the job
            foreach (var _allowedPrinterToSkip in _allowedPrintersToSkip)
            {
                if (_allowedPrinterToSkip == printJobData.PrintJobTitle.PrinterName)
                {
                    lock (_allowedPrintersTitles)
                    {
                        if (!_allowedPrintersTitles.HasTitle(printJobData))
                        {
                            _allowedPrintersTitles.Add(printJobData);
                        }
                    }

                    return(true);
                }
            }

            LogHelper.LogDebug(printJobData.PrintJobTitle.Host + " | " + printJobData.PrintJobTitle.Owner + " | raise : " + raise);

            // check the host of the job
            string host = printJobData.PrintJobTitle.Host;

            LogHelper.LogDebug(_host + " : " + "host of the job " + host + " | current host " + _jobHost);
            if (!string.IsNullOrWhiteSpace(host))
            {
                if (host != @"\\" + _jobHost && host != _jobHost && _jobHost != @"\\" + host)
                {
                    return(true);
                }
            }

            // check the user of the job
            string user = printJobData.PrintJobTitle.Owner;

            LogHelper.LogDebug(_host + " : " + "user of the job " + user + " | current user " + _user);
            if (!string.IsNullOrWhiteSpace(user))
            {
                if (user != _user)
                {
                    return(true);
                }
            }

            return(false);
        }
 /// <summary>
 /// Tries to resume the print job first time
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="printJob"></param>
 void ResumeJobFirstTry(PrintJobData printJob)
 {
     if (ConfigData.Config_DontCheckUserBalance)
     {
         ResumeJob(printJob);
     }
     else
     {
         SetStatus("Checking user balance");
         var res = APIWrapper.CheckIfCanPrint(Environment.MachineName, Environment.UserName, printJob.Color, NumberOfPrints, printJob.PrintJobTitle.PrinterName);
         if (res == null)
         {
             WPFNotifier.Warning(string.Format("No response from server but still printing."));
             ResumeJob(printJob);
         }
         else
         {
             if (res.Result)
             {
                 if (res.AllowedToPrint)
                 {
                     ResumeJob(printJob);
                 }
                 else
                 {
                     SetStatus("Not allowed to print");
                     if (WPFNotifier.Question(string.Format("You are not allowed to print at the current time.{0}Reason: {1}{0}{2}", Environment.NewLine, res.Reason, "Do you want to leave the printing (Yes) or continue waiting (No)?")) == MessageBoxResult.Yes)
                     {
                         CancelJob(printJob);
                     }
                     else
                     {
                         StartTimerAllowedToPrint();
                     }
                 }
             }
             else
             {
                 WPFNotifier.Warning(string.Format("Not successful request CheckIfCanPrint."));
             }
         }
     }
 }
Example #20
0
        /// <summary>
        /// Adds watcher to the specified print job data
        /// </summary>
        /// <param name="data"></param>
        public void AddWatcher(PrintJobData data)
        {
            if (data == null)
            {
                return;
            }

            if (data.PrintJobTitle == null)
            {
                return;
            }

            LogHelper.LogDebug(data.PrintJobTitle.ToString());

            if (_watchers != null)
            {
                _watchers.AddWatcher(new PrintJobWatcher(data.PrintJobTitle));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mewPrintJobs_EventDeleted(object sender, System.Management.EventArrivedEventArgs e)
        {
            //if (ConfigData.Config_InterceptPrintJobAndCancel)
            //return;

            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 (CanSkip2(printJobData))
                {
                    return;
                }

                lock (_titlesProcessed)
                    _titlesProcessed.RemoveTitle(printJobData);

                //lock (_allowedPrintersTitles)
                //_allowedPrintersTitles.RemoveTitle(printJobData);

                ResetSkip(printJobData);

                OnPrintJobCompleted(new PrintJobDataEventArgs(printJobData));
            }
            catch (Exception ex)
            {
                LogHelper.LogDebug(ex);
            }
        }
Example #22
0
        public JobHolder(int jobID, byte[] bytes, RasterCodecs codec, PrintJobData jobData, string fontPath)
        {
            _jobID   = jobID;
            _codec   = codec;
            _jobData = jobData;
            _saving  = false;

            Encoding unicode = Encoding.Unicode;

            string strBytes = unicode.GetString(bytes);
            int    nIndex;

            nIndex = strBytes.IndexOf("---");
            _saved = false;

            _format   = strBytes.Substring(0, nIndex);
            strBytes  = strBytes.Substring(nIndex + 3);
            _savename = strBytes;

            _fontPath = fontPath;
        }
 public void CheckFilledData(PrintJobData newData)
 {
     if (TimeStarted != newData.TimeStarted) {
         Status = newData.Status;
         Pages = newData.Pages;
         Size = newData.Size;
         User = newData.User;
         MachineName = newData.MachineName;
         DocumentName = newData.DocumentName;
         TimeElapsed = newData.TimeElapsed;
         TimeStarted = newData.TimeStarted;
     }
     else {
         if (newData.Pages > Pages)
             Pages = newData.Pages;
         if (newData.Size > Size)
             Size = newData.Size;
         Status = newData.Status;
         TimeElapsed = newData.TimeElapsed;
     }
 }
Example #24
0
        /// <summary>
        /// Adds watcher to the specified print job data
        /// </summary>
        /// <param name="data"></param>
        public void AddWatcher(PrintJobData data)
        {
            // check data
            if (data == null)
            {
                return;
            }

            // check title
            if (data.PrintJobTitle == null)
            {
                return;
            }

            LogHelper.LogDebug(data.PrintJobTitle.ToString());

            // check watchers
            if (_watchers != null)
            {
                // add watcher for the specified title
                _watchers.AddWatcher(new PrintJobWatcher(data.PrintJobTitle));
            }
        }
        /// <summary>
        /// Removes watcher
        /// </summary>
        /// <param name="data"></param>
        public void RemoveWatcher(PrintJobData data)
        {
            if (data == null)
            {
                return;
            }

            PrintJobWatcher pjw = null;

            foreach (var watcher in this)
            {
                if (watcher != null)
                {
                    if (watcher.IsWatchingThisJob(data))
                    {
                        pjw = watcher;
                        return;
                    }
                }
            }

            watcher_CanBeDisposed(pjw, EventArgs.Empty);
        }
        /// <summary>
        /// Updates data.
        /// </summary>
        /// <param name="data">updated data to be used</param>
        public void UpdateData(PrintJobData data)
        {
            // check data
            if (data == null)
            {
                LogHelper.LogDebug("Update data but nothing received");
                return;
            }

            try
            {
                LogHelper.LogDebug("Update data, pages " + data.PrintJobTitle.TotalPages);

                // update data if more pages found
                if (data.PrintJobTitle.TotalPages > PrintJobData.PrintJobTitle.TotalPages)
                {
                    LogHelper.LogDebug("Current pages " + PrintJobData.PrintJobTitle.TotalPages);

                    // set data
                    PrintJobData = data;

                    // update values
                    Title         = data.PrintJobTitle;
                    NumberOfPages = data.PrintJobTitle.TotalPages;

                    // set status
                    SetStatus("Ready to print");
                }
            }
            catch (Exception ex)
            {
                WPFNotifier.Error(ex);
            }

            UpdateDataDevMode();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="printJobData"></param>
        /// <param name="raise"></param>
        /// <returns></returns>
        private bool CanSkip(PrintJobData printJobData, bool raise = false)
        {
            // check printer of the job
            foreach (var _allowedPrinterToSkip in _allowedPrintersToSkip)
            {
                if (_allowedPrinterToSkip == printJobData.PrintJobTitle.PrinterName)
                {
                    lock (_allowedPrintersTitles)
                    {
                        if (!_allowedPrintersTitles.HasTitle(printJobData))
                        {
                            _allowedPrintersTitles.Add(printJobData);
                            OnAllowedTitleAdded(new PrintJobDataEventArgs(printJobData));

                            /*
                             * while (true)
                             * {
                             *  var jobInfo2 = CubiclesPrinterLib.Win32.Print.PrintJob.GetJobInfo(printJobData.RemotePrinterName, printJobData.PrintJobTitle.JobID);
                             *  if (jobInfo2 != null)
                             *      printJobData.NumberOfCopies = jobInfo2.dmOut.dmCopies;
                             * }*/
                        }
                    }

                    return(true);
                }
            }

            LogHelper.LogDebug(printJobData.PrintJobTitle.Host + " | " + printJobData.PrintJobTitle.Owner + " | raise : " + raise);

            // check the host of the job
            string host = printJobData.PrintJobTitle.Host;

            LogHelper.LogDebug(_host + " : " + "host of the job " + host + " | current host " + _jobHost);
            if (!string.IsNullOrWhiteSpace(host))
            {
                if (host != @"\\" + _jobHost && host != _jobHost && _jobHost != @"\\" + host)
                {
                    return(true);
                }
            }

            // check the user of the job
            string user = printJobData.PrintJobTitle.Owner;

            LogHelper.LogDebug(_host + " : " + "user of the job " + user + " | current user " + _user);
            if (!string.IsNullOrWhiteSpace(user))
            {
                if (user != _user)
                {
                    return(true);
                }
            }

            LogHelper.LogDebug(_host + " : " + "Check " + printJobData.PrintJobTitle.Document + " | " + _titlesToSkip.Count);

            lock (_titlesToSkip)
            {
                if (_titlesToSkip != null && _titlesToSkip.Count > 0)
                {
                    LogHelper.LogDebug(_host + " : " + "Titles");
                    // check the document of the job
                    if (_titlesToSkip.HasTitle(printJobData))
                    {
                        LogHelper.LogDebug(_host + " : " + "Has title " + printJobData.PrintJobTitle.Document);
                        //if (raise)
                        //OnPrintJobStarted(new PrintJobDataEventArgs(printJobData));
                        return(true);
                    }
                }
            }

            LogHelper.LogDebug(_host + " : " + "Check Quit");

            return(false);
        }
Example #28
0
        public void _printer_JobEvent(object sender, JobEventArgs e)
        {
            if (e.JobEventState == EventState.JobStart)
            {
                _btnCancel.Enabled = true;
                _btnChange.Enabled = false;

                this.BringToFront();
                this.Focus();

                PrintJobData jobData = _printer.RemoteData;
                if (_printer.RemoteData != null)
                {
                    _jobHolder = new JobHolder(e.JobID, jobData.UserData, _codec, jobData, _fontPath);

                    _jobHolder._message = "( " + _jobHolder._jobData.IPAddress + " ) Job name " +
                                          jobData.PrintJobName + " Job ID " + jobData.JobID;

                    _nIndex = _lstBoxLog.Items.Add(_jobHolder);
                }
                else
                {
                    _jobHolder = new JobHolder(e.JobID, _codec, _fontPath);

                    _jobHolder._message = "Job Received With No Extra Information ( Job ID  " + e.JobID + " )";
                    _nIndex             = _lstBoxLog.Items.Add(_jobHolder);
                }
            }
            else if (e.JobEventState == EventState.JobEnd)
            {
                JobHolder tmpHolder = null;
                for (int i = 0; i < _lstBoxLog.Items.Count; i++)
                {
                    if (_lstBoxLog.Items[i].GetType() != typeof(JobHolder))
                    {
                        continue;
                    }

                    tmpHolder = (JobHolder)_lstBoxLog.Items[i];
                    if (tmpHolder._jobID == e.JobID)
                    {
                        _jobHolder = tmpHolder;
                        break;
                    }
                }

                if (_jobHolder != null)
                {
                    _btnCancel.Enabled = false;
                    this.BringToFront();
                    this.Focus();

                    string strMessage = "";

                    //Check if Job has client custom data
                    if (_jobHolder._jobData != null)
                    {
                        strMessage = "( " + _jobHolder._jobData.IPAddress + " ) Saving " + _jobHolder._format + " file, please wait ... ";
                    }
                    else
                    {
                        strMessage = "( No Extra Information ) Saving " + _jobHolder._format + " file, please wait ... ";
                    }

                    _jobHolder._message       = strMessage;
                    _lstBoxLog.Items[_nIndex] = _jobHolder;

                    //Get embedded fonts related to the Job ID
                    string[] arrFonts = _printer.GetEmbeddedFonts(_jobHolder._fontPath, e.JobID);
                    _jobHolder.SetFonts(arrFonts);

                    //Save on a different thread
                    ParameterizedThreadStart pStart = new ParameterizedThreadStart(DoSave);
                    Thread tSaving = new Thread(pStart);
                    tSaving.Start(new object[] { _jobHolder, _nIndex });
                    _jobHolder = null;
                }
            }
        }
        /// Methods
        #region Methods

        /// <summary>
        /// Updates data with the new one.
        /// </summary>
        /// <param name="data">new data</param>
        public void UpdateData(PrintJobData data)
        {
            // update data
            _viewModel.UpdateData(data);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="title">print job title</param>
 public PrintingControlWindow(PrintJobData title)
     : this()
 {
     // create view model
     _viewModel = new PrintingControlViewModel(this, new PrintingControlModel(title));
 }
        /// <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);
            }
        }