Esempio n. 1
0
        public static async Task PrintOneFile(PrintJobModel printJob, IProgress <Queue <PrintJobModel> > progress)
        {
            OngoingPrintJobRequests += 1;
            string tempDocumentPath = await GetDocument(printJob);

            try
            {
                PrintDocumentHelper.PrintDocument(tempDocumentPath, printJob);

                await UpdatePrintJobStatus(printJob.Id);

                OngoingPrintJobRequests -= 1;
                // TODO: Hacky AF
                //  Why:
                //  - When printButton is used the row is removed from the printQueueTable.
                //    However, printJobStatus for the job is not updated on backend.
                //    So, only refresh table from backend once all ongoing jobs are finished, and the printJobStatus is updated on backend.
                if (OngoingPrintJobRequests == 0)
                {
                    showMessageBox = false;
                    progress.Report(new Queue <PrintJobModel>());
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                Debug.WriteLine(e.Message);
            }
        }
Esempio n. 2
0
        public static async Task PrintJobThread(IProgress <Queue <PrintJobModel> > progress)
        {
            // = await LoadPrintJobs();
            PrintJobModel printJob;

            int printCount = 0;

            while (true)
            {
                if (!PausePrint)
                {
                    printJobQueue = await LoadPrintJobs();

                    // TODO: Implement an Hacky AF solution here as well.
                    progress.Report(printJobQueue);
                    GetPrintJobs = false;
                    while (printJobQueue.Count != 0)
                    {
                        printJob = printJobQueue.Dequeue();

                        progress.Report(printJobQueue);
                        string tempDocumentPath = await GetDocument(printJob);

                        //string tempDocumentPath = @"C:\Program Files\Preasy\PrintHub\print.docx";

                        try
                        {
                            //MessageBox.Show("Just before PrintDocument");
                            PrintDocumentHelper.PrintDocument(tempDocumentPath, printJob);
                            //MessageBox.Show("Just exited PrintDocument");
                            Debug.WriteLine(printCount++);

                            await UpdatePrintJobStatus(printJob.Id);

                            if (PausePrint)
                            {
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                            Debug.WriteLine(e.Message);
                        }

                        //System.Threading.Thread.Sleep(10000);
                        GetPrintJobs = true;
                    }
                    // Automatic Operation Mode
                    if (!GetPrintJobs)
                    {
                        System.Threading.Thread.Sleep(10000);
                    }
                }
                else
                {
                    // Manual Opernation Mode.
                    printJobQueue = await LoadPrintJobs();

                    // TODO: Implement an Hacky AF solution here as well.
                    if (OngoingPrintJobRequests == 0)
                    {
                        progress.Report(printJobQueue);
                    }

                    System.Threading.Thread.Sleep(10000);
                }
            }
        }