Exemple #1
0
        public HttpResponseMessage Get(string JobID)
        {
            CloudPrintJob job = PrintProxy.GetCloudPrintJobById(JobID);

            if (job == null)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.NotFound));
            }

            string username = Request.GetSession()["username"];

            bool isadmin = WindowsIdentityStore.IsUserAdmin(username);

            if (isadmin || username == job.Username)
            {
                HttpResponseMessage response = new HttpResponseMessage
                {
                    Content = new StreamContent(new MemoryStream(job.GetPrintData()))
                };
                response.Content.Headers.ContentType.MediaType = "application/pdf";

                return(response);
            }
            else
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden));
            }
        }
 public override void Print(CloudPrintJob job)
 {
     PrintTicket printTicket = job.GetPrintTicket();
     byte[] printData = job.GetPrintData();
     string printerDriver = Config.GhostscriptPrinterDrivers[job.Printer.Name];
     PrintData(job.Username, printTicket, job.Printer.Name, job.JobTitle, printData, printerDriver);
 }
        public override void Print(CloudPrintJob job)
        {
            PrintTicket printTicket = job.GetPrintTicket();

            byte[] printData = job.GetPrintData();
            Print(job.Username, job.GetPrintData(), job.Printer.Name, job.JobTitle, job.GetPrintTicket());
        }
Exemple #4
0
        public override void Print(CloudPrintJob job)
        {
            using (Ghostscript gs = new Ghostscript())
            {
                PrintTicket   printTicket = job.GetPrintTicket();
                byte[]        printData   = job.GetPrintData();
                List <string> args        = new List <string>();

                args.Add("-dAutoRotatePages=/None");

                if (printTicket.OutputColor != OutputColor.Color)
                {
                    args.Add("-sColorConversionStrategy=Gray");
                    args.Add("-dProcessColorModel=/DeviceGray");
                }

                byte[] printdata = gs.ProcessData(printTicket, printData, "pdfwrite", args.ToArray(), null);

                WindowsRawPrintJob pj = new WindowsRawPrintJob
                {
                    JobName     = job.JobTitle,
                    UserName    = job.Username,
                    PrinterName = job.Printer.Name,
                    PrintData   = printdata,
                    RunAsUser   = true
                };

                pj.Print();
            }
        }
        public override void Print(CloudPrintJob job)
        {
            using (Ghostscript gs = new Ghostscript())
            {
                PrintTicket printTicket = job.GetPrintTicket();
                byte[] printData = job.GetPrintData();
                List<string> args = new List<string>();

                args.Add("-dAutoRotatePages=/None");

                if (printTicket.OutputColor != OutputColor.Color)
                {
                    args.Add("-sColorConversionStrategy=Gray");
                    args.Add("-dProcessColorModel=/DeviceGray");
                }

                byte[] printdata = gs.ProcessData(printTicket, printData, "pdfwrite", args.ToArray(), null);

                WindowsRawPrintJob pj = new WindowsRawPrintJob
                {
                    JobName = job.JobTitle,
                    UserName = job.Username,
                    PrinterName = job.Printer.Name,
                    PrintData = printdata,
                    RunAsUser = true
                };

                pj.Print();
            }
        }
Exemple #6
0
        public override void Print(CloudPrintJob job)
        {
            PrintTicket printTicket = job.GetPrintTicket();

            byte[] printData     = job.GetPrintData();
            string printerDriver = Config.GhostscriptPrinterDrivers[job.Printer.Name];

            PrintData(job.Username, printTicket, job.Printer.Name, job.JobTitle, printData, printerDriver);
        }
Exemple #7
0
        public void AddJob(CloudPrintJob job)
        {
            ThrowIfDisposed();

            lock (PrintJobQueue)
            {
                PrintJobQueue.Enqueue(job);
            }

            ProcessQueuedPrintJobs();
        }
Exemple #8
0
        public override void Print(CloudPrintJob job)
        {
            Dictionary <string, string> pjlattribs = new Dictionary <string, string>
            {
                { "LUNA", job.Username },
                { "ACNA", job.JobTitle },
                { "JOAU", UserIDMapper.GetUserId(job.Username) }
            };

            base.Print(job, false, true, pjlattribs, null);
        }
        public override void Print(CloudPrintJob job)
        {
            Dictionary<string, string> pjlattribs = new Dictionary<string,string>
            {
                { "LUNA", job.Username },
                { "ACNA", job.JobTitle },
                { "JOAU", UserIDMapper.GetUserId(job.Username) }
            };

            base.Print(job, false, true, pjlattribs, null);
        }
