Exemplo n.º 1
0
        private static WeatherDay ProcessTodaysWeatherData(DaysWeatherData daysData, Location location)
        {
            WeatherDay today = new WeatherDay(DateTime.Now)
            {
                //Store tomorrow's date as 'long date' format: "Thursday, 10 April 2008"
                Date            = DateTime.Today,
                WeatherLocation = location
            };

            //Iterate through all weather data retrieved and create WeatherHour objects
            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
                if (ValidTimeToday(date))
                {
                    WeatherHour weather = new WeatherHour
                    {
                        Temperature = daysData.list[i].main.temp,
                        IconId      = daysData.list[i].weather[0].icon,
                        WeatherType = daysData.list[i].weather[0].main,
                        Time        = date
                    };
                    today.WeatherDays.Add(weather);
                }
            }
            return(today);
        }
Exemplo n.º 2
0
        //--------------------------------------------------------------------------------
        //------------------------------End Current Weather-------------------------------
        //--------------------------------------------------------------------------------



        //--------------------------------------------------------------------------------
        //---------------------------------Today's Weather--------------------------------
        //--------------------------------------------------------------------------------
        //TODO set this method up to handle issues where the read fails.
        public static WeatherDay FetchTodaysWeather(Location location)
        {
            DaysWeatherData forecast = GetWeatherForecastData(location);
            WeatherDay      today    = null;

            if (forecast != null)
            {
                today = ProcessTodaysWeatherData(forecast, location);
            }
            return(today);
        }
Exemplo n.º 3
0
        //--------------------------------------------------------------------------------
        //-------------------------------End Today's Weather------------------------------
        //--------------------------------------------------------------------------------



        //--------------------------------------------------------------------------------
        //-------------------------------Tomorrow's Weather-------------------------------
        //--------------------------------------------------------------------------------
        //TODO set this method up to handle issues where the read fails.
        public static WeatherDay FetchTomorrowsWeather(Location location)
        {
            //Read tomorrows weather data and process it into a Weather Day format
            DaysWeatherData forecast = GetWeatherForecastData(location);
            WeatherDay      tomorrow = null;

            if (forecast != null)
            {
                tomorrow = ProcessTomorrowsWeatherData(forecast, location);
            }
            return(tomorrow);
        }
        private void ConvertWeatherDayToWeatherDayViewModel(WeatherDay model, WeatherDayViewModel viewModel)
        {
            List <WeatherHourViewModel> hoursList = new List <WeatherHourViewModel>();

            foreach (WeatherHour hour in model.WeatherDays)
            {
                string               temp   = hour.Temperature.ToString("F0");
                string               time   = hour.Time.ToString("h:mm tt");
                BitmapImage          icon   = new BitmapImage(new Uri("ms-appx:/Assets/Weather/" + hour.IconId + ".png"));
                WeatherHourViewModel hourVM = new WeatherHourViewModel(time, temp, icon);
                hoursList.Add(hourVM);
            }
            viewModel.WeatherHours = hoursList;
            viewModel.Location     = model.WeatherLocation.City + ", " + model.WeatherLocation.State;
            viewModel.Date         = model.Date.ToString("M");
            viewModel.ReadTime     = model.ReadTime.ToString("g");
        }
        public void UpdateTomorrowsWeather(Location location)
        {
            WeatherDay weather = WeatherService.FetchTomorrowsWeather(location);

            ConvertWeatherDayToWeatherDayViewModel(weather, tomorrowsWeather);
        }