Exemplo n.º 1
0
        private static Status CancelJob(PrintQueue printQueue, string uniqueFileName)
        {
            // If you do not "refresh" the print queue, then getting information about the jobs will fail.
            printQueue.Refresh();
            PrintJobInfoCollection jobs = printQueue.GetPrintJobInfoCollection();

            // Extension is pulled out because some applications omit the file extension when it creates the job name.
            string             fileName = Path.GetFileNameWithoutExtension(uniqueFileName);
            PrintSystemJobInfo jobInfo  = jobs.FirstOrDefault(j => j.Name.Contains(fileName));

            jobInfo?.Cancel();

            //wait for 20 seconds to check if the job got deleted
            DateTime expireTime = DateTime.Now + TimeSpan.FromSeconds(20);

            while (jobInfo.IsDeleting && DateTime.Now < expireTime)
            {
                Thread.Sleep(100);
            }

            if (jobInfo.IsDeleted)
            {
                return(Status.Passed);
            }
            return(Status.Failed);
        }
Exemplo n.º 2
0
        }//end SpotTroubleUsingJobAttributes

        // </SnippetSpotTroubleUsingJobAttributes>

        //<SnippetHandlePausedJob>
        internal static void HandlePausedJob(PrintSystemJobInfo theJob)
        {
            // If there's no good reason for the queue to be paused, resume it and
            // give user choice to resume or cancel the job.
            Console.WriteLine("The user or someone with administrative rights to the queue" +
                              "\nhas paused the job or queue." +
                              "\nResume the queue? (Has no effect if queue is not paused.)" +
                              "\nEnter \"Y\" to resume, otherwise press return: ");
            String resume = Console.ReadLine();

            if (resume == "Y")
            {
                theJob.HostingPrintQueue.Resume();

                // It is possible the job is also paused. Find out how the user wants to handle that.
                Console.WriteLine("Does user want to resume print job or cancel it?" +
                                  "\nEnter \"Y\" to resume (any other key cancels the print job): ");
                String userDecision = Console.ReadLine();
                if (userDecision == "Y")
                {
                    theJob.Resume();
                }
                else
                {
                    theJob.Cancel();
                }
            } //end if the queue should be resumed
        }     //end HandlePausedJob
Exemplo n.º 3
0
        public void DeleteLastJob()
        {
            PrintSystemJobInfo lastJob = getLastJob();

            if (lastJob != null)
            {
                lastJob.Cancel();
                lastJob.Refresh();
            }
        }
Exemplo n.º 4
0
        private void cmdCancelJob_Click(object sender, RoutedEventArgs e)
        {
            if (lstJobs.SelectedValue != null)
            {
                PrintQueue         queue = printServer.GetPrintQueue(lstQueues.SelectedValue.ToString());
                PrintSystemJobInfo job   = queue.GetJob((int)lstJobs.SelectedValue);
                job.Cancel();

                lstQueues_SelectionChanged(null, null);
            }
        }
Exemplo n.º 5
0
        internal static void HandlePausedJob(PrintSystemJobInfo theJob)
        {
            Console.WriteLine("The user or someone with administrative rights to the queue" +
                              "\nhas paused the job or queue." +
                              "\nResume the queue? (Has no effect if queue is not paused.)" +
                              "\nEnter \"Y\" to resume, otherwise press return: ");
            String resume = Console.ReadLine();

            if (resume == "Y")
            {
                theJob.HostingPrintQueue.Resume();
                Console.WriteLine("Does user want to resume print job or cancel it?" + "\nEnter \"Y\" to resume (any other key cancels the print job): ");
                String userDecision = Console.ReadLine();
                if (userDecision == "Y")
                {
                    theJob.Resume();
                }
                else
                {
                    theJob.Cancel();
                }
            }
        }