예제 #1
0
        public WeatherData GetWeatherData(string locId, bool force)
        {
            var result = new WeatherData();

            if (String.IsNullOrEmpty(locId))
            {
                return(null);
            }
            try
            {
                if (!LoadWeatherData(locId, force, false))
                {
                    return(null);
                }
                var data = new XmlDocument();
                data.Load(_cacheDir + "/" + locId + ".xml");
                result.TempUnit     = data.SelectSingleNode("//weather/head/ut").InnerText;
                result.LocationName = data.SelectSingleNode("//weather/loc/dnam").InnerText;
                result.Today        = new WeatherCurrentDetail
                {
                    Temperature = data.SelectSingleNode("//weather/cc/tmp").InnerText,
                    Icon        = data.SelectSingleNode("//weather/cc/icon").InnerText
                };

                result.PromoLinks.Clear();
                var elements = data.SelectNodes("//weather/lnks/link");
                if (elements != null)
                {
                    foreach (XmlElement element in elements)
                    {
                        var temp = new WeatherLink
                        {
                            Url  = new Uri(element.SelectSingleNode("l").InnerText),
                            Name = element.SelectSingleNode("t").InnerText
                        };
                        result.PromoLinks.Add(temp);
                    }
                }


                result.Forecast.Clear();
                return(result);
            }
            catch (XmlException) { }
            catch (XPathException) { }
            catch (IOException) { }
            catch (NullReferenceException) { }
            return(null);
        }
예제 #2
0
        public WeatherData GetForecastWeatherData(string locId, bool force)
        {
            var result = new WeatherData();
            if (String.IsNullOrEmpty(locId))
                return null;
            try
            {
                if (!LoadWeatherData(locId, force, true))
                    return null;
                var data = new XmlDocument();
                data.Load(_cacheDir + "/" + locId + ".forecast.xml");
                result.TempUnit = data.SelectSingleNode("//weather/head/ut").InnerText;
                result.LocationName = data.SelectSingleNode("//weather/loc/dnam").InnerText;
                result.Today = new WeatherCurrentDetail
                {
                    Temperature = data.SelectSingleNode("//weather/cc/tmp").InnerText,
                    Icon = data.SelectSingleNode("//weather/cc/icon").InnerText
                };

                result.PromoLinks.Clear();
                var elements = data.SelectNodes("//weather/lnks/link");
                if (elements != null)
                    foreach (XmlElement element in elements)
                    {
                        var temp = new WeatherLink
                        {
                            Url = new Uri(element.SelectSingleNode("l").InnerText),
                            Name = element.SelectSingleNode("t").InnerText
                        };
                        result.PromoLinks.Add(temp);
                    }

                result.Forecast.Clear();
                elements = data.SelectNodes("//weather/dayf/day");
                if (elements != null)
                    foreach (XmlElement element in elements)
                    {
                        var temp = new WeatherForecastDetail
                        {
                            DayDiff = Convert.ToInt32("0" + element.GetAttribute("d"),CultureInfo.InvariantCulture),
                            DayName = element.GetAttribute("t"),
                            DayDate = element.GetAttribute("dt"),
                            DayIcon = element.SelectSingleNode("part[@p='d']").SelectSingleNode("icon").InnerText,
                            NightIcon = element.SelectSingleNode("part[@p='n']").SelectSingleNode("icon").InnerText,
                            MaxTemp = element.SelectSingleNode("hi").InnerText,
                            LowTemp = element.SelectSingleNode("low").InnerText
                        };
                        result.Forecast.Add(temp);
                    }
                return result;
            }
            catch (XmlException) { }
            catch (XPathException) { }
            catch (IOException) { }
            catch (NullReferenceException) { }
            return null;
        }
예제 #3
0
        public WeatherData GetWeatherData(string locId, bool force)
        {
            var result = new WeatherData();
            if (String.IsNullOrEmpty(locId))
                return null;
            try
            {
                if (!LoadWeatherData(locId,force,false))
                    return null;
                var data = new XmlDocument();
                data.Load(_cacheDir + "/" + locId + ".xml");
                result.TempUnit = data.SelectSingleNode("//weather/head/ut").InnerText;
                result.LocationName = data.SelectSingleNode("//weather/loc/dnam").InnerText;
                result.Today = new WeatherCurrentDetail
                {
                    Temperature = data.SelectSingleNode("//weather/cc/tmp").InnerText,
                    Icon = data.SelectSingleNode("//weather/cc/icon").InnerText
                };

                result.PromoLinks.Clear();
                var elements = data.SelectNodes("//weather/lnks/link");
                if (elements != null)
                    foreach (XmlElement element in elements)
                    {
                        var temp = new WeatherLink
                                        {
                                            Url = new Uri(element.SelectSingleNode("l").InnerText),
                                            Name = element.SelectSingleNode("t").InnerText
                                        };
                        result.PromoLinks.Add(temp);
                    }
                

                result.Forecast.Clear();
                return result;
            }
            catch (XmlException) { }
            catch (XPathException) { }
            catch (IOException) { }
            catch (NullReferenceException) { }
            return null;
        }
예제 #4
0
        public WeatherData GetForecastWeatherData(string locId, bool force)
        {
            var result = new WeatherData();

            if (String.IsNullOrEmpty(locId))
            {
                return(null);
            }
            try
            {
                if (!LoadWeatherData(locId, force, true))
                {
                    return(null);
                }
                var data = new XmlDocument();
                data.Load(_cacheDir + "/" + locId + ".forecast.xml");
                result.TempUnit     = data.SelectSingleNode("//weather/head/ut").InnerText;
                result.LocationName = data.SelectSingleNode("//weather/loc/dnam").InnerText;
                result.Today        = new WeatherCurrentDetail
                {
                    Temperature = data.SelectSingleNode("//weather/cc/tmp").InnerText,
                    Icon        = data.SelectSingleNode("//weather/cc/icon").InnerText
                };

                result.PromoLinks.Clear();
                var elements = data.SelectNodes("//weather/lnks/link");
                if (elements != null)
                {
                    foreach (XmlElement element in elements)
                    {
                        var temp = new WeatherLink
                        {
                            Url  = new Uri(element.SelectSingleNode("l").InnerText),
                            Name = element.SelectSingleNode("t").InnerText
                        };
                        result.PromoLinks.Add(temp);
                    }
                }

                result.Forecast.Clear();
                elements = data.SelectNodes("//weather/dayf/day");
                if (elements != null)
                {
                    foreach (XmlElement element in elements)
                    {
                        var temp = new WeatherForecastDetail
                        {
                            DayDiff   = Convert.ToInt32("0" + element.GetAttribute("d"), CultureInfo.InvariantCulture),
                            DayName   = element.GetAttribute("t"),
                            DayDate   = element.GetAttribute("dt"),
                            DayIcon   = element.SelectSingleNode("part[@p='d']").SelectSingleNode("icon").InnerText,
                            NightIcon = element.SelectSingleNode("part[@p='n']").SelectSingleNode("icon").InnerText,
                            MaxTemp   = element.SelectSingleNode("hi").InnerText,
                            LowTemp   = element.SelectSingleNode("low").InnerText
                        };
                        result.Forecast.Add(temp);
                    }
                }
                return(result);
            }
            catch (XmlException) { }
            catch (XPathException) { }
            catch (IOException) { }
            catch (NullReferenceException) { }
            return(null);
        }