private static Common.Weather.WeatherPoint ConvertToWeatherPoint(WeatherCurrentCondition source, WeatherArea area) { var destination = new Common.Weather.WeatherPoint(); if (area != null) { destination.Location = new Common.Weather.Location(); destination.Location.Country = area.Country; destination.Location.Locality = area.AreaName; destination.Location.Latitude = area.Latitude; destination.Location.Longitude = area.Longitude; } destination.Weather = new Common.Weather.WeatherPointData(); destination.Weather.Condition = ConvertToWeatherCondition(source.WeatherCode); if (source.TemperatureCelsius.HasValue) { destination.Weather.Temperature = new Common.Weather.Temperature() { Celsius = source.TemperatureCelsius.Value }; } else if (source.TemperatureFahrenheit.HasValue) { destination.Weather.Temperature = new Common.Weather.Temperature() { Fahrenheit = source.TemperatureFahrenheit.Value }; } destination.Weather.Humidity = source.Humidity; destination.Weather.Pressure = source.Pressure; destination.Weather.WindDirection = source.WindDirection; destination.Weather.WindSpeed = source.WindspeedKmph; if (source.Precipitation.GetValueOrDefault(0) > 0) { destination.Weather.PrecipitationType = Common.Weather.PrecipitationType.Rain; destination.Weather.Precipitation = source.Precipitation; } destination.Weather.Visibility = source.Visibility; destination.Weather.CloudCover = source.CloudCover; return destination; }
private static Common.Weather.WeatherPoint ConvertToWeatherPoint(WeatherResponse source) { var destination = new Common.Weather.WeatherPoint(); destination.Location = new Location(); destination.Location.Latitude = source.Latitude; destination.Location.Longitude = source.Longitude; return destination; }
public WeatherPoint GetCurrentWeather(string woeId) { try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(string.Format("http://weather.yahooapis.com/forecastrss?w={0}&u=c", woeId)); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { var document = new System.Xml.XPath.XPathDocument(response.GetResponseStream()); var navigator = document.CreateNavigator(); XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable); manager.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0"); var temperature = navigator.SelectSingleNode("rss/channel/item/yweather:condition/@temp", manager); var conditionCode = navigator.SelectSingleNode("rss/channel/item/yweather:condition/@code", manager); var windSpeed = navigator.SelectSingleNode("rss/channel/yweather:wind/@speed", manager); var windChill = navigator.SelectSingleNode("rss/channel/yweather:wind/@chill", manager); var windDirection = navigator.SelectSingleNode("rss/channel/yweather:wind/@direction", manager); var atmosphereHumidity = navigator.SelectSingleNode("rss/channel/yweather:atmosphere/@humidity", manager); var atmosphereVisibility = navigator.SelectSingleNode("rss/channel/yweather:atmosphere/@visibility", manager); var atmospherePressure = navigator.SelectSingleNode("rss/channel/yweather:atmosphere/@pressure", manager); //var atmosphereRising= navigator.SelectSingleNode("rss/channel/yweather:atmosphere/@rising", manager); var astronomySunrise = navigator.SelectSingleNode("rss/channel/yweather:astronomy/@sunrise", manager); var astronomySunset = navigator.SelectSingleNode("rss/channel/yweather:astronomy/@sunset", manager); var weatherPoint = new Common.Weather.WeatherPoint() { Timestamp = DateTime.Now, Weather = new Common.Weather.WeatherPointData() }; weatherPoint.Weather.Temperature = new Common.Weather.Temperature() { Celsius = decimal.Parse(temperature.Value, System.Globalization.NumberFormatInfo.InvariantInfo) }; if (conditionCode != null && !string.IsNullOrEmpty(conditionCode.Value)) { weatherPoint.Weather.Condition = GetWeatherCondition(conditionCode.Value); } if (windChill != null && !string.IsNullOrEmpty(windChill.Value)) { weatherPoint.Weather.WindChill = decimal.Parse(windChill.Value, System.Globalization.NumberFormatInfo.InvariantInfo); } if (windSpeed != null && !string.IsNullOrEmpty(windSpeed.Value)) { weatherPoint.Weather.WindSpeed = decimal.Parse(windSpeed.Value, System.Globalization.NumberFormatInfo.InvariantInfo); } if (windDirection != null && !string.IsNullOrEmpty(windDirection.Value)) { weatherPoint.Weather.WindDirection = decimal.Parse(windDirection.Value, System.Globalization.NumberFormatInfo.InvariantInfo); } if (atmospherePressure != null && !string.IsNullOrEmpty(atmospherePressure.Value)) { weatherPoint.Weather.Pressure = decimal.Parse(atmospherePressure.Value, System.Globalization.NumberFormatInfo.InvariantInfo); } if (atmosphereVisibility != null && !string.IsNullOrEmpty(atmosphereVisibility.Value)) { weatherPoint.Weather.Visibility = decimal.Parse(atmosphereVisibility.Value, System.Globalization.NumberFormatInfo.InvariantInfo); } if (atmosphereHumidity != null && !string.IsNullOrEmpty(atmosphereHumidity.Value)) { weatherPoint.Weather.Humidity = decimal.Parse(atmosphereHumidity.Value, System.Globalization.NumberFormatInfo.InvariantInfo); } //TODO: Sunrise, Sunset return weatherPoint; } } catch (Exception ex) { return null; } }
private static Common.Weather.WeatherPoint ConvertToWeatherPoint(WeatherPoint source) { var destination = new Common.Weather.WeatherPoint() { SunAltitude = source.SunAltitude, Timestamp = source.Timestamp.ToLocalTime(), Location = new Common.Weather.Location() }; ConvertWeatherLocation(destination.Location, source); if (source.Weather != null) { destination.Weather = new Common.Weather.WeatherPointData(); ConvertWeather(destination.Weather, source.Weather); } return destination; }
private static Common.Weather.WeatherPoint ConvertToWeatherPoint(CurrentWeatherResponse source) { var destination = new Common.Weather.WeatherPoint(); destination.Location = ConvertToLocation(source); destination.Weather = ConvertToWeatherPointData(source); if (source.Timestamp.HasValue) { destination.Timestamp = UnixToDateTime(source.Timestamp.Value); } destination.SunAltitude = null; return destination; }
private static List<Common.Weather.WeatherPoint> ConvertToWeatherPoints(HourlyWeatherResponse source) { var destination = new List<Common.Weather.WeatherPoint>(); foreach (var item in source.Weather) { var destinationItem = new Common.Weather.WeatherPoint(); if (item.Timestamp.HasValue) { destinationItem.Timestamp = UnixToDateTime(item.Timestamp.Value); } destinationItem.Weather = ConvertToWeatherPointData(item); destinationItem.SunAltitude = null; destination.Add(destinationItem); } return destination; }