Exemplo n.º 1
0
        static async Task <Uri> InitializeLawnAsync(LawnSize lawnsize)
        {
            try
            {
                HttpResponseMessage response = await Client.PostAsJsonAsync("Lawn", lawnsize);

                response.EnsureSuccessStatusCode();
                // Return the URI of the created resource.
                return(response.Headers.Location);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error occur while initializing lawn : {ex.Message}");
            }
            return(null);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to SLMM Application Client");

            // REgister with the notification hub
            //InitializeSignalRClient();
            GetLogAndPrint();


            Console.WriteLine("Please provide  width of the lawn ");
            string sWidth = Console.ReadLine();
            int    Width  = Int32.Parse(sWidth);


            Console.WriteLine("Please provide  height of the lawn ");
            string sHeight = Console.ReadLine();
            int    Height  = Int32.Parse(sWidth);


            LawnSize size = new LawnSize()
            {
                SizeX = Width, SizeY = Height, StartX = 0, StartY = 0
            };

            InitializeLawnAsync(size);

            // Initialize the client   client.DefaultRequestHeaders.Accept.Clear();
            Client.DefaultRequestHeaders.Accept.Clear();
            Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var exit = false;

            ShowHelp();
            while (!exit)
            {
                string input = Console.ReadLine()?.ToLower();
                switch (input)
                {
                case "tl":
                    SaveExecution(() => TurnMachine(-1));
                    break;

                case "tr":
                    SaveExecution(() => TurnMachine(1));
                    break;

                case "mf":
                    SaveExecution(async() =>
                    {
                        Console.WriteLine("Enter steps to move:");
                        int steps;
                        if (!int.TryParse(Console.ReadLine(), out steps))
                        {
                            Console.WriteLine("Invalid input. Number is expected.");
                        }
                        else
                        {
                            await Client.PutAsJsonAsync("location", steps).ContinueWith(PrintResult);
                        }
                    });
                    break;

                case "ml":
                    SaveExecution(() => Client.PutAsJsonAsync("mower", true).ContinueWith(PrintResult));
                    break;

                case "exit":
                    exit = true;
                    break;

                default:
                    Console.WriteLine("Not supported command.");
                    break;
                }
            }
        }