コード例 #1
0
        public ForecastViewModel(Forecast forecast)
        {   
            Forecast = forecast;
            Date = forecast.Date;
            Weather = forecast.Weather;
            Title = string.Format(forecast.Date.ToString("dddd d{0} MMMM"), Date.DaySuffix());
            IssuedBy = string.Format("Issued by The Met Office on {0} at {1}",
                string.Format(forecast.Date.ToString("d{0} MMM"), Date.DaySuffix()),
                string.Format(forecast.Date.ToString("hh:ss")));

            if (forecast.WeatherPPN != null && forecast.WeatherPPN.WxPeriods != null)
            {
                int code = forecast.WeatherPPN.WxPeriods
                    .Where(x => x.No > 2 && x.No < 7)
                    .Select(x => x.Weather)
                    .Mode();

                var weatherCode = WeatherCodes.Instance.FirstOrDefault(x => x.Code == code);

                if (weatherCode != null && !string.IsNullOrEmpty(weatherCode.Icon))
                    Icon = weatherCode.Icon;

                WeatherPeriods = forecast.WeatherPPN.WxPeriods
                    .Select(period => new WeatherPeriodViewModel(period))
                    .ToList();
            }
        } 
コード例 #2
0
        private Forecast ParseForecast(JToken token, DateTime datetime)
        {
            var forecast = new Forecast
            {
                Date = datetime,
                Weather = (string)token["Weather"],
                Visibility = (string)token["Visibility"],
                HillFog = (string)token["HillFog"],
                MaxWindLevel = (string)token["MaxWindLevel"],
                MaxWind = (string)token["MaxWind"],
                TempLowLevel = (string)token["TempLowLevel"],
                TempHighLevel = (string)token["TempHighLevel"],
                FreezingLevel = (string)token["FreezingLevel"]                             
            };

            if (token["WeatherPPN"] != null)
            {
                var wxPeriod = token["WeatherPPN"]["WxPeriod"];

                forecast.WeatherPPN = new WeatherPPN
                { 
                    WxPeriods = wxPeriod.Select(period =>
                            new WxPeriod
                        {
                            No = (short)period["period"],
                            Period = (string)period["Period"],
                            Weather = (int)period["Weather"],
                            Probability = (string)period["Probability"],
                            PpnType = (string)period["Ppn_type"]
                            }).ToArray()
                }; 
            }

            return forecast;
        }