コード例 #1
0
        private static async Task <ObservableCollection <WeatherModel> > GetWeather(string location)
        {
            var url = string.Format("http://api.openweathermap.org/data/2.5/forecast?zip={0}&units=imperial&APPID=a0a0e5e6d1ded0c79e853990c86f957b", location);

            var client   = new HttpClient();
            var response = await client.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                ObservableCollection <WeatherModel> weatherList = new ObservableCollection <WeatherModel>();
                string content = await response.Content.ReadAsStringAsync();

                var          data = JsonConvert.DeserializeObject <WeatherResult>(content);
                WeatherModel model;
                foreach (var item in data.list)
                {
                    model             = new WeatherModel();
                    model.date        = Convert.ToDateTime(item.dt_txt);
                    model.humidity    = item.main.humidity;
                    model.pressure    = item.main.pressure;
                    model.description = item.weather[0].description;
                    model.hightemp    = item.main.temp_min;
                    model.lowtemp     = item.main.temp_max;
                    weatherList.Add(model);
                }
                return(weatherList);
            }
            else
            {
                throw new Exception(await response.Content.ReadAsStringAsync());
            }
        }
コード例 #2
0
 public void EndEdit()
 {
     _clone = null;
 }
コード例 #3
0
 public void BeginEdit()
 {
     _clone = (WeatherModel)this.MemberwiseClone();
 }