public void LoadForecastData(WeatherData data, string skin) { if (data == null || data.Forecast.Count <= 0) return; Day0IconDay = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Forecast[0].DayIcon + ".png"; Day0IconNight = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Forecast[0].NightIcon + ".png"; Day0Name = DateTime.Now.AddDays(data.Forecast[0].DayDiff) .ToString("dddd", CultureInfo.CurrentUICulture.DateTimeFormat) .ToUpperInvariant(); Day0MaxTemp = data.GetTemp(data.Forecast[0].MaxTemp); Day0MinTemp = data.GetTemp(data.Forecast[0].LowTemp); if (data.Forecast.Count > 1) { Day1IconDay = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Forecast[1].DayIcon + ".png"; Day1IconNight = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Forecast[1].NightIcon + ".png"; Day1Name = DateTime.Now.AddDays(data.Forecast[1].DayDiff) .ToString("dddd", CultureInfo.CurrentUICulture.DateTimeFormat) .ToUpperInvariant(); Day1MaxTemp = data.GetTemp(data.Forecast[1].MaxTemp); Day1MinTemp = data.GetTemp(data.Forecast[1].LowTemp); } if (data.Forecast.Count > 2) { Day2IconDay = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Forecast[2].DayIcon + ".png"; Day2IconNight = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Forecast[2].NightIcon + ".png"; Day2Name = DateTime.Now.AddDays(data.Forecast[2].DayDiff) .ToString("dddd", CultureInfo.CurrentUICulture.DateTimeFormat) .ToUpperInvariant(); Day2MaxTemp = data.GetTemp(data.Forecast[2].MaxTemp); Day2MinTemp = data.GetTemp(data.Forecast[2].LowTemp); } if (data.Forecast.Count > 3) { Day3IconDay = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Forecast[3].DayIcon + ".png"; Day3IconNight = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Forecast[3].NightIcon + ".png"; Day3Name = DateTime.Now.AddDays(data.Forecast[3].DayDiff) .ToString("dddd", CultureInfo.CurrentUICulture.DateTimeFormat) .ToUpperInvariant(); Day3MaxTemp = data.GetTemp(data.Forecast[3].MaxTemp); Day3MinTemp = data.GetTemp(data.Forecast[3].LowTemp); } if (data.Forecast.Count > 4) { Day4IconDay = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Forecast[4].DayIcon + ".png"; Day4IconNight = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Forecast[4].NightIcon + ".png"; Day4Name = DateTime.Now.AddDays(data.Forecast[4].DayDiff) .ToString("dddd", CultureInfo.CurrentUICulture.DateTimeFormat) .ToUpperInvariant(); Day4MaxTemp = data.GetTemp(data.Forecast[4].MaxTemp); Day4MinTemp = data.GetTemp(data.Forecast[4].LowTemp); } }
public void LoadCurrentData(WeatherData data, string skin) { if (data == null) return; Location = data.LocationName; CurrentIcon = Helper.SkinPath + skin + @"\Weather\Icons\" + data.Today.Icon + ".png"; CurrentBackground = Helper.SkinPath + skin + @"\Weather\Backgrounds\" + data.Today.Icon + ".jpg"; CurrentTemp = data.GetTemp(data.Today.Temperature); }
public WeatherData GetWeatherData(string locId, bool force) { var result = new WeatherData(); if (String.IsNullOrEmpty(locId)) return null; try { if (!LoadWeatherData(locId,force,false)) return null; var data = new XmlDocument(); data.Load(_cacheDir + "/" + locId + ".xml"); var ns = new XmlNamespaceManager(data.NameTable); ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0"); XmlNode node = data.SelectSingleNode("/rss/channel/yweather:units", ns); result.TempUnit = node.Attributes["temperature"].InnerText; node = data.SelectSingleNode("/rss/channel/yweather:location", ns); result.LocationName = node.Attributes["city"].InnerText; node = data.SelectSingleNode("/rss/channel/item/yweather:condition", ns); result.Today = new WeatherCurrentDetail { Temperature = node.Attributes["temp"].InnerText, Icon = node.Attributes["code"].InnerText }; result.PromoLinks.Clear(); result.Forecast.Clear(); return result; } catch (XmlException) { } catch (XPathException) { } catch (IOException) { } catch (NullReferenceException) { } return null; }
public WeatherData GetForecastWeatherData(string locId, bool force) { var result = new WeatherData(); if (String.IsNullOrEmpty(locId)) { return(null); } try { if (!LoadWeatherData(locId, force, true)) { return(null); } var data = new XmlDocument(); data.Load(_cacheDir + "/" + locId + ".forecast.xml"); var ns = new XmlNamespaceManager(data.NameTable); ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0"); XmlNode node = data.SelectSingleNode("/rss/channel/yweather:units", ns); result.TempUnit = node.Attributes["temperature"].InnerText; node = data.SelectSingleNode("/rss/channel/yweather:location", ns); result.LocationName = node.Attributes["city"].InnerText; node = data.SelectSingleNode("/rss/channel/item/yweather:condition", ns); result.Today = new WeatherCurrentDetail { Temperature = node.Attributes["temp"].InnerText, Icon = node.Attributes["code"].InnerText }; result.Forecast.Clear(); XmlNodeList nodes = data.SelectNodes("/rss/channel/item/yweather:forecast", ns); var diff = 0; foreach (XmlNode inode in nodes) { var temp = new WeatherForecastDetail { DayDiff = diff, DayName = inode.Attributes["day"].InnerText, DayDate = inode.Attributes["date"].InnerText, DayIcon = inode.Attributes["code"].InnerText, NightIcon = inode.Attributes["code"].InnerText, MaxTemp = inode.Attributes["high"].InnerText, LowTemp = inode.Attributes["low"].InnerText }; result.Forecast.Add(temp); diff++; } return(result); } catch (XmlException) { } catch (XPathException) { } catch (IOException) { } catch (NullReferenceException) { } return(null); }
public WeatherData GetForecastWeatherData(string locId, bool force) { var result = new WeatherData(); if (String.IsNullOrEmpty(locId)) return null; try { if (!LoadWeatherData(locId, force, true)) return null; var data = new XmlDocument(); data.Load(_cacheDir + "/" + locId + ".forecast.xml"); var ns = new XmlNamespaceManager(data.NameTable); ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0"); XmlNode node = data.SelectSingleNode("/rss/channel/yweather:units", ns); result.TempUnit = node.Attributes["temperature"].InnerText; node = data.SelectSingleNode("/rss/channel/yweather:location", ns); result.LocationName = node.Attributes["city"].InnerText; node = data.SelectSingleNode("/rss/channel/item/yweather:condition", ns); result.Today = new WeatherCurrentDetail { Temperature = node.Attributes["temp"].InnerText, Icon = node.Attributes["code"].InnerText }; result.Forecast.Clear(); XmlNodeList nodes = data.SelectNodes("/rss/channel/item/yweather:forecast", ns); var diff = 0; foreach (XmlNode inode in nodes) { var temp = new WeatherForecastDetail { DayDiff = diff, DayName = inode.Attributes["day"].InnerText, DayDate = inode.Attributes["date"].InnerText, DayIcon = inode.Attributes["code"].InnerText, NightIcon = inode.Attributes["code"].InnerText, MaxTemp = inode.Attributes["high"].InnerText, LowTemp = inode.Attributes["low"].InnerText }; result.Forecast.Add(temp); diff++; } return result; } catch (XmlException) { } catch (XPathException) { } catch (IOException) { } catch (NullReferenceException) { } return null; }