Beispiel #1
0
        public void DownloadCityWeather(City city)
        {
            DateTime       start     = DateTime.Now;
            string         url       = string.Format("http://api.openweathermap.org/data/2.5/weather?APPID=75a3e7d73376fa1ae08a542ca103899a&id={0}", city._Id);
            WebClient      client    = new WebClient();
            string         json      = client.DownloadString(url);
            JsonViewModel  jsonModel = new JavaScriptSerializer().Deserialize <JsonViewModel>(json);
            WeatherReading weather   = new WeatherReading()
            {
                CityID      = city.CityID,
                Temperature = jsonModel.Main.Temp,
                Humidity    = jsonModel.Main.Humidity,
                Date        = DateTime.Now
            };

            weatherRepository.AddWeatherReading(weather);
            DateTime stop     = DateTime.Now;
            TimeSpan timeSpan = start - stop;
            double   seconds  = timeSpan.TotalSeconds;
        }