Exemplo n.º 1
0
        public Conditions GetConditions()
        {
            var doc = XDocument.Load(uri.AbsoluteUri);
            doc.Save("results.xml");

            const string WEATHER = "{http://xml.weather.yahoo.com/ns/rss/1.0}";
            const string GEO = "{http://www.w3.org/2003/01/geo/wgs84_pos#}";
            const string ATMOSPHERE = "{0}atmosphere";
            const string CONDITION = "{0}condition";
            const string LATITUDE = "{0}lat";
            const string LONGITUDE = "{0}long";
            var atmosphere = doc.Descendants(string.Format(ATMOSPHERE, WEATHER)).FirstOrDefault();

            var hAttribute = atmosphere.Attribute("humidity");
            var pAttribute = atmosphere.Attribute("pressure");

            if (hAttribute == null || pAttribute == null)
            {
                return Conditions.Empty;
            }

            var h = double.Parse(hAttribute.Value);
            var p = double.Parse(pAttribute.Value);

            XElement condition = doc.Descendants(string.Format(CONDITION, WEATHER)).FirstOrDefault();

            var tAttribute = condition.Attribute("temp");
            if (tAttribute == null)
            {
                return Conditions.Empty;
            }

            var t = double.Parse(tAttribute.Value);

            XElement latitude = doc.Descendants(string.Format(LATITUDE, GEO)).FirstOrDefault();
            XElement longitude = doc.Descendants(string.Format(LONGITUDE, GEO)).FirstOrDefault();

            var lat = new Latitude(double.Parse(latitude.Value));
            var lon = new Longitude(double.Parse(longitude.Value));

            var a = new Atmosphere(t, h, p);
            var l = new Location(lat, lon);

            return new Conditions(a, l);
        }
Exemplo n.º 2
0
 public Location(Latitude latitude, Longitude longitude)
 {
     Longitude = longitude.Value;
     Latitude = latitude.Value;
 }