예제 #1
0
 private void SetWeatherProperties(WeatherElement weather)
 {
     txbDay.Text = _currentPagerIndex == 0 ? "Today" : weather.Day;
     txbTempHight.Text = string.Format("{0}°F", weather.High);
     txbTempLow.Text = string.Format("{0}°F", weather.Low);
     txbCondition.Text = weather.Condition;
     imgWeather.Source = weather.Icon;// new BitmapImage(new Uri(string.Format(@"D:\Saraf's Project\MTouch\Docs\Concierge mockup\weather\icon{0}.png", (_currentPagerIndex + 2)), UriKind.Absolute));
 }
예제 #2
0
        public static List<WeatherElement> GetData(string location)
        {
            List<WeatherElement> elements = new List<WeatherElement>();

            if (!string.IsNullOrEmpty(location))
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/ig/api?weather=" + location);

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                XDocument doc = XDocument.Load(response.GetResponseStream());
                if (doc.Root.Element("problem_cause") == null)
                {
                    var x = from c in doc.Root.Element("weather").Elements() where c.Name == "forecast_conditions" select c;

                    foreach (XElement element in x)
                    {
                        //image = null;
                        WeatherElement welement = new WeatherElement();
                        welement.Condition = element.Element("condition").Attribute("data").Value;
                        welement.Day = element.Element("day_of_week").Attribute("data").Value;
                        welement.High = element.Element("high").Attribute("data").Value;
                        welement.Low = element.Element("low").Attribute("data").Value;
                        WeatherElement temp = elements.FirstOrDefault(e => e.Condition.Equals(welement.Condition));
                        if (temp != null)
                        {
                            welement.Icon = temp.Icon;
                        }
                        else
                        {
                            welement.Icon = new BitmapImage(new Uri("http://www.google.com/" + element.Element("icon").Attribute("data").Value));
                        }
                        elements.Add(welement);

                    }
                }
            }
            return elements;
        }