Exemple #10
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);
                        }
                    }
                }
            }
        }
Exemple #11
0
        public void UpdatePrintJob(CloudPrintJob job)
        {
            Logger.Log(LogLevel.Debug, "Updated job {0} with status {1}", job.JobID, job.Status.ToString());

            var reqdata = new
            {
                jobid   = job.JobID,
                status  = job.Status.ToString(),
                code    = job.ErrorCode,
                message = job.ErrorMessage
            };

            HTTPHelper.PostCloudPrintUrlEncodedRequest(OAuthTicket, "control", reqdata);

            if (job.Status == CloudPrintJobStatus.DONE)
            {
                CloudPrintJob _job;
                _PrintJobs.TryRemove(job.JobID, out _job);
            }
        }
Exemple #12
0
 private void NotifyUserToLogin(CloudPrintJob job)
 {
     try
     {
         string message = String.Format(
             "You have sent a job to cloud printer \"{0}\" on {1} at {2} on {3}\n\nPlease log into http://{4}:{5}/ to allow this job (and any others) to be printed.",
             job.Printer.Name,
             Environment.MachineName,
             job.CreateTime.ToLocalTime().ToString("hh:mm tt"),
             job.CreateTime.ToLocalTime().ToString("dd MMM yyyy"),
             Config.UserAuthHost,
             Config.UserAuthHttpPort
             );
         string subject = String.Format("Please log in to enable cloud printing on {0}", Environment.MachineName);
         SendEmail(job.OwnerId, subject, message);
     }
     catch (Exception ex)
     {
         Logger.Log(LogLevel.Warning, "Error notifying user to log in\n\n{0}", ex.ToString());
     }
 }
        protected void Print(CloudPrintJob job, bool runAsUser, bool usePJL, Dictionary <string, string> pjljobattribs, Dictionary <string, string> pjlsettings)
        {
            PrintTicket        ticket   = job.GetPrintTicket();
            PaginatedPrintData pagedjob = PostscriptHelper.FromPDF(job.GetPrintData(), ticket);

            if (usePJL)
            {
                pagedjob.Prologue = PJLHelper.GetPJL(pjljobattribs, pjlsettings, "POSTSCRIPT").Concat(pagedjob.Prologue).ToArray();
            }

            WindowsRawPrintJob pj = new WindowsRawPrintJob
            {
                PagedData   = pagedjob,
                JobName     = job.JobTitle,
                PrinterName = job.Printer.Name,
                UserName    = job.Username,
                PrintTicket = ticket,
                RunAsUser   = runAsUser
            };

            pj.Print();
        }
        protected void Print(CloudPrintJob job, bool runAsUser, bool usePJL, Dictionary<string, string> pjljobattribs, Dictionary<string, string> pjlsettings)
        {
            PrintTicket ticket = job.GetPrintTicket();
            PaginatedPrintData pagedjob = PostscriptHelper.FromPDF(job.GetPrintData(), ticket);

            if (usePJL)
            {
                pagedjob.Prologue = PJLHelper.GetPJL(pjljobattribs, pjlsettings, "POSTSCRIPT").Concat(pagedjob.Prologue).ToArray();
            }

            WindowsRawPrintJob pj = new WindowsRawPrintJob
            {
                PagedData = pagedjob,
                JobName = job.JobTitle,
                PrinterName = job.Printer.Name,
                UserName = job.Username,
                PrintTicket = ticket,
                RunAsUser = runAsUser
            };

            pj.Print();
        }
