Exemple #1
0
        /// <summary>
        /// Displays weather forecast for tommorow to the user
        /// </summary>
        public static void DisplayForecastWeather()
        {
            WeatherCity newWC = wcf.Tommorow;

            string skyInfo = newWC.weather[0]["description"];

            if (weatherDictionary.ContainsKey(newWC.weather[0]["description"]))
            {
                if (Controller.language == Controller.Lang.pl)
                {
                    skyInfo = weatherDictionary[newWC.weather[0]["description"]];
                }
                else if (Controller.language == Controller.Lang.en)
                {
                    skyInfo = newWC.weather[0]["description"];
                }
            }

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(skyInfo);
            Console.ForegroundColor = ConsoleColor.Gray;

            if (Controller.language == Controller.Lang.pl)
            {
                Console.Write("Temperatura rano: ");
            }
            else if (Controller.language == Controller.Lang.en)
            {
                Console.Write("Morning temperature: ");
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(newWC.GetMorningCelsiusTemperature() + "°C");
            Console.ForegroundColor = ConsoleColor.Gray;

            if (Controller.language == Controller.Lang.pl)
            {
                Console.Write("Temperatura w dzień: ");
            }
            else if (Controller.language == Controller.Lang.en)
            {
                Console.Write("Day temperature: ");
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(newWC.GetDayCelsiusTemperature() + "°C");
            Console.ForegroundColor = ConsoleColor.Gray;

            if (Controller.language == Controller.Lang.pl)
            {
                Console.Write("Temperatura wieczorem: ");
            }
            else if (Controller.language == Controller.Lang.en)
            {
                Console.Write("Evening temperature: ");
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(newWC.GetNightCelsiusTemperature() + "°C");
            Console.ForegroundColor = ConsoleColor.Gray;
        }
Exemple #2
0
        /// <summary>
        /// Gets weather for a choosen city and asynchronically fills 'wc' object with it
        /// </summary>
        public static async Task GetWeatherAsync(string userInput)
        {
            // Make a request to weather API
            string apiCallUrl = @"http://api.openweathermap.org/data/2.5/weather?q=" + userInput + "&APPID=c656c46298cb34e764fd34a3659ad500";
            string resp       = "";

            // Check if there was a problem with fetching weather info
            try
            {
                resp = await client.GetStringAsync(apiCallUrl);
            }
            catch (HttpRequestException)
            {
                DisplayErrorMessage();
                requestSuccesfull = false;
                return;
            }

            //Console.WriteLine(resp); //Debug

            // Fill information about weather in specified city
            wc = JsonConvert.DeserializeObject <WeatherCity>(resp);
            requestSuccesfull = true;
        }