예제 #1
0
 private async static Task AddToppingToPizzaAsync(string pizzaId, string toppingId)
 {
     DelegatingHandler[] start = null;
     using (var pizzaServer = new PizzaServer.PizzaServerRESTAPI(new AnonymousCredential(), start))
     {
         try
         {
             await pizzaServer.AddToppingUsingPOSTAsync(long.Parse(pizzaId), long.Parse(toppingId));
         }
         catch (HttpOperationException ex)
         {
             if (ex.Message == "Operation returned an invalid status code 'Created'")
             {
                 //eat it
                 await GetToppingsForPizzaAsync(pizzaId);
             }
             else
             {
                 DisplayErrorMessage($"Failed to add Topping to Pizza \n {ex.Message}");
             }
         }
         catch (Exception ex)
         {
             if (ex.Message == "Operation returned an invalid status code 'Created'")
             {
                 //eat it
                 await GetToppingsForPizzaAsync(pizzaId);
             }
             else
             {
                 DisplayErrorMessage($"Failed to add Topping to Pizza \n {ex.Message}");
             }
         }
     }
 }
예제 #2
0
        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}");
                }
            }
        }
예제 #3
0
        private async static Task GetPizzasAsync()
        {
            DelegatingHandler[] start = null;
            var pizzaServer           = new PizzaServer.PizzaServerRESTAPI(new AnonymousCredential(), start);
            var pizzas = await pizzaServer.GetPizzasUsingGETWithHttpMessagesAsync();

            //var result = pizzas.Body;
            await DisplayResultAsync(pizzas.Body as IList <Pizza>);
        }
예제 #4
0
        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}");
                    }
                }
            }
        }
예제 #5
0
 private async static Task AddPizzaAsync(Pizza pizza)
 {
     DelegatingHandler[] start = null;
     using (var pizzaServer = new PizzaServer.PizzaServerRESTAPI(new AnonymousCredential(), start))
     {
         try
         {
             var pizzas = await pizzaServer.CreatePizzaUsingPOSTAsync(pizza);
         }
         catch (HttpOperationException ex)
         {
             if (ex.Message == "Operation returned an invalid status code 'Created'")
             {
                 //eat it
                 Console.WriteLine($"Added new Pizza {pizza.Name}");
             }
             else
             {
                 DisplayErrorMessage("Failed to add new Pizzag {name}");
             }
         }
         catch (Exception ex)
         {
             if (ex.Message == "Operation returned an invalid status code 'Created'")
             {
             }
             else
             {
                 DisplayErrorMessage("Failed to add new Pizzag {name}");
             }
         }
         finally
         {
             await GetPizzasAsync();
         }
     }
 }
예제 #6
0
 private static async Task AddToppingAsync(string name)
 {
     DelegatingHandler[] start = null;
     using (var pizzaServer = new PizzaServer.PizzaServerRESTAPI(new AnonymousCredential(), start))
     {
         try
         {
             var result = await pizzaServer.CreateToppingUsingPOSTAsync(new Topping { Name = name });
         }
         catch (Exception ex)
         {
             if (ex.Message == "Operation returned an invalid status code 'Created'")
             {
                 //eat it
                 Console.WriteLine($"Added Topping {name}");
                 await GetToppingsAsync();
             }
             else
             {
                 DisplayErrorMessage("Failed to add Topping {name}");
             }
         }
     }
 }