Пример #1
0
        //TODO this doesn't seem to update right at midnight, it will still retrieve yesterdays info for a while
        //We will need to fetch 7 days and perform a check to ensure we are getting between tomorrow and the 5th day.
        private static WeatherWeek ProcessWeeksWeatherData(WeeksWeatherData daysData)
        {
            WeatherWeek week = new WeatherWeek(DateTime.Now)
            {
                //Store tomorrow's date as 'long date' format: "Thursday, 10 April 2008"
                StartDate = DateTime.Today.AddDays(1),
                EndDate   = DateTime.Today.AddDays(5)
            };

            //Iterate through all weather data retrieved, starting at 1 because it includes today
            //and create WeatherHour objects for each
            for (int i = 1; i < daysData.cnt; i++)
            {
                DateTime date = UnixTimeStampToDateTime(daysData.list[i].dt);
                //If the current result is for today, process it and store it in today
                WeatherWeekDay weather = new WeatherWeekDay()
                {
                    HighTemperature = daysData.list[i].temp.max,
                    LowTemperature  = daysData.list[i].temp.min,
                    Date            = date,
                    IconId          = daysData.list[i].weather[0].icon,
                };
                week.AddDay(weather);
            }
            return(week);
        }
Пример #2
0
        //--------------------------------------------------------------------------------
        //-----------------------------End Tomorrow's Weather-----------------------------
        //--------------------------------------------------------------------------------


        //--------------------------------------------------------------------------------
        //---------------------------------Week's Weather---------------------------------
        //--------------------------------------------------------------------------------
        //TODO set this method up to handle issues where the read fails.
        public static WeatherWeek FetchWeeksWeather(Location location)
        {
            WeeksWeatherData forecast = GetWeeksWeatherForecastData(location);
            WeatherWeek      week     = null;

            if (forecast != null)
            {
                week = ProcessWeeksWeatherData(forecast);
            }
            return(week);
        }
        public void UpdateWeeksWeather(Location location)
        {
            WeatherWeek weather = WeatherService.FetchWeeksWeather(location);
            List <WeatherWeekDayViewModel> daysList = new List <WeatherWeekDayViewModel>();

            foreach (WeatherWeekDay day in weather.WeatherDays)
            {
                string                  high  = day.HighTemperature.ToString("F0");
                string                  low   = day.LowTemperature.ToString("F0");
                string                  date  = day.Date.ToString("MM/dd");
                BitmapImage             icon  = new BitmapImage(new Uri("ms-appx:/Assets/Weather/" + day.IconId + ".png"));
                WeatherWeekDayViewModel dayVM = new WeatherWeekDayViewModel(high, low, date, icon);
                daysList.Add(dayVM);
            }
            weeksWeather.WeatherDays = daysList;
            weeksWeather.Location    = location.City + "," + location.State;
            weeksWeather.DateRange   = weather.StartDate.ToString("MM/dd") + " - " + weather.EndDate.ToString("MM/dd");
            weeksWeather.ReadTime    = weather.ReadTime.ToString("g");
        }