Пример #1
0
        static async Task <WeatherData> GetCurrentWeatherDataAsync(LocationCoordinates coordinates)
        {
            string url;

            StringBuilder sb = new StringBuilder();

            sb.Clear();
            sb.Append("http://api.openweathermap.org/data/2.5/weather?");
            sb.Append("&lat=" + coordinates.Latitude.ToString());
            sb.Append("&lon=" + coordinates.Longitude.ToString());
            sb.Append("&appid=864d252afc928abff4010abe732617a1");

            url = sb.ToString();

            WeatherData currentWeather = new WeatherData();

            Task <WeatherData> getCurrentWeather = HttpGetCurrentWeatherByLocationAsync(url);

            //
            // Note: The Wait() method is necessary so that the app does not proceed
            //       to the menu before returning the weather data. If there is an issue
            //       returning the data, the Wait() will create a deadlock in the app flow.
            //
            getCurrentWeather.Wait();

            currentWeather = await getCurrentWeather;

            return(currentWeather);
        }
Пример #2
0
        static void DisplayCurrentWeather(LocationCoordinates coordinates)
        {
            DisplayHeader("Current Weather");

            WeatherData currentWeatherData = GetCurrentWeatherData(coordinates);

            Console.WriteLine(String.Format("Temperature (Fahrenheit): {0:0.0}", ConvertToFahrenheit(currentWeatherData.Main.Temp)));

            DisplayContinuePrompt();
        }
Пример #3
0
        static async Task DisplayCurrentWeatherAsync(LocationCoordinates coordinates)
        {
            Console.Clear();

            DisplayHeader("Current Weather");

            WeatherData currentWeatherData = await GetCurrentWeatherDataAsync(coordinates);

            Console.WriteLine(String.Format("Temperature (Fahrenheit): {0:0.0}", ConvertToFahrenheit(currentWeatherData.Main.Temp)));

            DisplayContinuePrompt();
        }
Пример #4
0
        static void DisplayMenu()
        {
            bool quit = false;
            LocationCoordinates coordinates = new LocationCoordinates(0, 0);
            LocationZip         zips        = new LocationZip(0);

            while (!quit)
            {
                DisplayHeader("Main Menu");

                Console.WriteLine("Enter the number of your menu choice.");
                Console.WriteLine();
                Console.WriteLine("1) Set the Location by Coordinates");
                Console.WriteLine("2) Set the Location by Zip Code");
                Console.WriteLine("3) Display the Current Weather by Coordinates");
                Console.WriteLine("4) Display the Current Weather by Zip");
                Console.WriteLine("5) Exit");
                Console.WriteLine();
                Console.Write("Enter Choice:");
                string userMenuChoice = Console.ReadLine();

                switch (userMenuChoice)
                {
                case "1":
                    coordinates = DisplayGetLocationByCoordinates();
                    break;

                case "2":
                    zips = DisplayGetLocationByZip();
                    break;

                case "3":
                    DisplayCurrentWeather(coordinates);
                    break;

                case "4":
                    DisplayCurrentWeatherByZip(zips);
                    break;

                case "5":
                    quit = true;
                    break;

                default:
                    Console.WriteLine("You must enter a number from the menu.");
                    break;
                }
            }
        }
Пример #5
0
        static void DisplayCurrentWeather(LocationCoordinates coordinates)
        {
            DisplayHeader("Current Weather by Coordinates");

            WeatherData currentWeatherData = GetCurrentWeatherData(coordinates);

            Console.WriteLine(String.Format("Temperature (Fahrenheit): {0:0.0}", ConvertToFahrenheit(currentWeatherData.Main.Temp)));
            Console.WriteLine(String.Format("Wind: {0:0.0}", currentWeatherData.Wind.Speed));
            Console.WriteLine(String.Format("Visibility: {0:0.0}", currentWeatherData.Visibility));
            Console.WriteLine(String.Format("Pressure: {0}", currentWeatherData.Main.Pressure));
            Console.WriteLine(String.Format("Humidity: {0:0.0}", currentWeatherData.Main.Humidity));


            DisplayContinuePrompt();
        }
Пример #6
0
        static LocationCoordinates DisplayGetLocation()
        {
            DisplayHeader("Set Location by Coordinates");

            LocationCoordinates coordinates = new LocationCoordinates();

            Console.Write("Enter Latitude: ");
            coordinates.Latitude = double.Parse(Console.ReadLine());

            Console.Write("Enter longitude: ");
            coordinates.Longitude = double.Parse(Console.ReadLine());

            Console.WriteLine();
            Console.WriteLine($"Location Coordinates: ({coordinates.Latitude}, {coordinates.Longitude})");
            Console.WriteLine();

            DisplayContinuePrompt();

            return(coordinates);
        }
Пример #7
0
        static WeatherData GetCurrentWeatherData(LocationCoordinates coordinates)
        {
            string url;

            StringBuilder sb = new StringBuilder();

            sb.Clear();
            sb.Append("http://api.openweathermap.org/data/2.5/weather?");
            sb.Append("&lat=" + coordinates.Latitude.ToString());
            sb.Append("&lon=" + coordinates.Longitude.ToString());
            sb.Append("&appid=5e8d3f877557f170f55863ff55ad54f5");

            url = sb.ToString();

            WeatherData currentWeather = new WeatherData();

            currentWeather = HttpGetCurrentWeatherByLocation(url);

            return(currentWeather);
        }
Пример #8
0
        static WeatherData GetCurrentWeatherData(LocationCoordinates coordinates)
        {
            string url;

            StringBuilder sb = new StringBuilder();

            sb.Clear();
            sb.Append("http://api.openweathermap.org/data/2.5/weather?");
            sb.Append("&lat=" + coordinates.Latitude.ToString());
            sb.Append("&lon=" + coordinates.Longitude.ToString());
            sb.Append("&appid=864d252afc928abff4010abe732617a1");

            url = sb.ToString();

            WeatherData currentWeather = new WeatherData();

            currentWeather = HttpGetCurrentWeatherByLocation(url);

            return(currentWeather);
        }