Ejemplo n.º 1
0
        public void Launch()
        {
            // user date
            Console.WriteLine("Enter a starting date (as mm/dd/yyyy): ");
            string dateStart = Console.ReadLine();

            // user time
            Console.WriteLine("--- Alert: the bug with the hours for the year 2013 are not fixed yet");
            Console.WriteLine("Enter a starting hour between 0 and 23: ");
            string timeStart = Console.ReadLine();

            DateAndTime dt = new DateAndTime();
            string      startDateAndTime = dt.ReadUserDateAndTime(dateStart, timeStart);

            // user date
            Console.WriteLine("Enter an ending date (as mm/dd/yyyy): ");
            string dateEnd = Console.ReadLine();

            // user time
            Console.WriteLine("Enter an ending hour between 0 and 23: ");
            string timeEnd = Console.ReadLine();

            string endDateAndTime = dt.ReadUserDateAndTime(dateEnd, timeEnd);

            ReadTextFiles      rd           = new ReadTextFiles();
            List <WeatherItem> weatherItems = ProcessUserDateAndTime(startDateAndTime, endDateAndTime);

            this.PointsToGraphic(weatherItems);
            // rd.DisplayItems(weatherItems);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Algorithm to return the full list of items to the user
        /// </summary>
        /// <param name="startDateAndTime">User entry</param>
        /// <param name="userDateAndTime">User entru</param>
        public List <WeatherItem> ProcessUserDateAndTime(string startDateAndTime, string endDateAndTime)
        {
            ReadTextFiles      rd           = new ReadTextFiles();
            List <WeatherItem> weatherItems = new List <WeatherItem>();

            try
            {
                int startYear = int.Parse(startDateAndTime.Split('_')[0]);
                int endYear   = int.Parse(endDateAndTime.Split('_')[0]);

                int currentYear = startYear;
                int gap         = ComputeGap(startYear, endYear);

                if (gap == 0)
                {
                    weatherItems.AddRange(rd.ReadYear(startDateAndTime, endDateAndTime));
                    return(weatherItems);
                }
                else if (gap == 1)
                {
                    weatherItems.AddRange(rd.ReadYearStart(startDateAndTime));
                    weatherItems.AddRange(rd.ReadYearEnd(endDateAndTime));
                    return(weatherItems);
                }
                else if (gap > 1)
                {
                    weatherItems.AddRange(rd.ReadYearStart(startDateAndTime));

                    currentYear++;
                    gap -= 1;

                    while (gap > 1)
                    {
                        weatherItems.AddRange(rd.ReadFullYear(currentYear));

                        currentYear++;
                        gap -= 1;
                    }
                    weatherItems.AddRange(rd.ReadYearEnd(endDateAndTime));
                    return(weatherItems);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(null);
        }