Пример #1
0
        static async Task RunAsync()
        {
            Options opt = RunMenu();
            string  url = GetRequestURL(opt);

            try
            {
                if (opt.type == "weather?") //<- this is filled in at menu
                {
                    WeatherCurrentMessage msg = await GetCurrentWeatherAsync(url);

                    ShowWeather(msg);
                }
                else
                {
                    WeatherForecastMessage msg = await GetForecastWeatherAsync(url);

                    ShowWeather(msg);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #2
0
        static async Task <WeatherCurrentMessage> GetCurrentWeatherAsync(string path)
        {
            WeatherCurrentMessage weather = null;
            var uri = new Uri(path);
            HttpResponseMessage response = await http.GetAsync(uri.AbsoluteUri);

            if (response.IsSuccessStatusCode)
            {
                weather = await response.Content.ReadAsAsync <WeatherCurrentMessage>();
            }

            return(weather);
        }
Пример #3
0
 static void ShowWeather(WeatherCurrentMessage weather)
 {
     Console.Clear();
     Console.WriteLine("Current Weather =>");
     Console.WriteLine($"Name: {weather.name}, Date: {epoch2string(weather.dt)}");
 }