static void Main(string[] args) { //Step 1: Create an instance of the WCF proxy. FridgeClient client = new FridgeClient(); Console.WriteLine("Add 3 oranges"); var total = client.AddFruit(Orange, 3); Console.WriteLine($"Total oranges = {total}"); Console.WriteLine("Add 2 apples"); total = client.AddFruit(Apple, 2); Console.WriteLine($"Total apples = {total}"); Console.WriteLine("Add 1 banana"); total = client.AddFruit(Banana, 1); Console.WriteLine($"Total bananas = {total}"); Console.WriteLine("Remove 1 banana"); total = client.RemoveFruit(Banana, 1); Console.WriteLine($"Total bananas = {total}"); Console.WriteLine("Remove 1 banana (no more left)"); total = client.RemoveFruit(Banana, 1); Console.WriteLine($"Total bananas = {total}"); Console.WriteLine("Remove 2 oranges (1 left)"); total = client.RemoveFruit(Orange, 2); Console.WriteLine($"Total oranges = {total}"); Console.WriteLine("Query fruit count"); total = client.TotalFruit(); Console.WriteLine($"Total fruit = {total}"); }
static void Main(string[] args) { FridgeClient client = new FridgeClient(); client.AddFood(4, "banana"); client.AddFood(5, "pear"); client.AddFood(6, "tomato"); client.AddFood(7, "pen"); client.AddFood(8, "bottle"); var totalFood = client.Food(); foreach (var f in totalFood) { Console.WriteLine($"There are {f.Value} {f.Key}'s in the fridge."); } client.SubtractFood(4, "bottle"); var totalFood1 = client.Food(); foreach (var f in totalFood1) { Console.WriteLine($"There are {f.Value} {f.Key}'s in the fridge."); } Console.WriteLine("\nPress <Enter> to terminate the client."); Console.ReadLine(); client.Close(); }
static void Main(string[] args) { //Step 1: Create an instance of the WCF proxy. FridgeClient client = new FridgeClient(); // Step 2: Call the service operations. // Call the Add service operation. Console.WriteLine($"There are {client.Add("apple", 10)} apples."); Console.WriteLine($"There are {client.Add("orange", 15)} oranges."); Console.WriteLine($"There are {client.Subtract("apple", 5)} apples."); Console.WriteLine($"There are {client.Get("pear")} pears."); client.Close(); }
static void Main(string[] args) { //Step 1: Create an instance of the WCF proxy. FridgeClient client = new FridgeClient(); var fridgeContent = client.FridgeContents(); Console.WriteLine("Fridge intially has these fruits in it."); foreach (var item in fridgeContent) { Console.WriteLine(item); } int result = 0; result = client.GetFruitTotal(); Console.WriteLine($"Total fruits in fridge is : {result}\n"); string fruit = "Papaya"; result = client.AddFruit("Papaya"); Console.WriteLine($"{fruit} added in"); fridgeContent = client.FridgeContents(); Console.WriteLine("Fridge now has these fruits in it."); foreach (var item in fridgeContent) { Console.WriteLine(item); } Console.WriteLine($"Total fruits in fridge is : {result}\n"); result = client.TakeFruit(fruit); Console.WriteLine($"\nI took out the {fruit} and ate it"); fridgeContent = client.FridgeContents(); Console.WriteLine("Fridge now has these fruits in it."); foreach (var item in fridgeContent) { Console.WriteLine(item); } Console.WriteLine($"Total fruits in fridge is : {result}\n"); // Step 3: Close the client to gracefully close the connection and clean up resources. Console.WriteLine("\nPress <Enter> to terminate the client."); Console.ReadLine(); client.Close(); }
static void Main(string[] args) { Console.WriteLine("Welcome to Nick's fridge"); // generated client class, object-oriented representation of the SOAP service (HTTP etc is encapsulated) using (var client = new FridgeClient()) { while (true) { Console.WriteLine("Press 1 to get all items, 2 to clean the fridge, 3 to exit"); char input = Console.ReadKey().KeyChar; Console.WriteLine(); switch (input) { case '1': FoodItem[] items = client.GetAllContents(); foreach (var item in items) { Console.WriteLine($"{item.Name} ({item.Id}), expires {item.ExpirationDate.Date}"); } Console.WriteLine(); break; case '2': FoodItem[] removedItems = client.Clean(); foreach (var item in removedItems) { Console.WriteLine($"{item.Name} ({item.Id}), expires {item.ExpirationDate.Date}"); } Console.WriteLine(); break; case '3': return; default: Console.WriteLine("Error"); break; } } } }
static void Main(string[] args) { //Step 1: Create an instance of the WCF proxy. FridgeClient client = new FridgeClient(); int fruit = client.HowMuchFruit(); Console.WriteLine("There are {0} pieces of fruit to start", fruit); Console.ReadLine(); fruit = client.AddFruit(5); Console.WriteLine("There are {0} pieces of fruit left after adding {1} pieces", fruit, 5); Console.ReadLine(); fruit = client.HowMuchFruit(); Console.WriteLine("There are now {0} pieces of fruit left", fruit); Console.ReadLine(); fruit = client.GetFruit(2); Console.WriteLine("There are now {0} pieces of fruit left after getting {1} pieces", fruit, 2); Console.ReadLine(); client.Close(); }