private static async Task GetAvailableTickets(Ticketer.TicketerClient client) { Console.WriteLine("Getting available ticket count..."); var response = await client.GetAvailableTicketsAsync(new Empty()); Console.WriteLine("Available ticket count: " + response.Count); }
private static async Task GetAvailableTicketsAsync(Ticketer.TicketerClient client) { Console.WriteLine("Getting available ticket count..."); var response = await client.GetAvailableTicketsAsync(new Google.Protobuf.WellKnownTypes.Empty()); Console.WriteLine($"Available ticket count:{response.Count}"); }
private static async Task PurchaseTicket(Ticketer.TicketerClient client, string?token) { Console.WriteLine("Purchasing ticket..."); try { Metadata?headers = null; if (token != null) { headers = new Metadata(); headers.Add("Authorization", $"Bearer {token}"); } var response = await client.BuyTicketsAsync(new BuyTicketsRequest { Count = 1 }, headers); if (response.Success) { Console.WriteLine("Purchase successful."); } else { Console.WriteLine("Purchase failed. No tickets available."); } } catch (Exception ex) { Console.WriteLine("Error purchasing ticket." + Environment.NewLine + ex.ToString()); } }
static async Task Main(string[] args) { var channel = GrpcChannel.ForAddress(Address); var client = new Ticketer.TicketerClient(channel); Console.WriteLine("gRPC Ticketer"); Console.WriteLine(); Console.WriteLine("Press a key:"); Console.WriteLine("1: Get available tickets"); Console.WriteLine("2: Purchase ticket"); Console.WriteLine("3: Authenticate"); Console.WriteLine("4: Exit"); Console.WriteLine(); string?token = null; var exiting = false; while (!exiting) { var consoleKeyInfo = Console.ReadKey(intercept: true); switch (consoleKeyInfo.KeyChar) { case '1': await GetAvailableTicketsAsync(client); break; case '2': await PurchaseTicketAsync(client, token); break; case '3': token = await AuthenticateAsync(); break; case '4': exiting = true; break; default: break; } } //await BidirectionalStreamingExample(client); Console.WriteLine("Shutting down"); Console.WriteLine("Press any key to exit ..."); Console.ReadKey(); }
static async Task Main(string[] args) { var channel = CreateAuthenticatedChannel($"https://{Address}"); var client = new Ticketer.TicketerClient(channel); Console.WriteLine("gRPC Ticketer"); Console.WriteLine(); Console.WriteLine("Press a key:"); Console.WriteLine("1: Get available tickets"); Console.WriteLine("2: Purchase ticket"); Console.WriteLine("3: Authenticate"); Console.WriteLine("4: Exit"); Console.WriteLine("5: Authenticate with POST"); Console.WriteLine(); var exiting = false; while (!exiting) { var consoleKeyInfo = Console.ReadKey(intercept: true); switch (consoleKeyInfo.KeyChar) { case '1': await GetAvailableTickets(client); break; case '2': await PurchaseTicket(client); break; case '3': _token = await Authenticate().ConfigureAwait(false); Console.WriteLine(_token); break; case '4': exiting = true; break; case '5': _token = await AuthenticatePost(); Console.WriteLine(_token); break; } } Console.WriteLine("Exiting"); }
static async Task Main(string[] args) { // Server will only support Https on Windows and Linux var credentials = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ChannelCredentials.Insecure : ClientResources.SslCredentials; var channel = new Channel("localhost:50051", credentials); var client = new Ticketer.TicketerClient(channel); Console.WriteLine("gRPC Ticketer"); Console.WriteLine(); Console.WriteLine("Press a key:"); Console.WriteLine("1: Get available tickets"); Console.WriteLine("2: Purchase ticket"); Console.WriteLine("3: Authenticate"); Console.WriteLine("4: Exit"); Console.WriteLine(); string?token = null; var exiting = false; while (!exiting) { var consoleKeyInfo = Console.ReadKey(intercept: true); switch (consoleKeyInfo.KeyChar) { case '1': await GetAvailableTickets(client); break; case '2': await PurchaseTicket(client, token); break; case '3': token = await Authenticate(); break; case '4': exiting = true; break; } } Console.WriteLine("Exiting"); await channel.ShutdownAsync(); }
static async Task Main(string[] args) { var channel = GrpcChannel.ForAddress(Address); var client = new Ticketer.TicketerClient(channel); Console.WriteLine("gRPC Ticketer"); Console.WriteLine(); Console.WriteLine("Press a key:"); Console.WriteLine("1: Get available tickets"); Console.WriteLine("2: Purchase ticket"); Console.WriteLine("3: Authenticate"); Console.WriteLine("4: Exit"); Console.WriteLine(); string?token = null; var exiting = false; while (!exiting) { var consoleKeyInfo = Console.ReadKey(intercept: true); switch (consoleKeyInfo.KeyChar) { case '1': await GetAvailableTickets(client); break; case '2': await PurchaseTicket(client, token); break; case '3': token = await Authenticate(); break; case '4': exiting = true; break; } } Console.WriteLine("Exiting"); }
public static async Task Main(string[] args) { // Obtain request token. _token = await RequestTokenFromServer("ChrisSolutions"); var channel = CreateAuthenticatedChannel($"https://{Address}", _token); var client = new Ticketer.TicketerClient(channel); Console.WriteLine("gRPC Ticketer"); Console.WriteLine(); Console.WriteLine("Press a key:"); Console.WriteLine("1: Get available tickets"); Console.WriteLine("2: Purchase ticket"); //Console.WriteLine("3: Authenticate"); Console.WriteLine("4: Exit"); Console.WriteLine(); var exiting = false; while (!exiting) { var consoleKeyInfo = Console.ReadKey(intercept: true); switch (consoleKeyInfo.KeyChar) { case '1': await GetAvailableTickets(client); break; case '2': await PurchaseTicket(client); break; //case '3': // _token = await Authenticate(); // break; case '4': exiting = true; break; } } Console.WriteLine("Exiting"); }
private static async Task PurchaseTicket(Ticketer.TicketerClient client) { Console.WriteLine("Purchasing ticket..."); try { var response = await client.BuyTicketsAsync(new BuyTicketsRequest { Count = 1 }); if (response.Success) { Console.WriteLine("Purchase successful."); } else { Console.WriteLine("Purchase failed. No tickets available."); } } catch (Exception ex) { Console.WriteLine("Error purchasing ticket." + Environment.NewLine + ex.ToString()); } }