Example #1
0
        public WeatherData GetForecastWeatherDataNew(string locId, bool force)
        {
            bool night  = false;
            var  result = new WeatherData();

            Logger.Instance().Trace("Weather:", "GetForecastWeatherDataNew");
            Logger.Instance().Trace("Weather:", "Weather API Equals: " + _weatherAPI);
            string str = "";

            string newLocID = locId;
            string invalid  = @";/:\";

            foreach (char c in invalid)
            {
                newLocID = newLocID.Replace(c.ToString(), "");
            }
            string path  = _cacheDir + @"\" + newLocID + ".json";
            string path2 = _cacheDir + @"\" + newLocID + ".json";

            if (String.IsNullOrEmpty(locId))
            {
                Logger.Instance().Trace("Weather:", "GetForecastWeatherDataNew:  locID Null or Empty");
                return(null);
            }

            // GetWeatherDataNew(locId, false);    //loads conditions --> probably need to move this

            if (!LoadWeatherData(locId, force, true))
            {
                Logger.Instance().Trace("Weather:", "!LoadWeatherData ForecastWeatherDataNull returning null.");
                return(null);
            }
            //First check Conditions as need this to get name amongst other things.

            try
            {
                using (StreamReader client = new StreamReader(path2))
                {
                    try
                    {
                        str = client.ReadToEnd();//DataUrl + _weatherAPI + @"/conditions" + locId + ".json");
                        Logger.Instance().Trace("Weather:", "GetWeatherForecast COnditions Data: Trying DATA FILE " + path2);
                        //Logger.Instance().Trace("Weather:", "GetWeatherData: Data " + str);
                    }
                    catch (WebException ex)
                    {
                        Logger.Instance().Trace("Weather:", " Error" + ex);
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance().Trace("Weather:", " Error" + ex);
                return(null);
            }


            try
            {
                string json = str;

                if (str.Contains("keynotfound"))
                {
                    Logger.Instance().Log("Weather:", "ERORR in Weather API Key Not Found");
                    return(null);
                }


                var deserializer = new JavaScriptSerializer();
                var server       = deserializer.Deserialize <OpenWeatherAPI.Root>(json);
                result.LocationName = server.timezone.ToString();
                result.Forecast.Clear();
                var currentWeather = server.current.weather.First();

                try
                {
                    Logger.Instance().Trace("Weather**", "Getting icon url to find night or not:" + currentWeather.icon);
                    Logger.Instance().Trace("Weather**", "IS File True: icon url to find night or not:" + currentWeather.icon);
                    if (currentWeather.icon.EndsWith("n"))
                    {
                        night = true;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance().Trace("Weather*", "Exception Caught in Icon Night or Day test" + ex);
                }

                result.TempUnit = "°";
                result.Today    = new WeatherCurrentDetail
                {
                    Temperature = server.current.temp.ToString(),
                    Icon        = convertIcons(currentWeather.icon)
                };
            }
            catch (Exception ex)
            {
                Logger.Instance().Trace("Weather", " Error" + ex);
                return(null);
            }

            // Now downloading Forecast stuff...


            try
            {
                using (StreamReader client = new StreamReader(path))
                {
                    try
                    {
                        str = client.ReadToEnd();
                        Logger.Instance().Trace("Weather:", "GetForecastWeather Data Trying Data FILE: " + path);
                        //Logger.Instance().Trace("Weather:", "Result is :" + str);
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance().Trace("Weather:", "Underground Error" + ex);
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance().Trace("Weather", "Underground Error" + ex);
            }


            try
            {
                string json = str;


                if (str.Contains("keynotfound"))
                {
                    Logger.Instance().Log("Weather:", "ERORR in Weather API Key Not Found");
                    return(null);
                }

                var deserializer = new JavaScriptSerializer();
                var server       = deserializer.Deserialize <OpenWeatherAPI.Root>(json);

                result.Forecast.Clear();

                var diff = 0;

                if (server != null)
                {
                    foreach (var element in server.daily)
                    {
                        var currentdatetime = UnixTimeStampToDateTime(element.dt);
                        var daysWeather     = element.weather.First();

                        var temp = new WeatherForecastDetail
                        {
                            DayDiff   = diff,
                            DayName   = currentdatetime.DayOfWeek.ToString(),
                            DayDate   = currentdatetime.Date.ToString(),
                            DayIcon   = convertIcons(daysWeather.icon),
                            NightIcon = convertIcons(daysWeather.icon),
                            MaxTemp   = element.temp.max.ToString(),
                            LowTemp   = element.temp.min.ToString(),
                        };
                        result.Forecast.Add(temp);
                        diff++;
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                Logger.Instance().Trace("Weather", "Underground Error" + ex);
                return(null);
            }
        }
Example #2
0
/*
        public WeatherData GetForecastWeatherDataOLD(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");
                var ns = new XmlNamespaceManager(data.NameTable);
                ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");


                XmlNode node = data.SelectSingleNode("/rss/channel/yweather:units", ns);
                result.TempUnit = node.Attributes["temperature"].InnerText;

                node = data.SelectSingleNode("/rss/channel/yweather:location", ns);
                result.LocationName = node.Attributes["city"].InnerText;

                node = data.SelectSingleNode("/rss/channel/item/yweather:condition", ns);

                result.Today = new WeatherCurrentDetail
                {
                    Temperature = node.Attributes["temp"].InnerText,
                    Icon = node.Attributes["code"].InnerText
                };


                result.Forecast.Clear();

                XmlNodeList nodes = data.SelectNodes("/rss/channel/item/yweather:forecast", ns);
                var diff = 0;
                foreach (XmlNode inode in nodes)
                {

                    var temp = new WeatherForecastDetail
                    {
                        DayDiff = diff,
                        DayName = inode.Attributes["day"].InnerText,
                        DayDate = inode.Attributes["date"].InnerText,
                        DayIcon = inode.Attributes["code"].InnerText,
                        NightIcon = inode.Attributes["code"].InnerText,
                        MaxTemp = inode.Attributes["high"].InnerText,
                        LowTemp = inode.Attributes["low"].InnerText
                    };
                    result.Forecast.Add(temp);
                    diff++;
                }
                return result;
            }
            catch (XmlException) { }
            catch (XPathException) { }
            catch (IOException) { }
            catch (NullReferenceException) { }
            return null;
        }
 */
        public WeatherData GetForecastWeatherDataNew(string locId, bool force)
        {

            bool night = false;
            var result = new WeatherData();
            Logger.Instance().Trace("Weather:", "GetForecastWeatherDataNew");
            Logger.Instance().Trace("Weather:", "Weather API Equals: " + _weatherAPI);
            string str = "";

            string newLocID = locId;
            string invalid = @";/:\";
            foreach (char c in invalid)
            {
                newLocID = newLocID.Replace(c.ToString(), "");
            }
            string path = _cacheDir + @"\" + newLocID + ".forecast.json";
            string path2 = _cacheDir + @"\" + newLocID + ".json";

            if (String.IsNullOrEmpty(locId))
            {
                Logger.Instance().Trace("Weather:", "GetForecastWeatherDataNew:  locID Null or Empty");
                return null;
            }

           // GetWeatherDataNew(locId, false);    //loads conditions --> probably need to move this

            if (!LoadWeatherData(locId, force, true))
            {  
                Logger.Instance().Trace("Weather:", "!LoadWeatherData ForecastWeatherDataNull returning null.");
                return null;
            }
            //First check Conditions as need this to get name amongst other things.

            try
            {
                using (StreamReader client = new StreamReader(path2))
                {
                    try
                    {
                        str = client.ReadToEnd();//DataUrl + _weatherAPI + @"/conditions" + locId + ".json");
                        Logger.Instance().Trace("Weather:", "GetWeatherForecast COnditions Data: Trying DATA FILE " + path2);
                        //Logger.Instance().Trace("Weather:", "GetWeatherData: Data " + str);
                    }
                    catch (WebException ex)
                    {
                        Logger.Instance().Trace("Weather:", "Underground Error" + ex);
                        return null;
                    }
                }
            
            }
            catch (Exception ex)
            {
                    Logger.Instance().Trace("Weather:", "Underground Error" + ex);
                    return null;
            }


            try
            {
                    string json = str;
                    
                    if (str.Contains("keynotfound"))
                    {
                        Logger.Instance().Log("Weather:", "ERORR in Weather API Key Not Found");
                        return null;
                    }


                    var deserializer = new JavaScriptSerializer();
                    var server = deserializer.Deserialize<WeatherAPIWUndergroundConditions.Rootobject>(json);
                    result.LocationName = server.current_observation.display_location.full;
                    result.Forecast.Clear();


                    try
                    {
                        Uri uri = new Uri(server.current_observation.icon_url);
                        Logger.Instance().Trace("Weather**", "Getting icon url to find night or not:" + uri.AbsolutePath);
                        string filename = Path.GetFileName(uri.AbsolutePath);
                        Logger.Instance().Trace("Weather**", "IS File True: icon url to find night or not:" + filename);
                        if (filename.StartsWith("nt"))
                        {
                            night = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance().Trace("Weather*", "Exception Caught in Icon Night or Day test" + ex);
                    }

                    if (_unit == "c")
                    {
                        result.TempUnit = "celsius";
                        result.Today = new WeatherCurrentDetail
                            {
                                Temperature = server.current_observation.temp_c.ToString(),
                                Icon = night == true ? "nt_" + server.current_observation.icon : server.current_observation.icon
                            };
                    }

                    else if (_unit == "f")
                    {
                        result.TempUnit = @"F";
                        result.Today = new WeatherCurrentDetail
                            {
                                Temperature = server.current_observation.temp_f.ToString(),
                                Icon = night == true ? "nt_" + server.current_observation.icon : server.current_observation.icon
                            };
                    }

                }
                catch (Exception ex)
                {
                    Logger.Instance().Trace("Weather", "Underground Error" + ex);
                    return null;
                }
            
            // Now downloading Forecast stuff...


            try
            {
                using (StreamReader client = new StreamReader(path))
                {
                    try
                    {
                        str = client.ReadToEnd();
                        Logger.Instance().Trace("Weather:", "GetForecastWeather Data Trying Data FILE: " + path);
                        //Logger.Instance().Trace("Weather:", "Result is :" + str);
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance().Trace("Weather:", "Underground Error" + ex);
                        return null;
                    }
                }
            } 
            catch (Exception ex)
            {
                Logger.Instance().Trace("Weather", "Underground Error" + ex);
            }


            try
            {
                string json = str;


                if (str.Contains("keynotfound"))
                {
                    Logger.Instance().Log("Weather:", "ERORR in Weather API Key Not Found");
                    return null;
                }

                var deserializer = new JavaScriptSerializer();
                var server = deserializer.Deserialize<WeatherAPIWUnderground10day.Rootobject>(json);

                result.Forecast.Clear();

                var diff = 0;

                if (server != null)
                {
                    foreach (var element in server.forecast.simpleforecast.forecastday)
                    {

                        var temp = new WeatherForecastDetail
                        {
                            DayDiff = diff,
                            DayName = element.date.weekday,
                            DayDate = element.date.pretty,
                            DayIcon = night == true ? "nt_" + element.icon : element.icon,
                            NightIcon = "nt_"+element.icon,
                            MaxTemp = (_unit == "c") ? element.high.celsius : element.high.fahrenheit,
                            LowTemp = (_unit == "c") ? element.low.celsius : element.low.fahrenheit,

                        };
                        result.Forecast.Add(temp);
                        diff++;
                    }
                }
                return result;


            }
            catch (Exception ex)
            {
                Logger.Instance().Trace("Weather", "Underground Error" + ex);
                return null;
            }
        }
Example #3
0
        public WeatherData GetWeatherDataNew(string locId, bool force)
        {
            var result = new WeatherData();

            string newLocID = locId;
            string invalid  = @";/:\";

            foreach (char c in invalid)
            {
                newLocID = newLocID.Replace(c.ToString(), "");
            }
            string path = _cacheDir + @"\" + newLocID + ".json";

            Logger.Instance().Trace("Weather:", "GetWeatherDataNew Running..");
            Logger.Instance().Trace("Weather:", "Weather API Equals: " + _weatherAPI);
            string str = "";

            if (String.IsNullOrEmpty(locId))
            {
                Logger.Instance().Trace("Weather:", "locID Null returning Running..");
                return(null);
            }

            if (!LoadWeatherData(locId, force, false))
            {
                Logger.Instance().Trace("Weather:", "!LoadWeatherData Null returning null.");
                return(null);
            }
            try
            {
                using (StreamReader client = new StreamReader(path))
                {
                    try
                    {
                        str = client.ReadToEnd();//DataUrl + _weatherAPI + @"/conditions" + locId + ".json");
                        Logger.Instance().Trace("Weather:", "GetWeatherData: Trying DATA FILE " + path);
                        //Logger.Instance().Trace("Weather:", "GetWeatherData: Data " + str);
                    }
                    catch (WebException ex)
                    {
                        Logger.Instance().Trace("Weather:", "No Data File Exists: Exception: " + ex);
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance().Trace("Weather:", "DarkSky Error" + ex);
                return(null);
            }


            try
            {
                string json = str;

                bool night = false;

                if (str.Contains("keynotfound"))
                {
                    Logger.Instance().Log("Weather:", "ERORR in Weather API Key Not Found");
                    return(null);
                }


                var deserializer = new JavaScriptSerializer();
                var server       = deserializer.Deserialize <OpenWeatherAPI.Root>(json);

                result.LocationName = _LocationName;
                var currentWeather = server.current.weather.First();
                result.Forecast.Clear();

                try
                {
                    Logger.Instance().Trace("Weather**", "Getting icon url to find night or not:" + currentWeather.icon);
                    Logger.Instance().Trace("Weather**", "IS File True: icon url to find night or not:" + currentWeather.icon);
                    if (currentWeather.icon.EndsWith("n"))
                    {
                        night = true;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance().Trace("Weather*", "Exception Caught in Icon Night or Day test" + ex);
                }

                result.TempUnit = "°";

                result.Today = new WeatherCurrentDetail
                {
                    Temperature = server.current.temp.ToString(),
                    Icon        = convertIcons(currentWeather.icon)
                };
                return(result);
            }
            catch (Exception ex)
            {
                Logger.Instance().Trace("Weather", "DarkSky Error Caught:" + ex);
                return(null);
            }
            return(null);
        }
Example #4
0
/*
        public WeatherData GetWeatherDataOLDOLD(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");

                var ns = new XmlNamespaceManager(data.NameTable);
                ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");


                XmlNode node = data.SelectSingleNode("/rss/channel/yweather:units", ns);
                result.TempUnit = node.Attributes["temperature"].InnerText;

                node = data.SelectSingleNode("/rss/channel/yweather:location", ns);
                result.LocationName = node.Attributes["city"].InnerText;

                node = data.SelectSingleNode("/rss/channel/item/yweather:condition", ns);

                result.Today = new WeatherCurrentDetail
                {
                    Temperature = node.Attributes["temp"].InnerText,
                    Icon = node.Attributes["code"].InnerText
                };

                result.PromoLinks.Clear();

                result.Forecast.Clear();
                return result;
            }
            catch (XmlException) { }
            catch (XPathException) { }
            catch (IOException) { }
            catch (NullReferenceException) { }
            return null;
        }
        
 */
        public WeatherData GetWeatherDataNew(string locId, bool force)
        {

            var result = new WeatherData();

            string newLocID = locId;
            string invalid = @";/:\";
            foreach (char c in invalid)
            {
                newLocID = newLocID.Replace(c.ToString(), "");
            }
            string path = _cacheDir + @"\" + newLocID + ".json";

            Logger.Instance().Trace("Weather:", "GetWeatherDataNew Running..");
            Logger.Instance().Trace("Weather:", "Weather API Equals: " + _weatherAPI);
            string str = "";
            if (String.IsNullOrEmpty(locId))
            {
                Logger.Instance().Trace("Weather:", "locID Null returning Running..");
                return null;
            }

            if (!LoadWeatherData(locId, force, false))
            {
                Logger.Instance().Trace("Weather:", "!LoadWeatherData Null returning null.");
                return null;
            }
                try
                {
                    using (StreamReader client = new StreamReader(path))
                    {
                        try
                        {
                            str = client.ReadToEnd();//DataUrl + _weatherAPI + @"/conditions" + locId + ".json");
                            Logger.Instance().Trace("Weather:", "GetWeatherData: Trying DATA FILE " + path);
                            //Logger.Instance().Trace("Weather:", "GetWeatherData: Data " + str);
                        }
                        catch (WebException ex)
                        {
                            Logger.Instance().Trace("Weather:", "No Data File Found:" + ex);
                            return null;
                        }
                    }
                    /*
                    using (var client = new WebClient())
                    {
                        try
                        {
                            str = client.DownloadString(DataUrl+_weatherAPI+@"/conditions" + locId + ".json");
                            Logger.Instance().Trace("Weather:", "GetWeatherData: Trying DataURL " + DataUrl + _weatherAPI + @"/conditions" + locId + ".json");
                            Logger.Instance().Trace("Weather:", "GetWeatherData: Data " +str);
                        }
                        catch (WebException ex)
                        {
                            Logger.Instance().Trace("Weather:", "Underground Error" + ex);
                            return null;
                        }
                    }
                     */
                }
                catch (Exception ex)
                {
                    Logger.Instance().Trace("Weather:", "Underground Error" + ex);
                    return null;
                }


                try
                {
                    string json = str;
                    
                    bool night = false ;

                    if (str.Contains("keynotfound"))
                    {
                        Logger.Instance().Log("Weather:", "ERORR in Weather API Key Not Found");
                        return null;
                    }


                    var deserializer = new JavaScriptSerializer();
                    var server = deserializer.Deserialize<WeatherAPIWUndergroundConditions.Rootobject>(json);
                    result.LocationName = server.current_observation.display_location.full;
                    result.Forecast.Clear();

                    try
                    {
                        Uri uri = new Uri(server.current_observation.icon_url);
                        Logger.Instance().Trace("Weather**", "Getting icon url to find night or not:" + uri.AbsolutePath);
                        string filename = Path.GetFileName(uri.AbsolutePath);
                        Logger.Instance().Trace("Weather**", "IS File True: icon url to find night or not:" + filename);
                        if (filename.StartsWith("nt"))
                        {
                            night = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance().Trace("Weather*", "Exception Caught in Icon Night or Day test" + ex);
                    }


                    if (_unit == "c")
                    {
                        result.TempUnit = "celsius";
                        
                        result.Today = new WeatherCurrentDetail
                            {
                                Temperature = server.current_observation.temp_c.ToString(),
                                Icon = night == true ? "nt_" + server.current_observation.icon : server.current_observation.icon 
                            };
                        return result;
                    }
                    else if (_unit == "f")
                    {
                        result.TempUnit = @"F";
                        result.Today = new WeatherCurrentDetail
                            {
                                Temperature = server.current_observation.temp_f.ToString(),
                                // Tricky - use UV to figure out whether day or night, 
                                Icon = night == true ?  "nt_"+server.current_observation.icon : server.current_observation.icon 
                            };
                        return result;
                    }

                }
                catch (Exception ex)
                {
                    Logger.Instance().Trace("Weather", "Underground Error" + ex);
                    return null;
                }
                return null;



            
        }
Example #5
0
    public void LoadForecastData(WeatherData data, string skin)
    {
      if (data == null || data.Forecast.Count <= 0) return;

      Day0IconDay = Helper.SkinorDefault( Helper.SkinPath, skin,  @"\Weather\Icons\" + data.Forecast[0].DayIcon + ".png");
      Day0IconNight = Helper.SkinorDefault( Helper.SkinPath , skin , @"\Weather\Icons\" + data.Forecast[0].NightIcon + ".png");
      Day0Name =
        DateTime.Now.AddDays(data.Forecast[0].DayDiff)
                .ToString("dddd", CultureInfo.CurrentUICulture.DateTimeFormat)
                .ToUpperInvariant();
      Day0MaxTemp = data.GetTemp(data.Forecast[0].MaxTemp);
      Day0MinTemp = data.GetTemp(data.Forecast[0].LowTemp);
      if (data.Forecast.Count > 1)
      {
        Day1IconDay = Helper.SkinorDefault( Helper.SkinPath , skin , @"\Weather\Icons\" + data.Forecast[1].DayIcon + ".png");
        Day1IconNight = Helper.SkinorDefault(Helper.SkinPath, skin, @"\Weather\Icons\" + data.Forecast[1].NightIcon + ".png");
        Day1Name =
          DateTime.Now.AddDays(data.Forecast[1].DayDiff)
                  .ToString("dddd", CultureInfo.CurrentUICulture.DateTimeFormat)
                  .ToUpperInvariant();
        Day1MaxTemp = data.GetTemp(data.Forecast[1].MaxTemp);
        Day1MinTemp = data.GetTemp(data.Forecast[1].LowTemp);
      }
      if (data.Forecast.Count > 2)
      {
          Day2IconDay = Helper.SkinorDefault(Helper.SkinPath, skin, @"\Weather\Icons\" + data.Forecast[2].DayIcon + ".png");
        Day2IconNight = Helper.SkinorDefault(Helper.SkinPath, skin, @"\Weather\Icons\" + data.Forecast[2].NightIcon + ".png");
        Day2Name =
          DateTime.Now.AddDays(data.Forecast[2].DayDiff)
                  .ToString("dddd", CultureInfo.CurrentUICulture.DateTimeFormat)
                  .ToUpperInvariant();
        Day2MaxTemp = data.GetTemp(data.Forecast[2].MaxTemp);
        Day2MinTemp = data.GetTemp(data.Forecast[2].LowTemp);
      }
      if (data.Forecast.Count > 3)
      {
          Day3IconDay = Helper.SkinorDefault(Helper.SkinPath, skin, @"\Weather\Icons\" + data.Forecast[3].DayIcon + ".png");
        Day3IconNight = Helper.SkinorDefault(Helper.SkinPath, skin, @"\Weather\Icons\" + data.Forecast[3].NightIcon + ".png");
        Day3Name =
          DateTime.Now.AddDays(data.Forecast[3].DayDiff)
                  .ToString("dddd", CultureInfo.CurrentUICulture.DateTimeFormat)
                  .ToUpperInvariant();
        Day3MaxTemp = data.GetTemp(data.Forecast[3].MaxTemp);
        Day3MinTemp = data.GetTemp(data.Forecast[3].LowTemp);
      }
      if (data.Forecast.Count > 4)
      {
          Day4IconDay = Helper.SkinorDefault(Helper.SkinPath, skin, @"\Weather\Icons\" + data.Forecast[4].DayIcon + ".png");
        Day4IconNight = Helper.SkinorDefault(Helper.SkinPath, skin, @"\Weather\Icons\" + data.Forecast[4].NightIcon + ".png");
        Day4Name =
          DateTime.Now.AddDays(data.Forecast[4].DayDiff)
                  .ToString("dddd", CultureInfo.CurrentUICulture.DateTimeFormat)
                  .ToUpperInvariant();
        Day4MaxTemp = data.GetTemp(data.Forecast[4].MaxTemp);
        Day4MinTemp = data.GetTemp(data.Forecast[4].LowTemp);
      }
    }
Example #6
0
    public void LoadCurrentData(WeatherData data, string skin)
    {
      if (data == null) return;
      Location = data.LocationName;
      CurrentIcon = Helper.SkinorDefault(Helper.SkinPath, skin,  @"\Weather\Icons\" + data.Today.Icon + ".png");
      

      CurrentBackground = Helper.SkinorDefault(Helper.SkinPath, skin, @"\Weather\Backgrounds\" + data.Today.Icon + ".jpg");
      
      CurrentTemp = data.GetTemp(data.Today.Temperature);
    }
Example #7
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");
                var ns = new XmlNamespaceManager(data.NameTable);
                ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");


                XmlNode node = data.SelectSingleNode("/rss/channel/yweather:units", ns);
                result.TempUnit = node.Attributes["temperature"].InnerText;

                node = data.SelectSingleNode("/rss/channel/yweather:location", ns);
                result.LocationName = node.Attributes["city"].InnerText;

                node = data.SelectSingleNode("/rss/channel/item/yweather:condition", ns);

                result.Today = new WeatherCurrentDetail
                {
                    Temperature = node.Attributes["temp"].InnerText,
                    Icon = node.Attributes["code"].InnerText
                };


                result.Forecast.Clear();

                XmlNodeList nodes = data.SelectNodes("/rss/channel/item/yweather:forecast", ns);
                var diff = 0;
                foreach (XmlNode inode in nodes)
                {

                    var temp = new WeatherForecastDetail
                    {
                        DayDiff = diff,
                        DayName = inode.Attributes["day"].InnerText,
                        DayDate = inode.Attributes["date"].InnerText,
                        DayIcon = inode.Attributes["code"].InnerText,
                        NightIcon = inode.Attributes["code"].InnerText,
                        MaxTemp = inode.Attributes["high"].InnerText,
                        LowTemp = inode.Attributes["low"].InnerText
                    };
                    result.Forecast.Add(temp);
                    diff++;
                }
                return result;
            }
            catch (XmlException) { }
            catch (XPathException) { }
            catch (IOException) { }
            catch (NullReferenceException) { }
            return null;
        }
Example #8
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");

                var ns = new XmlNamespaceManager(data.NameTable);
                ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");


                XmlNode node = data.SelectSingleNode("/rss/channel/yweather:units", ns);
                result.TempUnit = node.Attributes["temperature"].InnerText;

                node = data.SelectSingleNode("/rss/channel/yweather:location", ns);
                result.LocationName = node.Attributes["city"].InnerText;

                node = data.SelectSingleNode("/rss/channel/item/yweather:condition", ns);

                result.Today = new WeatherCurrentDetail
                {
                    Temperature = node.Attributes["temp"].InnerText,
                    Icon = node.Attributes["code"].InnerText
                };

                result.PromoLinks.Clear();

                result.Forecast.Clear();
                return result;
            }
            catch (XmlException) { }
            catch (XPathException) { }
            catch (IOException) { }
            catch (NullReferenceException) { }
            return null;
        }