/// <summary> /// Will update the Day properties. Run this when searching for a new locations weather data. /// </summary> /// <param name="woeid">The id of the location.</param> public void updateDay(XmlAccessManager xm) { xm.addNameSpace("lastBuildDate", "http://xml.weather.yahoo.com/ns/rss/1.0"); xm.addNameSpace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0"); // get the users choice of temperature (celcius/Fahrenheit) Settings settings = new Settings(); settings.readSettingsFile(); String tempChoice = settings.TempChoice; // assign the Day's attribute the relevant node content name = xm.Channel.SelectSingleNode("lastBuildDate", xm.NamespaceManager).InnerText.Substring(0, 3); date = xm.Channel.SelectSingleNode("lastBuildDate", xm.NamespaceManager).InnerText.Substring(5, 11); lastBuildDate = xm.Channel.SelectSingleNode("lastBuildDate", xm.NamespaceManager).InnerText; // the days weather attributes weather.Condition = xm.Channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", xm.NamespaceManager).Attributes["text"].Value; weather.WindChill = convertTemperature(tempChoice, xm.Channel.SelectSingleNode("yweather:wind", xm.NamespaceManager).Attributes["chill"].Value) + "\u00b0"; weather.WindDirection = xm.Channel.SelectSingleNode("yweather:wind", xm.NamespaceManager).Attributes["direction"].Value + "\u00b0"; weather.WindSpeed = xm.Channel.SelectSingleNode("yweather:wind", xm.NamespaceManager).Attributes["speed"].Value + "mph"; weather.Humidity = convertTemperature(tempChoice, xm.Channel.SelectSingleNode("yweather:atmosphere", xm.NamespaceManager).Attributes["humidity"].Value) + "\u00b0"; weather.Sunrise = xm.Channel.SelectSingleNode("yweather:astronomy", xm.NamespaceManager).Attributes["sunrise"].Value; weather.Sunset = xm.Channel.SelectSingleNode("yweather:astronomy", xm.NamespaceManager).Attributes["sunset"].Value; Weather.Temperature = convertTemperature(tempChoice, xm.Channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", xm.NamespaceManager).Attributes["temp"].Value) + "\u00b0"; // the forecast for the next 5 days is contained in the weather object weather.updateForecastList(xm); }
private void SettingsWindow_Loaded(object sender, RoutedEventArgs e) { // load settings settings.readSettingsFile(); postCode.DataContext = settings; if (settings.TempChoice.Equals("c")) { celciusRadioButton.IsChecked = true; } else { fahrenheitRadioButton.IsChecked = true; } }
/// <summary> /// Used to update the list of forecast objects containing basic weather data for the next 5 days /// </summary> /// <param name="woeid">The id of the location</param> public void updateForecastList(XmlAccessManager xm) { // update xm nodelist xm.updateXmlNodeList("yweather:forecast"); // get the users temperature choice (celcius/fahrenheit) Settings settings = new Settings(); settings.readSettingsFile(); int i = 0; // iterate through each of the nodes in the node list foreach (XmlNode forecastNode in xm.XmlNodeList) { // assign the nodes attribute data to the equivalant forecast object fields ForecastList.ElementAt(i).Day = (i == 0) ? "Today" : forecastNode.Attributes["day"].Value; ForecastList.ElementAt(i).Date = forecastNode.Attributes["date"].Value; ForecastList.ElementAt(i).HiLow = "Low: " + convertTemperature(settings.TempChoice, forecastNode.Attributes["low"].Value) + "\u00b0 / Hi: " + convertTemperature(settings.TempChoice, forecastNode.Attributes["high"].Value) + "\u00b0"; ForecastList.ElementAt(i).ForecastCondition = forecastNode.Attributes["text"].Value; i++; } }
private void Window_Loaded(object sender, RoutedEventArgs e) { // attempt to load data from .txt and .xml files try { // read settings from file set.readSettingsFile(); // load saved postcode searchCriteria.Add(set.Postcode); // get woeid using saved postcode set.updateWOEID(searchCriteria); // check if a woeid was found if (set.WOEID.Length <= 0) { // set a new valid postcode and save it to settings file set.Postcode = "ip333rl"; set.writeSettingsFile(); // use this default woeid to load program set.WOEID = "14714"; // notify user of invalid postcode displayError("Invalid saved postcode, reverted to system default location. Settings updated.\nPlease set a valid postcode in settings."); } // instantiate the Xml access object to be used for retrieving weather data xm = new XmlAccessManager(set.WOEID); // load todays info from saved postcode day = new Day(); day.updateDay(xm); // load location info from settings loc = new Location(); loc.updateLocation(xm); // load reusable forecast UI component UserControlLibrary.ForecastControl fc = new UserControlLibrary.ForecastControl(); rightStackPanel.Children.Add(fc); // set the data context for the various labels to display the correct data dayInfo.DataContext = day.Weather; lastBuildDateLabel.DataContext = day; townLabel.DataContext = loc; fc.Forecast1DC = day.Weather.ForecastList[0]; fc.Forecast2DC = day.Weather.ForecastList[1]; fc.Forecast3DC = day.Weather.ForecastList[2]; fc.Forecast4DC = day.Weather.ForecastList[3]; fc.Forecast5DC = day.Weather.ForecastList[4]; // set default location of map Microsoft.Maps.MapControl.WPF.Location l = new Microsoft.Maps.MapControl.WPF.Location(Convert.ToDouble(loc.Latitude), Convert.ToDouble(loc.Longitude)); Map.SetView(l, 11); } catch (Exception ex) { // display any errors in the error window Error errorWindow = new Error(); errorWindow.Show(); errorWindow.errorMessage.Text = ex.Message + "\n" + ex.StackTrace; } }