Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void _watchers_IssueFound(object sender, PrinterIssueEventArgs e)
 {
     LogHelper.LogDebug();
     try
     {
         if (e != null)
         {
             PrinterTrouble pt = e.Issue;
             LogHelper.LogDebug(pt.Issue());
             if (pt != PrinterTrouble.None)
             {
                 APIWrapper.PrinterIssue(e.PrinterName, pt);
                 Notifier.Error(string.Format("Document can't be printed because of printer issue : {1}.{0}Administration has been notified about this issue.", Environment.NewLine, pt.Issue()));
             }
             else
             {
                 if (!string.IsNullOrWhiteSpace(e.Status))
                 {
                     //Notifier.Error(string.Format("Document can't be printed because of printer issue : {1}", Environment.NewLine, e.Status));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Notifier.Error(ex);
     }
 }
Пример #2
0
        /// PrinterStatus
        #region PrinterStatus

        /// <summary>
        /// Gets printer status of the specified printer
        /// </summary>
        /// <param name="printerName">printer name</param>
        /// <returns>printer status</returns>
        public static PrinterTrouble GetPrinterStatus(string host, string printerName, out string statusReport)
        {
            statusReport = "";
            PrinterTrouble printerTrouble = PrinterTrouble.None;

            try
            {
                PrintServer          printServer = new PrintServer(@"\\" + host);
                PrintQueueCollection printQueues = printServer.GetPrintQueues();
                foreach (PrintQueue pq in printQueues)
                {
                    if (pq.Name == printerName)
                    {
                        printerTrouble = SpotPrinterTroubles(ref statusReport, pq);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex);
            }

            return(printerTrouble);
        }
        /// <summary>
        /// Converts PrinterTrouble data to string
        /// </summary>
        /// <param name="issue">printer issue</param>
        /// <returns>issue string</returns>
        public static string Issue(this PrinterTrouble printerTrouble)
        {
            string issue = "";

            if (printerTrouble == PrinterTrouble.None)
            {
                return(issue);
            }

            if ((printerTrouble & PrinterTrouble.OutOfPaper) == PrinterTrouble.OutOfPaper)
            {
                issue += ", Out of Paper";
            }

            if ((printerTrouble & PrinterTrouble.OutOfToner) == PrinterTrouble.OutOfToner)
            {
                issue += ", Out of Toner";
            }

            if ((printerTrouble & PrinterTrouble.Offline) == PrinterTrouble.Offline)
            {
                issue += ", Offline";
            }

            if ((printerTrouble & PrinterTrouble.PaperJammed) == PrinterTrouble.PaperJammed)
            {
                issue += ", Paper jammed";
            }

            if ((printerTrouble & PrinterTrouble.Error) == PrinterTrouble.Error)
            {
                issue += ", Error";
            }

            if (string.IsNullOrWhiteSpace(issue))
            {
                return(null);
            }

            if (issue[0] == ',')
            {
                issue = issue.Substring(1).Trim();
            }

            return(issue);
        }
Пример #4
0
        /// <summary>
        /// Check for possible trouble states of a printer using its properties
        /// </summary>
        /// <param name="statusReport"></param>
        /// <param name="printQueue"></param>
        public static PrinterTrouble SpotPrinterTroubles(ref String statusReport, PrintQueue printQueue)
        {
            if (printQueue == null)
            {
                return(PrinterTrouble.None);
            }

            PrinterTrouble printerTrouble = PrinterTrouble.None;

            printQueue.Refresh();

            if (!(printQueue.HasToner))
            {
                printerTrouble |= PrinterTrouble.OutOfToner;
                statusReport    = statusReport + "Is out of toner. ";
            }

            if (printQueue.IsOutOfPaper)
            {
                printerTrouble |= PrinterTrouble.OutOfPaper;
                statusReport    = statusReport + "Is out of paper. ";
            }

            if (printQueue.IsOffline)
            {
                printerTrouble |= PrinterTrouble.Offline;
                statusReport    = statusReport + "Offline. ";
            }

            if (printQueue.IsInError)
            {
                printerTrouble |= PrinterTrouble.Error;
                statusReport    = statusReport + "Error. ";
            }

            if (printQueue.IsPaperJammed)
            {
                printerTrouble |= PrinterTrouble.PaperJammed;
                statusReport    = statusReport + "Paper jammed. ";
            }

            return(printerTrouble);
        }
Пример #5
0
        /// Init
        #region Init

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="printJob"></param>
        public PrintJobWatcher(PrintJobTitle printJobTitle)
        {
            if (printJobTitle == null)
            {
                return;
            }

            /*
             * if (printJob == null)
             *  return;
             *
             * if (printJob.PrintJob == null)
             *  return;*/

            PrintJobTitle  = printJobTitle;
            _printerStatus = PrinterTrouble.None;

            // initialize timer
            timer          = new Timer();
            timer.Enabled  = false;
            timer.Interval = ConfigData.Interval_TimerPrintJobWatcher;
            timer.Elapsed += timer_Elapsed;
        }
Пример #6
0
        /// <summary>
        /// Checks print job and printer status
        /// </summary>
        private void TimerCall()
        {
            timer.Enabled = false;

            bool jobfound   = false;
            bool hasTrouble = false;

            try
            {
                string statusReport = "";
                //_printerStatus |= PrintHelper.GetPrinterStatus(_printJob.ServerHost, _printJob.PrintJobTitle.PrinterName, out statusReport);
                _printerStatus |= PrintHelper.GetPrinterStatus(PrintJobTitle.Host, PrintJobTitle.PrinterName, out statusReport);

                if ((_printerStatus | PrinterTrouble.None) == PrinterTrouble.None)
                {
                    hasTrouble = false;
                }
                else
                {
                    hasTrouble = true;
                }

                // if issue found
                if (hasTrouble)
                {
                    // send data to server
                    //OnIssueFound(new PrinterIssueEventArgs(_printJob.PrintJobTitle.PrinterName, _printerStatus, statusReport));
                    OnIssueFound(new PrinterIssueEventArgs(PrintJobTitle.PrinterName, _printerStatus, statusReport));
                    OnCanBeDisposed(EventArgs.Empty);
                    return;
                }

                // find the job
                //foreach (var printJob in PrintHelper.GetPrintJobs(_printJob.ServerHost, _printJob.PrintJobTitle.PrinterName))
                foreach (var printJob in PrintHelper.GetPrintJobs(PrintJobTitle.Host, PrintJobTitle.PrinterName))
                {
                    //if (PrintHelper.ExtractDocumentName(printJob) == _printJob.PrintJobTitle.Document)
                    if (PrintHelper.ExtractDocumentName(printJob) == PrintJobTitle.Document)
                    {
                        jobfound = true;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                WPFNotifier.DebugError(ex);
            }

            // if job found
            if (jobfound)
            {
                // continue watching
                timer.Enabled = true;
            }
            else
            {
                // finish watching
                OnJobCompleted(new PrintJobDataEventArgs(null));
                OnCanBeDisposed(EventArgs.Empty);
            }
        }
Пример #7
0
 /// <summary>
 /// Sends printer issue if any exist
 /// </summary>
 /// <param name="printerName">printer name</param>
 /// <param name="issue">printer issue</param>
 public static void PrinterIssue(string machineName, string userName, string printerName, PrinterTrouble issue)
 {
     API.PrinterIssue(machineName, userName, printerName, issue.Issue());
 }
Пример #8
0
        /// Init
        #region Init

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="printerName">printer name</param>
        /// <param name="issue">issue</param>
        /// <param name="status">status</param>
        public PrinterIssueEventArgs(string printerName, PrinterTrouble issue, string status)
        {
            PrinterName = printerName;
            Issue       = issue;
            Status      = status;
        }