Beispiel #1
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);
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public IEnumerable <CloudPrintJob> GetCloudPrintJobsForUser(string username)
 {
     return(PrintJobs.Where(j => WindowsIdentityStore.IsAcceptedDomain(j.Domain) && j.Username == username));
 }