Пример #1
0
        public MsnWeather(MsnCurrentWeather currentWeather, List<MsnForecastWeather> forecasts)
        {
            if (currentWeather == null) throw new ArgumentNullException(nameof(currentWeather));
            if (forecasts == null) throw new ArgumentNullException(nameof(forecasts));

            this.CurrentWeather = currentWeather;
            this.Forecasts = forecasts;
        }
Пример #2
0
        private static MsnCurrentWeather ParseCurrent(XElement input)
        {
            var current = new MsnCurrentWeather();

            foreach (var element in input.Descendants(XName.Get(@"current")))
            {
                foreach (var attribute in element.Attributes())
                {
                    var value = attribute.Value.Trim();

                    var name = attribute.Name.LocalName;
                    if (name.Equals(@"temperature", StringComparison.OrdinalIgnoreCase))
                    {
                        current.Temperature = GetDouble(value);
                        continue;
                    }
                    if (name.Equals(@"skycode", StringComparison.OrdinalIgnoreCase))
                    {
                        current.IconCode = GetIconCode(value);
                        continue;
                    }
                    if (name.Equals(@"skytext", StringComparison.OrdinalIgnoreCase))
                    {
                        current.Description = value;
                        continue;
                    }
                    if (name.Equals(@"date", StringComparison.OrdinalIgnoreCase))
                    {
                        current.Date = GetDate(value);
                        continue;
                    }
                    if (name.Equals(@"observationtime", StringComparison.OrdinalIgnoreCase))
                    {
                        current.Date = current.Date.Add(GetTimeSpan(value));
                        continue;
                    }
                    if (name.Equals(@"observationpoint", StringComparison.OrdinalIgnoreCase))
                    {
                        current.Point = value;
                        continue;
                    }
                    if (name.Equals(@"feelslike", StringComparison.OrdinalIgnoreCase))
                    {
                        current.Feelslike = GetDouble(value);
                        continue;
                    }
                    if (name.Equals(@"humidity", StringComparison.OrdinalIgnoreCase))
                    {
                        current.Humidity = GetDouble(value);
                    }
                }
                break;
            }


            return current;
        }