Ejemplo n.º 1
0
        /// <summary>
        /// Unshare google cloud printer from other google user
        /// reference: https://developers.google.com/cloud-print/docs/shareApi#unshare
        /// </summary>
        /// <param name="request">Parameters for /unshare interface</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>Response from google cloud</returns>
        public async Task <Response <UnshareRequest> > UnsharePrinterAsync(UnshareRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            await UpdateTokenAsync(cancellationToken);

            return(await GoogleCloudPrintBaseUrl
                   .AppendPathSegment("unshare")
                   .WithOAuthBearerToken(_token.AccessToken)
                   .PostRequestAsync(request, cancellationToken)
                   .ReceiveJsonButThrowIfFails <Response <UnshareRequest> >()
                   .ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Unshare google cloud printer from other google user
        /// reference: https://developers.google.com/cloud-print/docs/shareApi#unshare
        /// </summary>
        /// <param name="request">Parameters for /unshare interface</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>Response from google cloud</returns>
        public async Task <UnshareResponse> UnsharePrinterAsync(UnshareRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            await UpdateTokenAsync(cancellationToken);

            return(await GoogleCloudPrintBaseUrl
                   .AppendPathSegment("unshare")
                   .WithOAuthBearerToken(_token.AccessToken)
                   .PostUrlEncodedAsync(new
            {
                printerid = request.PrinterId,
                scope = request.Scope
            }, cancellationToken)
                   .ReceiveJsonButThrowIfFails <UnshareResponse>()
                   .ConfigureAwait(false));
        }
        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");
            }
        }