Exemple #1
0
        private static async void GetRoute()
        {
            // Declare variables and set to empty
            string        originInput      = "";
            string        destinationInput = "";
            string        stationInput     = "";
            string        cityInput        = "";
            string        resu             = "";
            List <string> names            = new List <string>();

            Console.WriteLine("Choose the orgin place please, and then press Enter: ");
            Console.WriteLine("\t1 - From a velib station in a city");
            Console.WriteLine("\t2 - From any place you want.");

            string op = Console.ReadLine();

            try
            {
                switch (op)
                {
                case "1":
                    Console.WriteLine("Please enter the no. of the station and city seperated by space (e.g. 555 Lyon): ");
                    List <string> input = new List <string>();
                    input        = Console.ReadLine().Split(' ').ToList();
                    stationInput = input[0];
                    if (input.Count == 2)
                    {
                        cityInput = input[1];
                    }
                    if (!stationInput.Equals("") && !cityInput.Equals(""))
                    {
                        string tmp = client.GetInfomationsOfStationByNameAsync(cityInput, stationInput).Result;

                        if (tmp != "Not Found!")
                        {
                            resu = tmp;
                            List <string> res = new List <string>();
                            res = resu.Split('\n').ToList();
                            string ordi = res[6] + "," + res[7];
                            ordi        = ordi.Replace(" ", "");
                            originInput = ordi;
                        }
                        else
                        {
                            Console.WriteLine("Please return to main page to get the correct No.");
                        }
                    }


                    break;

                case "2":
                    Console.WriteLine("Please enter your origin: ");
                    originInput = Console.ReadLine();
                    break;

                default:
                    break;
                }
            }


            catch (Exception e)
            {
                Console.WriteLine("Oh no! An exception occurred trying to do the search.\n - Details: " + e.Message);
            }

            Console.WriteLine("Choose the destination place please, and then press Enter: ");
            Console.WriteLine("\t1 - To a velib station in a city");
            Console.WriteLine("\t2 - To any place you want.");

            op = Console.ReadLine();

            try
            {
                switch (op)
                {
                case "1":
                    Console.WriteLine("Please enter the no. of the station and city seperated by space (e.g. 555 Lyon): ");
                    List <string> input = new List <string>();
                    input        = Console.ReadLine().Split(' ').ToList();
                    stationInput = input[0];
                    if (input.Count == 2)
                    {
                        cityInput = input[1];
                    }
                    if (!stationInput.Equals("") && !cityInput.Equals(""))
                    {
                        string tmp = client.GetInfomationsOfStationByNameAsync(cityInput, stationInput).Result;

                        if (tmp != "Not Found!")
                        {
                            resu = tmp;
                            List <string> res = new List <string>();
                            res = resu.Split('\n').ToList();
                            string ordi = res[6] + "," + res[7];
                            ordi             = ordi.Replace(" ", "");
                            destinationInput = ordi;
                        }
                        else
                        {
                            Console.WriteLine("Please return to main page to get the correct No.");
                        }
                    }


                    break;

                case "2":
                    Console.WriteLine("Please enter your destination: ");
                    destinationInput = Console.ReadLine();
                    break;

                default:
                    break;
                }
            }


            catch (Exception e)
            {
                Console.WriteLine("Oh no! An exception occurred trying to do the search.\n - Details: " + e.Message);
            }

            //wait for the result
            List <string> result = client.GetRouteAsync(originInput, destinationInput).Result.ToList <string>();

            foreach (var item in result)
            {
                string ins = item.Replace("<b>", "");
                ins = ins.Replace("</b>", "");
                ins = ins.Replace("</div>", "");
                ins = ins.Replace("<div style=\"font-size:0.9em\">", " ");
                Console.WriteLine(ins);
            }
        }