Пример #1
0
 // Reads all available cities from json file and stores it in cityList
 private void ReadCityList()
 {
     using (StreamReader stream = new StreamReader(cityListFilePath))
     {
         string data = stream.ReadToEnd();
         cityList = JsonConvert.DeserializeObject <CityList>(data);
     }
 }
Пример #2
0
        public void RequestWeatherInfo(string city)
        {
            var searchCityId = CityList.Where(c => c.Name == city).Select(c => c.Id).FirstOrDefault();

            string url = @"https://api.openweathermap.org/data/2.5/forecast?units=metric&APPID=eb5e75d2643132a6c84e9c510ec6219e&id=";

            using (var client = new WebClient())
            {
                client.DownloadStringAsync(new Uri(url + searchCityId));
                client.DownloadStringCompleted += ClientDownloadStringCompleted;
                client.DownloadStringCompleted += RefreshUI;
            }
        }
Пример #3
0
        public void Refresh()
        {
            string selectedCity = citySelector.Text.Substring(0, 1).ToUpper() + citySelector.Text.Substring(1, citySelector.Text.Length - 1);

            if (!CityList.Any(c => c.Name == selectedCity))
            {
                MessageBox.Show("error");
                return;
            }

            WeatherModelUIs = new List <WeatherModel>();

            RequestWeatherInfo(selectedCity);
        }