private static void DeletePrinter() { var client = new GoogleCloudPrintClient(provider, token); var listRequest = new ListRequest { Proxy = proxy }; var listResponse = client.ListPrinterAsync(listRequest).Result; if (listResponse.Printers != null && listResponse.Printers.Any()) { for (int i = 0; i < listResponse.Printers.Count(); i++) { Console.WriteLine($"{i + 1}. {listResponse.Printers.ElementAt(i).DisplayName}"); } Console.Write("Please choose a printer to delete: "); int option = -1; if (int.TryParse(Console.ReadLine(), out option)) { var printer = listResponse.Printers.ElementAt(option - 1); var deleteRequest = new DeleteRequest { PrinterId = printer.Id }; var deleteResponse = client.DeletePrinterAsync(deleteRequest).Result; Console.WriteLine($"Delete: {deleteResponse.Success}"); } } else { Console.WriteLine("There is no printer to delete!"); } }
public void testeAsync() { var client = new GoogleCloudPrintClient(provider, token); var request1 = new ListRequest { Proxy = "db9ab847-832e-4a0c-ab76-3673be68e9c1" }; var response1 = client.ListPrinterAsync(request1).Result; //SubmitPrint(client); PrintJob(client); }
public void ListPrinterTest() { Cleanup(); RegisterPrinter("hihi_one"); RegisterPrinter("hihi_two"); RegisterPrinter("hihi_three"); var listRequest = new ListRequest() { Proxy = Proxy.Value }; var client = new GoogleCloudPrintClient(OAuth2Provider, RefreshToken.Value); var lists = client.ListPrinterAsync(listRequest).Result; Assert.Equal(3, lists.Printers.Count); }
public void Cleanup() { // Cleanup the environment var listRequest = new ListRequest { Proxy = Proxy.Value }; var client = new GoogleCloudPrintClient(OAuth2Provider, RefreshToken.Value); var lists = client.ListPrinterAsync(listRequest).Result; foreach (var p in lists.Printers) { var deleteRequest = new DeleteRequest { PrinterId = p.Id }; var success = client.DeletePrinterAsync(deleteRequest).Result; } }
private static void SharePrinter() { var client = new GoogleCloudPrintClient(provider, token); var listRequest = new ListRequest { Proxy = proxy }; var listResponse = client.ListPrinterAsync(listRequest).Result; if (listResponse.Printers != null && listResponse.Printers.Any()) { for (int i = 0; i < listResponse.Printers.Count; i++) { Console.WriteLine($"{i + 1}. {listResponse.Printers.ElementAt(i).DisplayName}"); } int printerOption = -1; Console.Write("Please choose a printer to share: "); if (int.TryParse(Console.ReadLine(), out printerOption)) { var printer = listResponse.Printers.ElementAt(printerOption - 1); Console.Write("Please enter a google account to send share invitation: "); string account = Console.ReadLine(); var shareRequest = new ShareRequest { PrinterId = printer.Id, Scope = account, Role = Role.USER, SkipNotification = false }; var shareResponse = client.SharePrinterAsync(shareRequest).Result; if (shareResponse.Success) { Console.WriteLine($"Invitaion is sent to {account}"); } else { Console.WriteLine($"Invitation is not sent, error: {shareResponse.Message}"); } } } else { Console.WriteLine("There is no printer in the list"); } }
static void ListAndGetPrinter() { var client = new GoogleCloudPrintClient(provider, token); var listRequest = new ListRequest { Proxy = proxy }; var listResponse = client.ListPrinterAsync(listRequest).Result; if (listResponse.Printers != null && listResponse.Printers.Any()) { for (int i = 0; i < listResponse.Printers.Count; i++) { Console.WriteLine($"{i + 1}. {listResponse.Printers.ElementAt(i).DisplayName}"); } int printerOption = -1; Console.Write("Please choose a printer to look for details: "); if (int.TryParse(Console.ReadLine(), out printerOption)) { var printer = listResponse.Printers.ElementAt(printerOption - 1); var printerRequest = new PrinterRequest { PrinterId = printer.Id }; var printerResponse = client.GetPrinterAsync(printerRequest).Result; if (printerResponse.Printers != null && printerResponse.Printers.Any()) { var thePrinter = printerResponse.Printers.ElementAt(0); var message = new StringBuilder() .AppendLine($"Printer: {thePrinter.Name}") .AppendLine($"Model: {thePrinter.Model}") .ToString(); Console.WriteLine(message); } else { Console.WriteLine("No relevant printer is found."); } } } else { Console.WriteLine("There is no printer in the list"); } }
private static void UnsharePrinter() { var client = new GoogleCloudPrintClient(provider, token); var listRequest = new ListRequest { Proxy = proxy }; var listResponse = client.ListPrinterAsync(listRequest).Result; if (listResponse.Printers != null && listResponse.Printers.Any()) { for (int i = 0; i < listResponse.Printers.Count; i++) { Console.WriteLine($"{i + 1}. {listResponse.Printers.ElementAt(i).DisplayName}"); } int printerOption = -1; Console.Write("Please choose a printer to unshare: "); if (int.TryParse(Console.ReadLine(), out printerOption)) { var printer = listResponse.Printers.ElementAt(printerOption - 1); Console.Write("Please enter a google account to unshare: "); string account = Console.ReadLine(); var unshareRequest = new UnshareRequest { PrinterId = printer.Id, Scope = account }; var unshareResponse = client.UnsharePrinterAsync(unshareRequest).Result; if (unshareResponse.Success) { Console.WriteLine($"Printer {printer.Name} is unshared from {account}"); } else { Console.WriteLine($"Printer unshare failed, error: {unshareResponse.Message}"); } } } else { Console.WriteLine("There is no printer in the list"); } }
static void FetchJob() { try { var client = new GoogleCloudPrintClient(provider, token); var listRequest = new ListRequest { Proxy = proxy }; var listResponse = client.ListPrinterAsync(listRequest).Result; if (listResponse.Printers != null && listResponse.Printers.Any()) { for (int i = 0; i < listResponse.Printers.Count(); i++) { Console.WriteLine($"{i + 1}. {listResponse.Printers.ElementAt(i).DisplayName}"); } // Choose printer Console.Write("Please choose a printer to fetch job: "); int printerOption = -1; if (int.TryParse(Console.ReadLine(), out printerOption)) { var printer = listResponse.Printers.ElementAt(printerOption - 1); var fetchRequest = new FetchRequest { PrinterId = printer.Id }; var fetchResponse = client.FetchJobAsync(fetchRequest).Result; if (fetchResponse.Success && fetchResponse.Jobs.Any()) { for (int i = 0; i < fetchResponse.Jobs.Count(); i++) { Console.WriteLine($"{i + 1}. {fetchResponse.Jobs.ElementAt(i).Title}"); } // Choose job on specific printer Console.Write("Please choose a print job to download: "); int printJobOption = -1; if (int.TryParse(Console.ReadLine(), out printJobOption)) { if (printJobOption == -1) { return; } var printJob = fetchResponse.Jobs.ElementAt(printJobOption - 1); if (DownloadTicket(client, printJob) && DownloadDocument(client, printJob)) { var updateRequest = new ControlRequest { JobId = printJob.Id, Status = Models.Job.LegacyJobStatus.DONE }; var updateResponse = client.UpdateJobStatusAsync(updateRequest).Result; Console.WriteLine($"Update job status: {updateResponse.Success}"); } } else { Console.WriteLine("Fail to choose print job"); } } else { Console.WriteLine("There is currently no job!"); } } } else { Console.WriteLine("There is no printer to delete!"); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } }
private static void SubmitJob() { var client = new GoogleCloudPrintClient(provider, token); var listRequest = new ListRequest { Proxy = proxy }; var listResponse = client.ListPrinterAsync(listRequest).Result; if (listResponse.Printers != null && listResponse.Printers.Any()) { for (int i = 0; i < listResponse.Printers.Count; i++) { Console.WriteLine($"{i + 1}. {listResponse.Printers.ElementAt(i).DisplayName}"); } int printerOption = -1; Console.Write("Please choose a printer to submit job: "); if (int.TryParse(Console.ReadLine(), out printerOption)) { var printer = listResponse.Printers.ElementAt(printerOption - 1); var printerRequest = new PrinterRequest { PrinterId = printer.Id }; var printerResponse = client.GetPrinterAsync(printerRequest).Result; if (printerResponse.Printers != null && printerResponse.Printers.Any()) { Console.Write("Do you print from Url or a local document? (Y: Url, N: Local Document)"); bool isUrl = Console.ReadLine().ToLower().Contains("y"); Console.WriteLine("Please enter the path to the url/ the local document"); string path = Console.ReadLine(); var cjt = new CloudJobTicket { Print = new PrintTicketSection { Color = new ColorTicketItem { Type = Color.Type.STANDARD_MONOCHROME }, Duplex = new DuplexTicketItem { Type = Duplex.Type.LONG_EDGE }, PageOrientation = new PageOrientationTicketItem() { Type = PageOrientation.Type.LANDSCAPE }, Copies = new CopiesTicketItem() { Copies = 3 } } }; JobResponse <SubmitRequest> response; if (isUrl) { var request = new SubmitRequest { PrinterId = printer.Id, Title = Guid.NewGuid().ToString(), Ticket = cjt, Content = new SubmitFileLink(path) }; response = client.SubmitJobAsync(request).Result; } else { using (var s = File.Open(path, FileMode.Open)) { var request = new SubmitRequest() { PrinterId = printer.Id, Title = Path.GetFileNameWithoutExtension(path), Ticket = cjt, Content = new SubmitFileStream("text/plain", path, s) }; response = client.SubmitJobAsync(request).Result; } } Console.WriteLine("Success: {0}", response.Success); } else { Console.WriteLine("No relevant printer is found."); } } } else { Console.WriteLine("There is no printer in the list"); } }