Example #1
0
        public BusinessWeatherForecast Make(WeatherForecast weatherForecast)
        {
            var bitmap       = Resources.ResourceManager.GetObject(weatherForecast.CurrentForecast.Icon) as Bitmap;
            var bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                bitmap.GetHbitmap(),
                IntPtr.Zero,
                System.Windows.Int32Rect.Empty,
                BitmapSizeOptions.FromWidthAndHeight(100, 100));

            BusinessWeatherForecast forecast = new BusinessWeatherForecast
            {
                Date        = formatter.GetNumberAndMonth(weatherForecast.CurrentForecast.Time),
                Time        = formatter.GetTime(weatherForecast.CurrentForecast.Time),
                Temperature = Convert.ToInt32(((weatherForecast.CurrentForecast.Temperature - 32) * 5 / 9)).ToString(),
                WindSpeed   = weatherForecast.CurrentForecast.WindSpeed.ToString(),
                CloudCover  = weatherForecast.CurrentForecast.Summary,
                Icon        = bitmapSource,

                WeekForecast = weatherForecast.WeekForecast.WeekForecasts.Select(df => new BusinessDailyForecast
                {
                    DayWeek          = formatter.GetWeekDay(df.Time),
                    Date             = formatter.GetShortDate(df.Time),
                    RangeTemperature = df.TemperatureMin.ToString() + "-" + df.TemperatureMax.ToString(),
                    WindSpeed        = df.WindSpeed.ToString(),
                    Icon             = Application.Current.Resources[df.Icon]
                }).ToList(),
            };

            return(forecast);
        }
Example #2
0
        private async void UpdateForecast()
        {
            var _forecast = await weatherService.GetWeather();

            Forecast = factory.Make(_forecast);
        }