Exemplo n.º 1
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            this.Text = "trying to register printer";
            var gcpService = new GoogleCloudPrintService(serviceAccount, P12FileLocation, P12Secret, ThisProgramName, GoogleCloudPrintService.CallingProgramConstants.Desktop);

            GoogleCloudPrint.Model.UnregisteredCloudPrinter pReg = new GoogleCloudPrint.Model.UnregisteredCloudPrinter();

            // fill printer object to register
            pReg.name = txtName.Text;
            pReg.default_display_name = txtDefault_display_name.Text;
            pReg.proxy        = txtProxy.Text;
            pReg.tag          = txtTag.Text;
            pReg.capabilities = txtCapabilities.Text;

            pReg = gcpService.RegisterPrinter(pReg);

            if (pReg.id == "failure")
            {
                MessageBox.Show("Failure" + CRLF
                                + pReg.name + CRLF
                                + pReg.description);

                this.Text = "failure :( ";
            }
            else
            {
                this.Text = "Success!!!";
            }
        }
Exemplo n.º 2
0
        // does the update method
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                CBOItem printerInfo       = (CBOItem)cboPrinters.SelectedItem;
                string  selectedPrinterID = printerInfo.Value;

                //if (txtNewName.Text == string.Empty) throw new Exception("Need new name");
                if (lblNewDefaultDisplayName.Text == string.Empty)
                {
                    throw new Exception("Need new display name");
                }

                var gcpService = new GoogleCloudPrintService(serviceAccount, P12FileLocation, P12Secret, ThisProgramName, GoogleCloudPrintService.CallingProgramConstants.Desktop);
                GoogleCloudPrint.Model.UnregisteredCloudPrinter pReg = new GoogleCloudPrint.Model.UnregisteredCloudPrinter();

                // fill printer object to rename
                //pReg.name = txtNewName.Text;
                pReg.default_display_name = lblNewDefaultDisplayName.Text;
                pReg.id = selectedPrinterID;

                gcpService.UpdatePrinter(pReg);

                GetPrinters();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        private void btnSharePrinter_Click(object sender, EventArgs e)
        {
            this.Text = "trying to share printer";
            var gcpService = new GoogleCloudPrintService(serviceAccount, P12FileLocation, P12Secret, ThisProgramName, GoogleCloudPrintService.CallingProgramConstants.Desktop);

            gcpService.PrinterShare(txtPrinterID.Text, NotifyUserOfShareEmail, chkNotify.Checked);
            this.Text = "done";
        }
Exemplo n.º 4
0
        private GoogleCloudPrint.Model.CloudPrinters GetPrinterCollection()
        {
            // get list of printers
            var gcpService        = new GoogleCloudPrintService(serviceAccount, P12FileLocation, P12Secret, ThisProgramName, GoogleCloudPrintService.CallingProgramConstants.Desktop);
            var printerCollection = gcpService.GetPrinters();

            return(printerCollection);
        }
Exemplo n.º 5
0
        private void btnPrintDoc_Click(object sender, EventArgs e)
        {
            // solution to show credentials - https://github.com/io7/GoogleCloudPrint/issues/3
            #region Instantiate library

            var gcpService = new GoogleCloudPrintService(serviceAccount, P12FileLocation, P12Secret, ThisProgramName, GoogleCloudPrintService.CallingProgramConstants.Desktop);
            #endregion
            byte[] docBytes = GetDocumentOnDisk();            // note Hard coding below

            gcpService.PrintDocument(m_printerId, PrintJobName, docBytes, MimeType);
        }
Exemplo n.º 6
0
        private void btnFilterPrintersByType_Click(object sender, EventArgs e)
        {
            var gcpService = new GoogleCloudPrintService(serviceAccount, P12FileLocation, P12Secret, ThisProgramName, GoogleCloudPrintService.CallingProgramConstants.Desktop);
            List <GoogleCloudPrint.Model.CloudPrinter> filteredPrinters = gcpService.GetFilteredPrinters((GoogleCloudPrint.Model.GoogleCloudPrinterTypeConstants)cboGCPPrinterType.SelectedValue);

            ClearComboBox(cboPrinters);

            // todo shold refactor the 3 or 4 lines below into a method
            cboPrinters.DataSource    = filteredPrinters;
            cboPrinters.DisplayMember = "defaultDisplayName";
            cboPrinters.ValueMember   = "id";

            cboPrinters.Text = string.Empty;
        }
Exemplo n.º 7
0
        private void btnInvite_Click(object sender, EventArgs e)
        {
            this.Text = "trying to invite newly shared printer";
            lblInviteResponse.Text = string.Empty;
            var gcpService = new GoogleCloudPrintService(serviceAccount, P12FileLocation, P12Secret, ThisProgramName, GoogleCloudPrintService.CallingProgramConstants.Desktop);
            var response   = gcpService.ProcessInvite(txtPrinterID.Text);

            lblInviteResponse.Text = response.success + System.Environment.NewLine + response.message;

            // refresh the list of printers
            GetPrinters();

            this.Text = "done";
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            var service = new GoogleCloudPrintService(accessToken: "ya29.Ci_JAzDgONRSXVc9LEXFKplbA5afLe3pRK-CcgXNicpJwsKKmQCH2KscL4hRWnSXog");

            var printers = service.GetPrinters();

            var document = typeof(Program).Assembly.GetManifestResourceStream("CloudPrint.Client.Test.Sample.pdf").ReadFully();

            //foreach (var printer in printers.printers)
            //{
            var printJob = service.PrintAsync(printerId: "c5f2459e-42ac-a564-3c4c-ed195552b2bc", title: "Sample Printer", document: document, mimeType: "application/pdf");

            printJob.Wait();
            Console.WriteLine($"c5f2459e-42ac-a564-3c4c-ed195552b2bc -> {printJob.Result.message}");
            //}


            Console.ReadLine();
        }
