Пример #1
0
        private IEnumerable <CloudPrintJob> UpdateCloudPrintJobs(CloudPrinter printer)
        {
            List <CloudPrintJob> jobs;

            dynamic fetchdata = HTTPHelper.PostCloudPrintUrlEncodedRequest(OAuthTicket, "fetch", new { printerid = printer.PrinterID });

            if (fetchdata.success)
            {
                jobs = ((IEnumerable <dynamic>)fetchdata.jobs).Select(j => new CloudPrintJobImpl(this, printer, j)).OfType <CloudPrintJob>().ToList();
            }
            else
            {
                jobs = new List <CloudPrintJob>();
            }

            foreach (CloudPrintJob job in jobs)
            {
                if (!_PrintJobs.ContainsKey(job.JobID))
                {
                    _PrintJobs[job.JobID] = job;
                    PrintJobProcessor.AddJob(job);
                    //Logger.Log(LogLevel.Info, "Received new print job {0} [{1}] owned by {2} for printer [{3}]", job.JobID, job.JobTitle, job.Username, job.Printer.Name);
                }
            }

            return(jobs);
        }
Пример #2
0
        private async void manualPrintFile(object sender, EventArgs e)
        {
            Button        button            = sender as Button;
            DataDelivered data              = (DataDelivered)button.Tag;
            var           progressIndicator = new Progress <Queue <PrintJobModel> >(RefreshPrintJobQueue);

            try
            {
                // TODO: Check if Application is running in manual mode
                // if in manual mode:
                //  print selected file
                //  update printjobstatus
                //  update tablelayout
                // else:
                //  Switch to Manual mode
                //  follow the steps for manual mode
                //  switch to automatic mode

                if (PrintJobProcessor.PausePrint)
                {
                    Task.Factory.StartNew(() => PrintJobProcessor.PrintOneFile(data.Job, progressIndicator), TaskCreationOptions.LongRunning);
                }

                TableLayoutHelper.RemoveArbitraryRow(tableLayoutPrintQueue, data.RowIndex);
            }
            catch (WebException ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Пример #3
0
        public PrintQueueControl()
        {
            InitializeComponent();

            var progressIndicator = new Progress <Queue <PrintJobModel> >(RefreshPrintJobQueue);

            Task.Factory.StartNew(() => PrintJobProcessor.PrintJobThread(progressIndicator), TaskCreationOptions.LongRunning);
        }
Пример #4
0
        private async void cancelPrint(object sender, EventArgs e)
        {
            Button        button = sender as Button;
            DataDelivered data   = (DataDelivered)button.Tag;

            try
            {
                await PrintJobProcessor.CancelPrint(data.Job);

                TableLayoutHelper.RemoveArbitraryRow(tableLayoutPrintQueue, data.RowIndex);
            }
            catch (WebException ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Пример #5
0
        public async void RefreshPrintJobQueue(Queue <PrintJobModel> printJobQueue)
        {
            //PrintJobQueue = GetPrintJobs();

            // TODO: Remove this server call and use formal parameter
            printJobQueue = await PrintJobProcessor.LoadPrintJobs();

            //int topPrintJobId = printJobQueue.Last().Id;
            string stringPrintJobQueue = printJobQueueToString(printJobQueue);

            if (!string.Equals(StringPrintJobQueue, stringPrintJobQueue))
            {
                StringPrintJobQueue = stringPrintJobQueue;

                // Only show this message in Manual operation
                if (PrintJobProcessor.PausePrint && PrintJobProcessor.showMessageBox)
                {
                    MessageBox.Show("We have a new Print Job");
                }
                PrintJobProcessor.showMessageBox = true;
                TableLayoutHelper.ClearTable(tableLayoutPrintQueue);
                populatePrintQueue(printJobQueue);
            }
        }
Пример #6
0
 public void EnqueuePrintJob(string jobid)
 {
     PrintJobProcessor.AddJob(GetCloudPrintJobById(jobid));
 }
Пример #7
0
        private IEnumerable <CloudPrinter> UpdatePrintQueues()
        {
            if (PrintQueuesLastUpdated + PrintQueueUpdateInterval - TimeSpan.FromSeconds(5) < DateTime.Now)
            {
                lock (UpdateLock)
                {
                    try
                    {
                        Dictionary <string, string> printerIds;

                        if (_Queues == null || _Queues.Count == 0)
                        {
                            IEnumerable <dynamic> printers = HTTPHelper.PostCloudPrintUrlEncodedRequest(OAuthTicket, "list", new { proxy = Config.CloudPrintProxyID }).printers;
                            printerIds = printers.ToDictionary(p => (string)p.name, p => (string)p.id);
                        }
                        else
                        {
                            printerIds = _Queues.ToDictionary(p => p.Name, p => p.PrinterID);
                        }

                        List <CloudPrinter> queues = new List <CloudPrinter>();

                        foreach (CloudPrinter queue in PrintJobProcessor.GetPrintQueues())
                        {
                            if (!printerIds.ContainsKey(queue.Name))
                            {
                                RegisterCloudPrinter(queue);
                            }
                            else
                            {
                                queue.SetPrinterID(printerIds[queue.Name]);
                                UpdateCloudPrinter(queue);
                            }

                            queues.Add(queue);
                        }

                        foreach (KeyValuePair <string, string> printer_kvp in printerIds)
                        {
                            if (queues.Count(q => q.PrinterID == printer_kvp.Value) == 0)
                            {
                                DeleteCloudPrinter(printer_kvp.Value);
                            }
                        }

                        _Queues = queues;

                        PrintQueuesLastUpdated = DateTime.Now;

                        UpdateCloudPrintJobs();

                        return(queues.AsEnumerable());
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(LogLevel.Warning, "Caught exception while updating printer queues:\n{0}", ex.ToString());
                        return(_Queues.AsEnumerable());
                    }
                }
            }
            else
            {
                return(_Queues.AsEnumerable());
            }
        }