Beispiel #1
0
 /// <summary>
 /// Gets data for specified date.
 /// </summary>
 /// <param name="date">Date to get condition for.</param>
 /// <returns>Weather condition or if data not available an n/a condition is returned.</returns>
 public WeatherCondition GetData(DateTime date)
 {
     if (_Forecast.ContainsKey(date.Date))
     {
         return(_Forecast[date.Date]);
     }
     else
     {
         return(WeatherCondition.CreateNotAvailable(date.Date));
     }
 }
Beispiel #2
0
        /// <summary>
        /// Creates an n/a instance.
        /// </summary>
        /// <param name="date">Date to set.</param>
        /// <returns>Instance with values set to n/a.</returns>
        public static WeatherCondition CreateNotAvailable(DateTime date)
        {
            WeatherCondition lResult = new WeatherCondition();

            lResult._ConditionIcon   = int.MinValue;
            lResult._ConditionText   = "";
            lResult._Date            = date;
            lResult._TemperatureHigh = int.MaxValue;
            lResult._TemperatureLow  = int.MinValue;

            return(lResult);
        }
Beispiel #3
0
        /// <summary>
        /// Returns configuration string from the passed instance.
        /// </summary>
        /// <param name="instance">Instance to get configuration string for.</param>
        /// <returns>Configuration string.</returns>
        public static string WriteToConfig(WeatherCondition instance)
        {
            string lResult = string.Join(";", new string[] {
                instance._Date.ToString("yyyyMMdd"),
                instance._TemperatureHigh.ToString(),
                instance._TemperatureLow.ToString(),
                instance._ConditionIcon.ToString(),
                instance.ConditionText
            });

            return(lResult);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new instance and sets the values from the passed config.
        /// </summary>
        /// <param name="config">Configuration string.</param>
        /// <returns>A new instance.</returns>
        public static WeatherCondition ReadFromConfig(string config)
        {
            string[] lValues = config.Split(';');

            WeatherCondition lResult = new WeatherCondition();

            lResult._Date            = DateTime.Parse("yyyyMMdd");
            lResult._TemperatureHigh = int.Parse(lValues[1]);
            lResult._TemperatureLow  = int.Parse(lValues[2]);
            lResult._ConditionIcon   = int.Parse(lValues[3]);
            lResult._ConditionText   = lValues[4];

            return(lResult);
        }
        private void ParseDay_Part(XmlElement node, WeatherCondition data)
        {
            foreach (XmlElement lChild in node.ChildNodes)
            {
                switch (lChild.Name)
                {
                case "icon":
                    data.ConditionIcon = int.Parse(lChild.InnerText);
                    break;

                case "t":
                    data.ConditionText = lChild.InnerText;
                    break;
                }
            }
        }
        private WeatherCondition ParseDay(XmlElement node, bool parseNight)
        {
            WeatherCondition lResult = new WeatherCondition();

            lResult.IsNight = parseNight;

            foreach (XmlElement lChild in node.ChildNodes)
            {
                switch (lChild.Name)
                {
                case "hi":
                    if (lChild.InnerText != "N/A")
                    {
                        lResult.TemperatureHigh = int.Parse(lChild.InnerText);
                    }
                    else
                    {
                        lResult.TemperatureHigh = int.MaxValue;
                    }
                    break;

                case "low":
                    if (lChild.InnerText != "N/A")
                    {
                        lResult.TemperatureLow = int.Parse(lChild.InnerText);
                    }
                    else
                    {
                        lResult.TemperatureLow = int.MinValue;
                    }
                    break;

                case "part":
                    if (lChild.Attributes["p"].Value == "d" && !parseNight)
                    {
                        ParseDay_Part(lChild, lResult);
                    }
                    else if (lChild.Attributes["p"].Value == "n" && parseNight)
                    {
                        ParseDay_Part(lChild, lResult);
                    }
                    break;
                }
            }

            return(lResult);
        }
 /// <summary>
 /// Returns configuration string from the passed instance.
 /// </summary>
 /// <param name="instance">Instance to get configuration string for.</param>
 /// <returns>Configuration string.</returns>
 public static string WriteToConfig(WeatherCondition instance)
 {
     string lResult = string.Join(";", new string[]{
     instance._Date.ToString("yyyyMMdd"),
     instance._TemperatureHigh.ToString(),
     instance._TemperatureLow.ToString(),
     instance._ConditionIcon.ToString(),
     instance.ConditionText});
       return lResult;
 }
        /// <summary>
        /// Creates a new instance and sets the values from the passed config.
        /// </summary>
        /// <param name="config">Configuration string.</param>
        /// <returns>A new instance.</returns>
        public static WeatherCondition ReadFromConfig(string config)
        {
            string[] lValues = config.Split(';');

              WeatherCondition lResult = new WeatherCondition();
              lResult._Date = DateTime.Parse("yyyyMMdd");
              lResult._TemperatureHigh = int.Parse(lValues[1]);
              lResult._TemperatureLow = int.Parse(lValues[2]);
              lResult._ConditionIcon = int.Parse(lValues[3]);
              lResult._ConditionText = lValues[4];

              return lResult;
        }
        /// <summary>
        /// Creates an n/a instance.
        /// </summary>
        /// <param name="date">Date to set.</param>
        /// <returns>Instance with values set to n/a.</returns>
        public static WeatherCondition CreateNotAvailable(DateTime date)
        {
            WeatherCondition lResult = new WeatherCondition();

              lResult._ConditionIcon = int.MinValue;
              lResult._ConditionText = "";
              lResult._Date = date;
              lResult._TemperatureHigh = int.MaxValue;
              lResult._TemperatureLow = int.MinValue;

              return lResult;
        }
Beispiel #10
0
        private void Repaint_Period()
        {
            DateTime lDate = DateTime.Now.Date;
              WeatherCondition[] lConditions = new WeatherCondition[3];

              // ----- Get conditions
              for (int i = 0; i <= 2; i++)
              {
            lConditions[i] = _Data.GetData(_CurrentDisplayDate.AddDays(i));
              }

              // ----- Update image
              lock (_Graphic)
              {
            _Graphic.FillRectangle(Brushes.Black, 0, 0, 96, 96);

            // Title
            int lTitleX = (96 - _Graphic.MeasureString(_CurrentDisplayTitle, _TitleFont).ToSize().Width) / 2;
            _Graphic.DrawString(_CurrentDisplayTitle, _TitleFont, Brushes.CadetBlue, lTitleX, 0);

            // Conditions
            for (int i = 0; i <= 2; i++)
            {
              WeatherCondition lCondition = lConditions[i];

              // Icon
              if (lCondition.ConditionIcon != int.MinValue)
              {
            Bitmap lIcon = (Bitmap)Properties.Resources.ResourceManager.GetObject("wicon32_" + lCondition.ConditionIcon.ToString());
            _Graphic.DrawImage(lIcon, 32 * i, 38, 32, 32);
              }
              else
              {
            _Graphic.DrawImage(Properties.Resources.wicon32_na, 32 * i, 38, 32, 32);
              }

              // Day
              string lDay = lCondition.Date.DayOfWeek.ToString().Substring(0, 2);
              int lDayX = (32 - _Graphic.MeasureString(lDay, _SmallFont).ToSize().Width) / 2;
              _Graphic.DrawString(lDay, _SmallFont, Brushes.White, i * 32 + lDayX, 22);

              // Temperature
              string lTemperature = "n/a";
              if (lCondition.TemperatureHigh != int.MaxValue) { lTemperature = string.Format("{0}{1}", lCondition.TemperatureHigh, _UnitSign); }
              else if (lCondition.TemperatureLow != int.MinValue) { lTemperature = string.Format("{0}{1}", lCondition.TemperatureLow, _UnitSign); }
              int lTemperatureX = (32 - _Graphic.MeasureString(lTemperature, _SmallFont).ToSize().Width) / 2;
              _Graphic.DrawString(lTemperature, _SmallFont, Brushes.White, i * 32 + lTemperatureX, 74);
            }

            // Update
            _Graphic.Flush();
            UpdateImage(_Bitmap);
              }
        }
Beispiel #11
0
 /// <summary>
 /// Adds passed condition, date is taken from passed object.
 /// </summary>
 /// <param name="condition">Condition to add.</param>
 public void SetData(WeatherCondition condition)
 {
     _Forecast[condition.Date] = condition;
 }
Beispiel #12
0
        private void Repaint_Period()
        {
            DateTime lDate = DateTime.Now.Date;

            WeatherCondition[] lConditions = new WeatherCondition[3];


            // ----- Get conditions
            for (int i = 0; i <= 2; i++)
            {
                lConditions[i] = _Data.GetData(_CurrentDisplayDate.AddDays(i));
            }


            // ----- Update image
            lock (_Graphic)
            {
                _Graphic.FillRectangle(Brushes.Black, 0, 0, 96, 96);

                // Title
                int lTitleX = (96 - _Graphic.MeasureString(_CurrentDisplayTitle, _TitleFont).ToSize().Width) / 2;
                _Graphic.DrawString(_CurrentDisplayTitle, _TitleFont, Brushes.CadetBlue, lTitleX, 0);

                // Conditions
                for (int i = 0; i <= 2; i++)
                {
                    WeatherCondition lCondition = lConditions[i];

                    // Icon
                    if (lCondition.ConditionIcon != int.MinValue)
                    {
                        Bitmap lIcon = (Bitmap)Properties.Resources.ResourceManager.GetObject("wicon32_" + lCondition.ConditionIcon.ToString());
                        _Graphic.DrawImage(lIcon, 32 * i, 38, 32, 32);
                    }
                    else
                    {
                        _Graphic.DrawImage(Properties.Resources.wicon32_na, 32 * i, 38, 32, 32);
                    }

                    // Day
                    string lDay  = lCondition.Date.DayOfWeek.ToString().Substring(0, 2);
                    int    lDayX = (32 - _Graphic.MeasureString(lDay, _SmallFont).ToSize().Width) / 2;
                    _Graphic.DrawString(lDay, _SmallFont, Brushes.White, i * 32 + lDayX, 22);

                    // Temperature
                    string lTemperature = "n/a";
                    if (lCondition.TemperatureHigh != int.MaxValue)
                    {
                        lTemperature = string.Format("{0}{1}", lCondition.TemperatureHigh, _UnitSign);
                    }
                    else if (lCondition.TemperatureLow != int.MinValue)
                    {
                        lTemperature = string.Format("{0}{1}", lCondition.TemperatureLow, _UnitSign);
                    }
                    int lTemperatureX = (32 - _Graphic.MeasureString(lTemperature, _SmallFont).ToSize().Width) / 2;
                    _Graphic.DrawString(lTemperature, _SmallFont, Brushes.White, i * 32 + lTemperatureX, 74);
                }

                // Update
                _Graphic.Flush();
                UpdateImage(_Bitmap);
            }
        }
Beispiel #13
0
        private void Repaint_Day()
        {
            DateTime         lDate      = DateTime.Now.Date;
            WeatherCondition lCondition = _Data.GetData(_CurrentDisplayDate);


            // ----- Title
            string lTitle = "";

            if (lCondition.Date.Date.Subtract(lDate).Days == 0)
            {
                lTitle = lCondition.IsNight ? "Tonight" : "Today";
            }
            else if (lCondition.Date.Date.Subtract(lDate).Days == 1)
            {
                lTitle = "Tomorrow";
            }
            else
            {
                lTitle = lCondition.Date.DayOfWeek.ToString();
            }


            // ----- Temperature
            string lTemperature = "";

            if (lCondition.TemperatureLow != int.MinValue && lCondition.TemperatureHigh != int.MaxValue)
            {
                // Both low and high available
                lTemperature = string.Format("{0}{1} to {2}{3}", lCondition.TemperatureLow, _UnitSign, lCondition.TemperatureHigh, _UnitSign);
            }
            else if (lCondition.TemperatureLow != int.MinValue)
            {
                // Only low available
                lTemperature = string.Format("{0}{1}", lCondition.TemperatureLow, _UnitSign);
            }
            else if (lCondition.TemperatureHigh != int.MaxValue)
            {
                // Only high available
                lTemperature = string.Format("{0}{1}", lCondition.TemperatureHigh, _UnitSign);
            }
            else
            {
                // None available
                lTemperature = "n/a";
            }


            // ----- Update image
            lock (_Graphic)
            {
                _Graphic.FillRectangle(Brushes.Black, 0, 0, 96, 96);

                // Title
                int lTitleX = (96 - _Graphic.MeasureString(lTitle, _TitleFont).ToSize().Width) / 2;
                _Graphic.DrawString(lTitle, _TitleFont, Brushes.CadetBlue, lTitleX, 0);

                // Icon
                if (lCondition.ConditionIcon != int.MinValue)
                {
                    Bitmap lIcon = (Bitmap)Properties.Resources.ResourceManager.GetObject("wicon64_" + lCondition.ConditionIcon.ToString());
                    _Graphic.DrawImage(lIcon, ICON_X, ICON_Y, 64, 64);
                }
                else
                {
                    _Graphic.DrawImage(Properties.Resources.wicon64_na, ICON_X, ICON_Y, 64, 64);
                }

                // Temperature
                int lTemperatureX = (96 - _Graphic.MeasureString(lTemperature, _SmallFont).ToSize().Width) / 2;
                _Graphic.DrawString(lTemperature, _SmallFont, Brushes.White, lTemperatureX, 80);

                // Update
                _Graphic.Flush();
                UpdateImage(_Bitmap);
            }
        }
        private void ParseDay_Part(XmlElement node, WeatherCondition data)
        {
            foreach (XmlElement lChild in node.ChildNodes)
              {
            switch (lChild.Name)
            {
              case "icon":
            data.ConditionIcon = int.Parse(lChild.InnerText);
            break;

              case "t":
            data.ConditionText = lChild.InnerText;
            break;
            }
              }
        }
        private WeatherCondition ParseDay(XmlElement node, bool parseNight)
        {
            WeatherCondition lResult = new WeatherCondition();
              lResult.IsNight = parseNight;

              foreach (XmlElement lChild in node.ChildNodes)
              {
            switch (lChild.Name)
            {
              case "hi":
            if (lChild.InnerText != "N/A")
            {
              lResult.TemperatureHigh = int.Parse(lChild.InnerText);
            }
            else
            {
              lResult.TemperatureHigh = int.MaxValue;
            }
            break;

              case "low":
            if (lChild.InnerText != "N/A")
            {
              lResult.TemperatureLow = int.Parse(lChild.InnerText);
            }
            else
            {
              lResult.TemperatureLow = int.MinValue;
            }
            break;

              case "part":
            if (lChild.Attributes["p"].Value == "d" && !parseNight)
            {
              ParseDay_Part(lChild, lResult);
            }
            else if (lChild.Attributes["p"].Value == "n" && parseNight)
            {
              ParseDay_Part(lChild, lResult);
            }
            break;
            }
              }

              return lResult;
        }
Beispiel #16
0
 /// <summary>
 /// Adds passed condition, date is taken from passed object.
 /// </summary>
 /// <param name="condition">Condition to add.</param>
 public void SetData(WeatherCondition condition)
 {
     _Forecast[condition.Date] = condition;
 }