Ejemplo n.º 1
0
        public static List <Forcast> parseForcasts(XmlDocument document, string elementName)
        {
            XmlNodeList    elemList    = document.GetElementsByTagName(elementName);
            List <Forcast> forcastList = new List <Forcast>();

            foreach (XmlNode elem in elemList)
            {
                Forcast forcast = new Forcast();
                forcast.ForcastDate = DateTime.ParseExact(elem.Attributes["date"].Value,
                                                          "d MMM yyyy", System.Globalization.CultureInfo.InvariantCulture);
                forcast.LowTemp        = int.Parse(elem.Attributes["low"].Value);
                forcast.HighTemp       = int.Parse(elem.Attributes["high"].Value);
                forcast.ForcastDetails = elem.Attributes["text"].Value;

                forcastList.Add(forcast);
            }

            return(forcastList);
        }
        public static List <string> generateAlerts(Forcast forcast)
        {
            if (forcast.LowTemp > forcast.HighTemp)
            {
                throw new ArgumentException("The Low Temperature cannot be higher than the high temperature");
            }

            List <string> output     = new List <string>();
            string        formatDate = forcast.ForcastDate.ToString("dddd, MMMM d");

            if (forcast.LowTemp <= FREEZING_TEMP_THRESHOLD)
            {
                output.Add(string.Format(FREEZING_TEMP_ALERT, formatDate));
            }

            if (forcast.HighTemp >= HIGH_HEAT_THRESHOLD)
            {
                output.Add(string.Format(HIGH_HEAT_ALERT, formatDate));
            }

            if (forcast.ForcastDetails.ToLower().Contains(RAIN_STRING))
            {
                output.Add(string.Format(RAIN_ALERT, formatDate));
            }

            if (forcast.ForcastDetails.ToLower().Contains(THUNDERSTORM_STRING))
            {
                output.Add(string.Format(THUNDERSTORM_ALERT, formatDate));
            }

            if (forcast.ForcastDetails.ToLower().Contains(SNOW_STRING))
            {
                output.Add(string.Format(SNOW_ALERT, formatDate));
            }

            if (forcast.ForcastDetails.ToLower().Contains(ICE_STRING))
            {
                output.Add(string.Format(ICE_ALERT, formatDate));
            }

            return(output);
        }
Ejemplo n.º 3
0
        public override bool Equals(Object obj)
        {
            Forcast forcastObj = obj as Forcast;

            if (forcastObj == null)
            {
                return(false);
            }
            else
            {
                if (forcastObj.ForcastDate.Equals(ForcastDate) &&
                    forcastObj.LowTemp == LowTemp &&
                    forcastObj.HighTemp == HighTemp &&
                    forcastObj.ForcastDetails.Equals(ForcastDetails))
                {
                    return(true);
                }
            }

            return(false);
        }