コード例 #1
0
        private IEnumerable <CloudPrintJob> DequeueDeferredPrintQueueJobs(string username)
        {
            CloudPrintJob job;
            ConcurrentQueue <CloudPrintJob> queue;

            if (UserDeferredJobs.TryGetValue(username, out queue))
            {
                while (queue.TryDequeue(out job))
                {
                    yield return(job);
                }
            }
        }
コード例 #2
0
        private void ProcessPrintJob(CloudPrintJob job)
        {
            if (DateTime.Now > job.CreateTime.AddDays(Config.MaxJobAgeInDays))
            {
                Logger.Log(LogLevel.Info, "Job {0} from {1}@{2} expired (Job created {3}, maxage: {4} days)", job.JobID, job.Username, job.Domain, job.CreateTime, Config.MaxJobAgeInDays);
                job.SetError("Expired", "Job expired in queue");
            }
            else if (!WindowsIdentityStore.IsAcceptedDomain(job.Domain))
            {
                Logger.Log(LogLevel.Info, "Job {0} deferred because {1}@{2} is not in an accepted domain", job.JobID, job.Username, job.Domain);
            }
            else
            {
                using (JobPrinter printer = Activator.CreateInstance(job.Printer.GetJobPrinterType()) as JobPrinter)
                {
                    if (!printer.UserCanPrint(job.Username))
                    {
                        if (printer.NeedUserAuth)
                        {
                            Logger.Log(LogLevel.Debug, "Job {0} deferred because {1} has not logged in", job.JobID, job.Username);

                            if (!job.DeliveryAttempted)
                            {
                                NotifyUserToLogin(job);
                            }
                        }

                        job.SetDeliveryAttempted();
                        UserDeferredJobs.GetOrAdd(job.Username, new ConcurrentQueue <CloudPrintJob>()).Enqueue(job);
                    }
                    else
                    {
                        job.SetStatus(CloudPrintJobStatus.IN_PROGRESS);
                        try
                        {
                            Logger.Log(LogLevel.Info, "Starting job {0}", job.JobID);
                            printer.Print(job);
                            Logger.Log(LogLevel.Info, "Job {0} Finished", job.JobID);
                            job.SetStatus(CloudPrintJobStatus.DONE);
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(LogLevel.Info, "Job {0} in error:\nException:\n{1}\n{2}", job.JobID, ex.Message, ex.ToString());
                            job.SetStatus(CloudPrintJobStatus.QUEUED);
                            //job.SetError(ex.GetType().Name, ex.Message);
                        }
                    }
                }
            }
        }
コード例 #3
0
        public IEnumerable <CloudPrintJob> GetQueuedJobs()
        {
            foreach (KeyValuePair <string, ConcurrentQueue <CloudPrintJob> > kvp in UserDeferredJobs.AsEnumerable())
            {
                foreach (CloudPrintJob job in kvp.Value.AsEnumerable())
                {
                    yield return(job);
                }
            }

            foreach (CloudPrintJob job in PrintJobQueue.AsEnumerable())
            {
                yield return(job);
            }
        }
コード例 #4
0
        public IEnumerable <CloudPrintJob> GetQueuedJobs(string username)
        {
            ConcurrentQueue <CloudPrintJob> queue;

            if (UserDeferredJobs.TryGetValue(username, out queue))
            {
                foreach (CloudPrintJob job in queue.AsEnumerable())
                {
                    yield return(job);
                }
            }

            foreach (CloudPrintJob job in PrintJobQueue.AsEnumerable().Where(j => j.Username == username))
            {
                yield return(job);
            }
        }