コード例 #1
0
        private void SetWeatherValues()
        {
            try
            {
                //reads temperature values (current, high, low)
                XmlNode temp_node   = WeatherData.SelectSingleNode("current/temperature");
                double  TempCurrent = double.Parse(temp_node.Attributes["value"].Value);
                double  TempHigh    = double.Parse(temp_node.Attributes["max"].Value);
                double  TempLow     = double.Parse(temp_node.Attributes["min"].Value);

                //reads wind speed
                XmlNode windspeed_node = WeatherData.SelectSingleNode("current/wind/speed");
                double  WindSpeed      = double.Parse(windspeed_node.Attributes["value"].Value);

                //reads wind direction
                XmlNode winddir_node  = WeatherData.SelectSingleNode("current/wind/direction");
                string  WindDirection = winddir_node.Attributes["code"].Value;

                //reads cloud cover value
                XmlNode clouds_node = WeatherData.SelectSingleNode("current/clouds");
                int     CloudCover  = int.Parse(clouds_node.Attributes["value"].Value);

                //reads current precipitation
                XmlNode rain_node = WeatherData.SelectSingleNode("current/precipitation");
                double  Rainfall  = 0;
                if (!rain_node.Attributes["mode"].Value.Equals("no"))
                {
                    Rainfall = double.Parse(rain_node.Attributes["value"].Value);
                    //Console.WriteLine(Rainfall);
                }

                // reads the weather description
                XmlNode weather_node       = WeatherData.SelectSingleNode("current/weather");
                string  WeatherDescription = weather_node.Attributes["value"].Value;
                Console.WriteLine(WeatherDescription);

                ReadValues = new WeatherValues(TempCurrent,
                                               TempHigh,
                                               TempLow,
                                               WindSpeed,
                                               WindDirection,
                                               CloudCover,
                                               Rainfall,
                                               WeatherDescription);
            }
            catch (Exception)
            {
                Console.WriteLine("Unable to read XML data.");
                ReadValues = BlankValues;
            }
        }
コード例 #2
0
 public void GetWeatherData()
 {
     try
     {
         WeatherData.Load(CurrentURL);
         SetWeatherValues();
     }
     catch (WebException ex)
     {
         Console.WriteLine(ex);
         ReadValues = BlankValues;
     }
     catch (Exception)
     {
         Console.WriteLine("Unknown error when getting weather data.");
         ReadValues = BlankValues;
     }
 }
コード例 #3
0
 public FetchWeather()
 {
     CurrentURL  = ForecastURL;
     WeatherData = new XmlDocument();
     ReadValues  = BlankValues;
 }