Exemplo n.º 9
0
        private void btnPrintDocFromName_Click(object sender, EventArgs e)
        {
            var gcpService = new GoogleCloudPrintService(serviceAccount, P12FileLocation, P12Secret, ThisProgramName, GoogleCloudPrintService.CallingProgramConstants.Desktop);

            GoogleCloudPrint.Model.CloudPrinters myPrinters = GetPrinterCollection();

            string localPrinterID = string.Empty;

            foreach (var aPrinter in myPrinters.printers)
            {
                if (aPrinter.defaultDisplayName == lblPrinterNameFromList.Text)
                {
                    localPrinterID = aPrinter.id;
                    break;
                }
            }
            byte[] docBytes = GetDocumentOnDisk();
            // note PrintJobName and MimeType come from the CONFIG file
            gcpService.PrintDocument(localPrinterID, PrintJobName, docBytes, MimeType);
        }
Exemplo n.º 10
0
        private void btnTestCapabilities_Click(object sender, EventArgs e)
        {
            var gcpService = new GoogleCloudPrintService(serviceAccount, P12FileLocation, P12Secret, ThisProgramName, GoogleCloudPrintService.CallingProgramConstants.Desktop);

            GoogleCloudPrint.Model.CloudPrinters myPrinters = GetPrinterCollection();

            string localPrinterID = string.Empty;

            foreach (var aPrinter in myPrinters.printers)
            {
                if (aPrinter.defaultDisplayName == lblPrinterNameFromList.Text)
                {
                    localPrinterID = aPrinter.id;
                    break;
                }
            }
            string content = "abc";
            // note PrintJobName and MimeType come from the CONFIG file
            string localMimeType = "text/plain";

            gcpService.PrintDocument(localPrinterID, "Title", content, localMimeType);
        }
Exemplo n.º 11
0
        private static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            using (var printService = new GoogleCloudPrintService("eLime.GoogleCoudPrintTest"))
            {
                await printService.AuthorizeJsonStringAsync(@"<json string");

                //await printService.AuthorizeJsonFileAsync(@"<json path>");
                //await printService.AuthorizeP12Async("<*****@*****.**>", "<p12 path>", "<secret>");

                Console.WriteLine("Accepting invite...");

                var printerid = "<printerid>";

                //accept invite for printer that was shared with service account
                var response = await printService.ProcessInvite(printerid);

                //get a printer
                var printer = await printService.GetPrinter(printerid, new List <string> {
                    "connectionStatus", "queuedJobsCount"
                });

                var cjt = @"
                {
                    ""version"":""1.0"",
                    ""print"":{
                        ""color"":{ ""vendor_id"":""psk:Color"",""type"":""STANDARD_COLOR""},
                        ""duplex"":{ ""type"":""LONG_EDGE""},
                        ""vendor_ticket_item"":[
                            {""id"":""psk:PageInputBin"",""value"":""epns200:Front1""},
                        ]
                    }
                }";

                //print document. Set print in color, duplex printing and paper tray 2 as source

                var printjob = printService.PrintDocument(printerid, "example.pdf", cjt, "http://www.africau.edu/images/default/sample.pdf");
            }
        }
Exemplo n.º 12
0
        public async Task <bool> PrintBadges(List <PrintBadge> badges)
        {
            using (var printService = new GoogleCloudPrintService("Mits.badge.print"))

            {
                Console.WriteLine(_hostingEnvironment.ContentRootPath);
                var p12Path = _hostingEnvironment.ContentRootPath + "\\Cloud Print-f133453408bb.p12";

                await printService.AuthorizeP12Async("*****@*****.**", p12Path, "notasecret");

                Console.WriteLine("Accepting invite...");

                var printerid = "95ffb34a-a2d0-d53c-f09f-f591206df145";

                var printer = await printService.GetPrinter(printerid, new List <string> {
                    "connectionStatus", "queuedJobsCount"
                });



                var cjt = @"
                {
                    ""version"":""1.0"",
                    ""print"":{
                        ""color"":{ ""vendor_id"":""psk:Color"",""type"":""STANDARD_COLOR""},
                        ""duplex"":{ ""type"":""LONG_EDGE""},
                        ""vendor_ticket_item"":[
                            {""id"":""psk:PageInputBin"",""value"":""epns200:Front1""},
                        ]
                    }
                }";

                //print document. Set print in color, duplex printing and paper tray 2 as source

                var printjob = printService.PrintDocument(printerid, "example.pdf", cjt, "http://www.africau.edu/images/default/sample.pdf");
            }

            return(true);
        }