Exemple #15
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var cloudPrint = new GoogleCloudPrint("");
                cloudPrint.UserName = txtUsername.Text + "%40ridgewood%2Ek12%2Enj%2Eus";
                cloudPrint.Password = pwdPassword.Password;
                var printers        = cloudPrint.Printers;
                int intPrinterIndex = 0;
                foreach (CloudPrinter printer in printers.printers)
                {
                    //name is the name of the printer on the system when added to google cloud print
                    //description is the comment of the printer in the Comment field on Windows. Mac shared printer was blank.

                    //Console.WriteLine(@"name:{0} description:{1}", printer.name, printer.description, printer.name);
                    //lstPrinters.Items.Add(String.Format(@"{0}", printer.name));
                    //lstPrinters.
                    //lstPrinters.Items.Add(printer.description);
                    if (selectedPrinter == printer.description)
                    {
                        //MessageBox.Show(printers.printers[intPrinterIndex].id);
                        CloudPrintJob job = cloudPrint.PrintDocument(printers.printers[intPrinterIndex].id, "PDF File", FileToByteArray(filepath), @"application/pdf");
                        MessageBox.Show("Print successful!");
                    }
                    intPrinterIndex++;
                }
                //Console.ReadLine();

                //CloudPrintJob job = cloudPrint.PrintDocument(printers.printers[0].id, "Title", FileToByteArray(@"page.pdf"), @"application/pdf");
                //Console.WriteLine(job.message);
            }
            catch
            {
                MessageBox.Show("Could not access API. Please make sure you aren't using your personal account.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 public Stream GetPrintDataStream(CloudPrintJob job)
 {
     byte[] data = HTTPHelper.GetResponseData(HTTPHelper.CreateRequest(OAuthTicket, job.FileUrl));
     return new MemoryStream(data);
 }
 public PrintTicket GetPrintTicket(CloudPrintJob job)
 {
     return new PrintTicket(new MemoryStream(HTTPHelper.GetResponseData(HTTPHelper.CreateRequest(OAuthTicket, job.TicketUrl))));
 }
        public void UpdatePrintJob(CloudPrintJob job)
        {
            Logger.Log(LogLevel.Debug, "Updated job {0} with status {1}", job.JobID, job.Status.ToString());

            var reqdata = new
            {
                jobid = job.JobID,
                status = job.Status.ToString(),
                code = job.ErrorCode,
                message = job.ErrorMessage
            };

            HTTPHelper.PostCloudPrintUrlEncodedRequest(OAuthTicket, "control", reqdata);

            if (job.Status == CloudPrintJobStatus.DONE)
            {
                CloudPrintJob _job;
                _PrintJobs.TryRemove(job.JobID, out _job);
            }
        }
 public override void Print(CloudPrintJob job)
 {
     Print(job, true, false, null, null);
 }
 public override void Print(CloudPrintJob job)
 {
     PrintTicket printTicket = job.GetPrintTicket();
     byte[] printData = job.GetPrintData();
     PrintData(job.Username, printTicket, job.Printer.Name, job.JobTitle, printData, null);
 }
 public abstract void Print(CloudPrintJob job);
Exemple #22
0
 public Stream GetPrintDataStream(CloudPrintJob job)
 {
     byte[] data = HTTPHelper.GetResponseData(HTTPHelper.CreateRequest(OAuthTicket, job.FileUrl));
     return(new MemoryStream(data));
 }
Exemple #23
0
 public PrintTicket GetPrintTicket(CloudPrintJob job)
 {
     return(new PrintTicket(new MemoryStream(HTTPHelper.GetResponseData(HTTPHelper.CreateRequest(OAuthTicket, job.TicketUrl)))));
 }
 public override void Print(CloudPrintJob job)
 {
     Print(job, true, false, null, null);
 }
        public void AddJob(CloudPrintJob job)
        {
            ThrowIfDisposed();

            lock (PrintJobQueue)
            {
                PrintJobQueue.Enqueue(job);
            }

            ProcessQueuedPrintJobs();
        }
 private void NotifyUserToLogin(CloudPrintJob job)
 {
     try
     {
         string message = String.Format(
             "You have sent a job to cloud printer \"{0}\" on {1} at {2} on {3}\n\nPlease log into http://{4}:{5}/ to allow this job (and any others) to be printed.",
             job.Printer.Name,
             Environment.MachineName,
             job.CreateTime.ToLocalTime().ToString("hh:mm tt"),
             job.CreateTime.ToLocalTime().ToString("dd MMM yyyy"),
             Config.UserAuthHost,
             Config.UserAuthHttpPort
         );
         string subject = String.Format("Please log in to enable cloud printing on {0}", Environment.MachineName);
         SendEmail(job.OwnerId, subject, message);
     }
     catch (Exception ex)
     {
         Logger.Log(LogLevel.Warning, "Error notifying user to log in\n\n{0}", ex.ToString());
     }
 }
        private void ProcessPrintJob(CloudPrintJob job)
        {
            if (DateTime.Now > job.CreateTime.AddDays(-Config.MaxJobAgeInDays))
            {
                Logger.Log(LogLevel.Info, "Job {0} from {1}@{2} expired", job.JobID, job.Username, job.Domain);
                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);
                        }
                    }
                }
            }
        }