public ObservableCollection<Forecast> GetForecasts()
        {
            var forecasts = new ObservableCollection<Forecast>();
            for (int i = 0; i < 3; i++)
            {
                var forecast = new Forecast()
                {
                    City = "City " + i
                };

                for (int j = 0; j < 3; j++)
                {
                    forecast.Forecasts.Add(new ForecastItem()
                    {
                        Description = "ein bisschen wolkig",
                        ConditionId = 801,
                        ConditionFontIcon =
                            ((char)int.Parse("EB48", System.Globalization.NumberStyles.HexNumber)).ToString(),
                        CloudinessPercentage = 80,
                        HumidityPercentage = 16,
                        WindDegreee = 310,
                        WindSpeed = 12,
                        TemperatureKelvin = 287,
                        PressurehPa = 1300,
                        Date = DateTime.Now,
                        RainVolume = 0,
                        SnowVolume = 0
                    });
                }

                forecasts.Add(forecast);
            }

            return forecasts;
        }
        public static void EvaluateFeed(string feed, Dictionary<string, string> weatherFontMapping, Forecast forecast)
        {
            forecast.Forecasts.Clear();
            var f = JsonConvert.DeserializeObject<Models.Forecast.RootObject>(feed);
            forecast.City = f.city.name;
            if (!string.IsNullOrEmpty(f.city.country))
                forecast.City += " (" + f.city.country + ")";
            foreach (var entry in f.list)
            {
                var item = new ForecastItem { Date = ConvertFromUnixTimestamp(entry.dt) };

                if (entry.main != null)
                {
                    item.HumidityPercentage = entry.main.humidity;
                    item.PressurehPa = entry.main.pressure;
                    item.TemperatureKelvin = entry.main.temp;
                }

                if (entry.weather != null && entry.weather.Any())
                {
                    var weather = entry.weather.FirstOrDefault();
                    item.ConditionId = weather.id;
                    if (weatherFontMapping.ContainsKey(weather.id.ToString()))
                        item.ConditionFontIcon = ((char)int.Parse(weatherFontMapping[weather.id.ToString()], System.Globalization.NumberStyles.HexNumber)).ToString();
                    item.Description = weather.description;
                }

                if (entry.clouds != null)
                {
                    item.CloudinessPercentage = entry.clouds.all;
                }

                if (entry.wind != null)
                {
                    item.WindDegreee = entry.wind.deg;
                    item.WindSpeed = entry.wind.speed;
                }

                if (entry.rain != null)
                {
                    item.RainVolume = entry.rain._3h;
                }

                if (entry.snow != null)
                {
                    item.RainVolume = entry.snow._3h;
                }

                forecast.Forecasts.Add(item);
            }
        }
示例#3
0
 public static void AddForecast(Forecast forecast)
 {
     Forecasts.Add(forecast);
 }
示例#4
0
 private Uri GetApiUrl(Forecast forecast)
 {
     return new Uri(Uri.EscapeUriString(_apiUrl.Replace("{city}", forecast.City)));
 }