示例#1
0
        /// <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);
        }
示例#2
0
        /// <summary>
        /// <para>Will update the Day properties. Run this when searching for a new locations weather data.</para>
        /// </summary>
        /// <param name="woeid">The id of the location</param>
        public void updateLocation(XmlAccessManager xm)
        {
            xm.addNameSpace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");
            xm.addNameSpace("geo", "http://www.w3.org/2003/01/geo/wgs84_pos#");

            // assign the Locations attributes the relevant node content
            Town      = checkIfNull(xm.Channel.SelectSingleNode("yweather:location", xm.NamespaceManager).Attributes["city"].Value);
            County    = checkIfNull(xm.Channel.SelectSingleNode("yweather:location", xm.NamespaceManager).Attributes["region"].Value);
            Latitude  = checkIfNull(xm.Channel.SelectSingleNode("item").SelectSingleNode("geo:lat", xm.NamespaceManager).InnerText);
            Longitude = checkIfNull(xm.Channel.SelectSingleNode("item").SelectSingleNode("geo:long", xm.NamespaceManager).InnerText);
        }
示例#3
0
        /// <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++;
            }
        }