private async static Task GetPizzaAsync(string pizzaId) { DelegatingHandler[] start = null; using (var pizzaServer = new PizzaServer.PizzaServerRESTAPI(new AnonymousCredential(), start)) { try { var result = await pizzaServer.GetPizzaUsingGETAsync(long.Parse(pizzaId)); Console.WriteLine($"{result.Name} {result.Description}"); var toppings = await pizzaServer.GetToppingsUsingGETAsync(long.Parse(pizzaId)); Console.WriteLine("Includes the following toppings: "); int i = 0; foreach (var item in toppings) { i++; Console.Write(item.Name); if (i < toppings.Count) { Console.Write(", "); } } } catch (HttpOperationException ex) { DisplayErrorMessage($"Failed to get Pizza with PizzaId {pizzaId}\n {ex.Message}"); } catch (Exception ex) { DisplayErrorMessage($"Failed to get Pizza with PizzaId {pizzaId}\n {ex.Message}"); } } }
private async static Task GetToppingsForPizzaAsync(string pizzaId) { DelegatingHandler[] start = null; using (var pizzaServer = new PizzaServer.PizzaServerRESTAPI(new AnonymousCredential(), start)) { try { var toppings = await pizzaServer.GetToppingsUsingGETAsync(long.Parse(pizzaId)); Console.WriteLine("Now includes the following toppings: "); int i = 0; foreach (var item in toppings) { i++; Console.Write(item.Name); if (i < toppings.Count) { Console.Write(", "); } } } catch (HttpOperationException ex) { DisplayErrorMessage($"Failed to get Toppings for Pizza with PizzaId {pizzaId}\n {ex.Message}"); DisplayErrorMessage($"Try running 'pizza --getPizzza {pizzaId}' to ensure it exists"); } catch (Exception ex) { if (ex.Message == "Operation returned an invalid status code 'Created'") { //eat it } else { DisplayErrorMessage($"Failed to get Toppings for Pizza with PizzaId {pizzaId}\n {ex.Message}"); } } } }