/// <summary> /// Gets the weather profile /// </summary> /// <returns></returns> private WeatherProfile GetWeatherProfile() { WeatherProfile _profile = new WeatherProfile(); _profile.CityName = this.CityName; _profile.isCondition = this.Condition; _profile.isConditionImage = this.ConditionImage; _profile.isHighTemperature = this.High; _profile.isHumidity = this.Humidity; _profile.isLowTemprature = this.Low; _profile.UnitTemperature = this.UnitTemperature; _profile.isUpdateInfo = this.UpdateInfo; _profile.isWind = this.Wind; return _profile; }
/// <summary> /// Gets the Weather details from Yahoo API in XML Format /// </summary> /// <param name="WOEID"></param> /// <returns></returns> private WeatherProfile GetWeatherDetails(string WOEID) { XDocument Response = null; WeatherProfile objProfile = new WeatherProfile(); string URL = string.Format("http://weather.yahooapis.com/forecastrss?w=" + WOEID + "&u=" + TempUnit); bool forecast = false; try { Response = XDocument.Load(URL); if (Response != null && Response.Root != null) { XmlDocument weatherDetails = new XmlDocument(); weatherDetails.LoadXml(Response.ToString()); foreach (XmlNode objNode in weatherDetails.ChildNodes[0].ChildNodes[0]) { if (objNode.Name.ToLower().Equals("yweather:location")) { foreach (XmlAttribute objAttribute in objNode.Attributes) { if (objAttribute.Name.ToLower().Equals("city")) { objProfile.Location = objAttribute.Value; } else if (objAttribute.Name.ToLower().Equals("region")) { objProfile.Location = objProfile.Location + ", " + objAttribute.Value; } else if (objAttribute.Name.ToLower().Equals("country")) { objProfile.Location = objProfile.Location + ", " + objAttribute.Value; } } } else if (objNode.Name.ToLower().Equals("yweather:atmosphere")) { foreach (XmlAttribute objAttribute in objNode.Attributes) { if (objAttribute.Name.ToLower().Equals("humidity")) { objProfile.Humidity = objAttribute.Value; break; } } } else if (objNode.Name.ToLower().Equals("yweather:wind")) { foreach (XmlAttribute objAttribute in objNode.Attributes) { if (objAttribute.Name.ToLower().Equals("speed")) { objProfile.Wind = objAttribute.Value; break; } } } if (objNode.Name.ToLower().Equals("item")) { foreach (XmlNode objItemNode in objNode.ChildNodes) { if (objItemNode.Name.ToLower().Equals("yweather:condition")) { foreach (XmlAttribute objAttribute in objItemNode.Attributes) { if (objAttribute.Name.ToLower().Equals("text")) { objProfile.Condition = objAttribute.Value; } else if (objAttribute.Name.ToLower().Equals("temp")) { objProfile.Temperature = objAttribute.Value; } else if (objAttribute.Name.ToLower().Equals("code")) { objProfile.ImagePath = "http://l.yimg.com/a/i/us/we/52/" + objAttribute.Value + ".gif"; } } } else if (objItemNode.Name.ToLower().Equals("pubdate")) { objProfile.PublishedDate = "Last Updated: " + objItemNode.InnerText; } else if (objItemNode.Name.ToLower().Equals("yweather:forecast")) { if (!forecast) { foreach (XmlAttribute objAttribute in objItemNode.Attributes) { if (objAttribute.Name.ToLower().Equals("low")) { objProfile.LowTemperature = objAttribute.Value; } else if (objAttribute.Name.ToLower().Equals("high")) { objProfile.HighTemperature = objAttribute.Value; } } forecast = true; } } } } } } } catch (Exception ex) { } return objProfile; }