コード例 #1
0
        //--------------------------------------------------------------------------------
        //--------------------------------Current Weather---------------------------------
        //--------------------------------------------------------------------------------
        //TODO set this method up to handle issues where the read fails.
        public static WeatherCurrent FetchCurrentWeather(Location location)
        {
            //Read the weather then assign all the fields of Today
            WeatherData    today         = GetCurrentWeatherData(location);
            WeatherCurrent todaysWeather = new WeatherCurrent(DateTime.Now);

            if (today != null)
            {
                todaysWeather.Temperature     = today.main.temp;
                todaysWeather.WeatherType     = today.weather[0].main;
                todaysWeather.IconId          = today.weather[0].icon;
                todaysWeather.HighTemperature = today.main.temp_max;
                todaysWeather.LowTemperature  = today.main.temp_min;
                todaysWeather.WeatherLocation = location;
                todaysWeather.Date            = UnixTimeStampToDateTime(today.dt);
            }
            return(todaysWeather);
        }
コード例 #2
0
        public void UpdateCurrentWeather(Location location)
        {
            //Fetch the new weather information from WeatherService
            WeatherCurrent weather = WeatherService.FetchCurrentWeather(location);

            //Update the view model, currentWeather
            currentWeather.Temperature = weather.Temperature.ToString("F0");
            currentWeather.HighTemp    = weather.HighTemperature.ToString("F0");
            currentWeather.LowTemp     = weather.LowTemperature.ToString("F0");
            currentWeather.Location    = location.City + ", " + location.State;
            currentWeather.Date        = weather.Date.ToString("M");
            currentWeather.ReadTime    = weather.ReadTime.ToString("g");
            currentWeather.WeatherType = weather.WeatherType;
            if (IconNeedsUpdate(currentWeather.CurrentIcon, weather.IconId))
            {
                currentWeather.WeatherIcon = new BitmapImage(new Uri("ms-appx:/Assets/Weather/" + weather.IconId + ".png"));
            }
        }