Exemplo n.º 1
0
        void FetchLatLong()
        {
            XmlDocument xml      = FetchXml("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" + WeatherController.EncodedCurrentLocation);
            XmlNodeList nodelist = xml.SelectNodes("current_observation/display_location");
            XmlNode     item     = nodelist.Item(0);
            double      dbl;

            Double.TryParse(item.SelectSingleNode("latitude").InnerText, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out dbl);
            Latitude = dbl;
            Double.TryParse(item.SelectSingleNode("longitude").InnerText, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out dbl);
            Longitude = dbl;
            SunRise   = WeatherController.Sunrise(Latitude, Longitude);
            SunSet    = WeatherController.Sunset(Latitude, Longitude);
        }
Exemplo n.º 2
0
        protected override void ParseXml(XmlDocument xml)
        {
            XmlNodeList nodelist;

            if (WeatherController.EncodedCurrentLocation.StartsWith("PWS."))
            {
                nodelist = xml.SelectNodes("current_observation/location");
            }
            else
            {
                nodelist = xml.SelectNodes("current_observation/display_location");
            }

            XmlNode item = nodelist.Item(0);

            City = item.SelectSingleNode("city").InnerText;
            double dbl;

            Double.TryParse(item.SelectSingleNode("latitude").InnerText, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out dbl);
            Latitude = dbl;
            Double.TryParse(item.SelectSingleNode("longitude").InnerText, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out dbl);
            Longitude = dbl;
            SunRise   = WeatherController.Sunrise(Latitude, Longitude);
            SunSet    = WeatherController.Sunset(Latitude, Longitude);

            nodelist = xml.SelectNodes("current_observation");
            item     = nodelist.Item(0);

            int temp;

            if (WeatherController.EncodedCurrentLocation.StartsWith("PWS."))
            {
                double tmp;
                Double.TryParse(item.SelectSingleNode("temp_f").InnerText, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out tmp);
                Temp      = (int)tmp;
                FeelsLike = (int)tmp;
            }
            else
            {
                Int32.TryParse(item.SelectSingleNode("temp_f").InnerText, out temp);
                Temp      = temp;
                FeelsLike = temp;
            }

            if (!item.SelectSingleNode("heat_index_f").InnerText.Equals("NA") && item.SelectSingleNode("heat_index_f").InnerText.Length > 0)
            {
                Int32.TryParse(item.SelectSingleNode("heat_index_f").InnerText, out temp);
                FeelsLike = temp;
            }
            else if (!item.SelectSingleNode("windchill_f").InnerText.Equals("NA") && item.SelectSingleNode("windchill_f").InnerText.Length > 0)
            {
                Int32.TryParse(item.SelectSingleNode("windchill_f").InnerText, out temp);
                FeelsLike = temp;
            }

            Int32.TryParse(item.SelectSingleNode("wind_mph").InnerText, out temp);
            Wind          = temp;
            WindDirection = item.SelectSingleNode("wind_dir").InnerText;

            Humidity = item.SelectSingleNode("relative_humidity").InnerText;

            if (WeatherController.EncodedCurrentLocation.StartsWith("PWS."))
            {
                string lat = Latitude.ToString(CultureInfo.GetCultureInfo("en-US"));
                string lon = Longitude.ToString(CultureInfo.GetCultureInfo("en-US"));
                xml      = FetchXml("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" + lat + "," + lon);
                nodelist = xml.SelectNodes("current_observation");
                item     = nodelist.Item(0);
            }

            Condition = item.SelectSingleNode("weather").InnerText;

            Image = GetImage(item.SelectSingleNode("icon").InnerText, true);
        }