Exemplo n.º 1
0
        public void Update(WeatherData instance, string locationCode, string unit)
        {
            if (locationCode == "")
            {
                return;
            }
            if (DateTime.Now.Subtract(_LastUpdate).TotalMinutes <= 120)
            {
                return;
            }

            XmlDocument lXml = GetXml(locationCode, unit);


            // ----- Get local time of location
            string   lLocalTimeValue = lXml.DocumentElement.SelectSingleNode("loc/tm").InnerText;
            DateTime lLocalTime;

            lLocalTime = DateTime.Parse(lLocalTimeValue, System.Globalization.CultureInfo.GetCultureInfo("en-US").DateTimeFormat);


            // ----- Get date the forecasts are based on
            string lBaseDateValue = lXml.DocumentElement.SelectSingleNode("dayf/lsup").InnerText;

            if (lBaseDateValue.IndexOf("AM") >= 0)
            {
                lBaseDateValue = lBaseDateValue.Substring(0, lBaseDateValue.IndexOf("AM") + 2);
            }
            else if (lBaseDateValue.IndexOf("PM") >= 0)
            {
                lBaseDateValue = lBaseDateValue.Substring(0, lBaseDateValue.IndexOf("PM") + 2);
            }

            DateTime lBaseDate;

            lBaseDate = DateTime.Parse(lBaseDateValue, System.Globalization.CultureInfo.GetCultureInfo("en-US").DateTimeFormat);


            // ----- Parse forecasts
            instance.ClearData();
            foreach (XmlElement lChild in lXml.DocumentElement.SelectNodes("dayf/day"))
            {
                int lIndex = int.Parse(lChild.Attributes["d"].Value);
                if (lIndex >= 0 && lIndex <= 9)
                {
                    WeatherCondition lData;
                    if (lIndex == 0)
                    {
                        // Starting with 17:00 (local time of location) the night's data is displayed
                        lData = ParseDay(lChild, (lLocalTime.Hour >= 17));
                    }
                    else
                    {
                        lData = ParseDay(lChild, false);
                    }

                    lData.Date = lBaseDate.Date.AddDays(lIndex);
                    instance.SetData(lData);
                }
            }

            _LastUpdate = DateTime.Now;
        }
Exemplo n.º 2
0
        public void Update(WeatherData instance, string locationCode, string unit)
        {
            if (locationCode == "") { return; }
              if (DateTime.Now.Subtract(_LastUpdate).TotalMinutes <= 120) { return; }

              XmlDocument lXml = GetXml(locationCode, unit);

              // ----- Get local time of location
              string lLocalTimeValue = lXml.DocumentElement.SelectSingleNode("loc/tm").InnerText;
              DateTime lLocalTime;
              lLocalTime = DateTime.Parse(lLocalTimeValue, System.Globalization.CultureInfo.GetCultureInfo("en-US").DateTimeFormat);

              // ----- Get date the forecasts are based on
              string lBaseDateValue = lXml.DocumentElement.SelectSingleNode("dayf/lsup").InnerText;
              if (lBaseDateValue.IndexOf("AM") >= 0)
              {
            lBaseDateValue = lBaseDateValue.Substring(0, lBaseDateValue.IndexOf("AM") + 2);
              }
              else if (lBaseDateValue.IndexOf("PM") >= 0)
              {
            lBaseDateValue = lBaseDateValue.Substring(0, lBaseDateValue.IndexOf("PM") + 2);
              }

              DateTime lBaseDate;
              lBaseDate = DateTime.Parse(lBaseDateValue, System.Globalization.CultureInfo.GetCultureInfo("en-US").DateTimeFormat);

              // ----- Parse forecasts
              instance.ClearData();
              foreach (XmlElement lChild in lXml.DocumentElement.SelectNodes("dayf/day"))
              {
            int lIndex = int.Parse(lChild.Attributes["d"].Value);
            if (lIndex >= 0 && lIndex <= 9)
            {
              WeatherCondition lData;
              if (lIndex == 0)
              {
            // Starting with 17:00 (local time of location) the night's data is displayed
            lData = ParseDay(lChild, (lLocalTime.Hour >= 17));
              }
              else
              {
            lData = ParseDay(lChild, false);
              }

              lData.Date = lBaseDate.Date.AddDays(lIndex);
              instance.SetData(lData);
            }
              }

              _LastUpdate = DateTime.Now;
        }