static void Main(string[] args)
        {
            FlightBuilder flightBuilder = new FlightBuilder();

            FlightFilter flightFilter = new FlightFilter();

            IList <Flight> flights = flightBuilder.GetFlights();
            TimeSpan       limit   = new TimeSpan(2, 0, 0);

            Console.WriteLine("Already Left");
            OutputMessage(flightFilter.ExtractAlreadyLeft(DateTime.Now, flights));

            Console.WriteLine("Flight in the past");
            OutputMessage(flightFilter.ExtractFlightInThePast(flights));

            Console.WriteLine("Time spend on the ground more than two hours");
            OutputMessage(flightFilter.ExtractSpentOnEath(limit, flights));

            void OutputMessage(IList <Flight> flightsList)
            {
                foreach (Flight flight in flightsList)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Flight");
                    foreach (Segment segment in flight.Segments)
                    {
                        Console.WriteLine("DepartureDate {0} - ArrivalDate {1}", segment.DepartureDate, segment.ArrivalDate);
                    }
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            FlightBuilder builder = new FlightBuilder();
            List <Flight> flights = builder.GetFlights().ToList <Flight>();
            FlightFilter  filter1 = new FlightFilter(0);
            FlightFilter  filter2 = new FlightFilter(1);
            FlightFilter  filter3 = new FlightFilter(2);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Все полеты");
            Console.ResetColor();
            PrintFlights(flights);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Задание №1");
            Console.ResetColor();
            PrintFlights(filter1.FFiltreOut(flights));

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Задание №2");
            Console.ResetColor();
            PrintFlights(filter2.FFiltreOut(flights));

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Задание №3");
            Console.ResetColor();
            PrintFlights(filter3.FFiltreOut(flights));

            Console.ReadLine();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.Clear();
            Console.WriteLine("1,2,3");

            FlightBuilder flightBuilder = new FlightBuilder();

            IEnumerable <Flight> testFlights = flightBuilder.GetFlights();

            DateTime departureDateTime = DateTime.Now;
            //DateTime departureDateTime = DateTime.Parse(Console.ReadLine()); // 04/14/2021 18:00:00

            IEnumerable <Flight> flightsBeforeDateTime = testFlights.GetFlightsBefore(departureDateTime);

            Console.WriteLine($"Полёты с датой вылета до {departureDateTime}:");

            flightsBeforeDateTime.WriteToConsole();

            Console.WriteLine(new string('=', 50));

            IEnumerable <Flight> flightsArrivalBeforeDeparture = testFlights.GetFlightsArrivalBeforeDeparture();

            Console.WriteLine("Полёты у которых имеются сегменты с датой вылета позже даты прибытия:");

            flightsArrivalBeforeDeparture.WriteToConsole();

            Console.WriteLine(new string('=', 50));

            IEnumerable <Flight> flightsWithToHoursDelay = testFlights.GetFlightsWithTwoHoursDelay();

            Console.WriteLine("Полёты у которых время ожидания между перелётами более 2-х часов:");

            flightsWithToHoursDelay.WriteToConsole();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            FlightBuilder flightBuilder = new FlightBuilder();
            var           flights       = flightBuilder.GetFlights();

            Console.WriteLine("======================================\n" +
                              "All flights:");
            foreach (var flight in flights)
            {
                Console.WriteLine(FlightOutput.FlightToString(flight));
            }

            Console.WriteLine("======================================\n" +
                              "Flights with departure date up to the current time are excluded:");
            foreach (var flight in flights.Except(flights.FlightsDepartingInThePast()))
            {
                Console.WriteLine(FlightOutput.FlightToString(flight));
            }

            Console.WriteLine("======================================\n" +
                              "Flights with an arrival date earlier than the departure date are excluded:");
            foreach (var flight in flights.Except(flights.FlightsThatDepartsBeforeItArrives()))
            {
                Console.WriteLine(FlightOutput.FlightToString(flight));
            }

            Console.WriteLine("======================================\n" +
                              "Flights with more than two hours ground time are excluded:");
            foreach (var flight in flights.Except(flights.FlightsWithMoreThanTwoHoursGroundTime()))
            {
                Console.WriteLine(FlightOutput.FlightToString(flight));
            }
        }
Exemple #5
0
        static void Main(string[] args)
        {
            FlightBuilder  flightBuilder = new FlightBuilder();
            IList <Flight> flights       = flightBuilder.GetFlights();

            FiltrationModule.DepartingInThePastCheck(flights);
            FiltrationModule.DepartsBeforeItArrivesCheck(flights);
            FiltrationModule.FlightWithMoreThanTwoHoursGroundCheck(flights);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Writer.Greeting();
            FlightBuilder builder = new FlightBuilder();
            FilterModule  module  = new FilterModule(builder.GetFlights());

            bool exit = true;

            do
            {
                exit = Reader.MainMenuResponse(ref module, builder);
            } while (exit);
        }
        private static void Main(string[] args)
        {
            Console.WriteLine($"Текущее время: {DateTime.Now}");
            var flights          = new FlightBuilder().GetFlights();
            var flightFormatter  = new FlightFormatProvider();
            var validatorService = new FlightValidationService();

            WriteLineWithColors("Всего полетов:");
            foreach (var f in flights)
            {
                Console.WriteLine(string.Format(flightFormatter, "{0}", f));
            }

            WriteLineWithColors("Вылет до текущего момента времени:");
            foreach (var f in validatorService.Validate(flights, new FlightValidationServiceOptions(new AnyDepartureTimeEarlierThanValidator(DateTime.Now))))
            {
                Console.WriteLine(string.Format(flightFormatter, "{0}", f));
            }

            WriteLineWithColors("Имеются сегменты с датой прилёта раньше даты вылета:");
            foreach (var f in validatorService.Validate(flights, new FlightValidationServiceOptions(new AnyArrivalTimeEarlierThanDepartureValidator())))
            {
                Console.WriteLine(string.Format(flightFormatter, "{0}", f));
            }

            WriteLineWithColors("Общее время, проведённое на земле превышает два часа:");
            try
            {
                foreach (var f in validatorService.Validate(flights,
                                                            new FlightValidationServiceOptions(new GroundTimeMoreThanValidator(TimeSpan.FromHours(2)))))
                {
                    Console.WriteLine(string.Format(flightFormatter, "{0}", f));
                }
            }
            catch (ArgumentException ex)
            {
                WriteLineWithColors($"{ex.Message}", ConsoleColor.Red);
            }
            finally
            {
                WriteLineWithColors("Валидируем все полеты, имеющие не менее двух сегментов. Результат:");
                foreach (var f in validatorService.Validate(flights.Where(c => c.Segments.Count > 1),
                                                            new FlightValidationServiceOptions(new GroundTimeMoreThanValidator(TimeSpan.FromHours(2)))))
                {
                    Console.WriteLine(string.Format(flightFormatter, "{0}", f));
                }
            }
        }
Exemple #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("1. Вылет до текущего момента времени");
            Console.WriteLine("2. Сегмент с датой прилёта раньше даты вылета");
            Console.WriteLine("3. Общее время, проведённое на земле превышает два часа");
            Console.WriteLine("-------------------------------------------------------");

            while (true)
            {
                FilterManager filterManager = new FilterManager();

                Console.WriteLine("Добавить номер фильтров через пробел или 0 для выбора всех фильтров");

                var commands = Console.ReadLine()?.Split(' ');

                foreach (var command in commands)
                {
                    switch (command)
                    {
                    case "1":
                        filterManager.AddFilter(new FilterNowTime(DateTime.Now));
                        break;

                    case "2":
                        filterManager.AddFilter(new FilterDepartsBeforeArrives());
                        break;

                    case "3":
                        filterManager.AddFilter(new FilterOverHoursOnGround(2));
                        break;

                    case "0":
                        filterManager.AddFilter(new FilterNowTime(DateTime.Now));
                        filterManager.AddFilter(new FilterDepartsBeforeArrives());
                        filterManager.AddFilter(new FilterOverHoursOnGround(2));
                        break;
                    }
                }

                FlightBuilder flightBuilder = new FlightBuilder();
                var           flights       = flightBuilder.GetFlights();

                filterManager.Process(flights);
                Console.WriteLine("******************************************************\r\n");
            }
        }
Exemple #9
0
        private static void Main(string[] args)
        {
            var filterCase1 = new IFlightFilter[] { new BeforeNowDepartureFlightFilter() };
            var filterCase2 = new IFlightFilter[] { new ArrivalBeforeDepartureFilter() };
            var filterCase3 = new IFlightFilter[] { new TwoHoursDelayFilter() };

            var filterExtraCase = new IFlightFilter[]
            { new BeforeNowDepartureFlightFilter(), new ArrivalBeforeDepartureFilter(), new TwoHoursDelayFilter() };

            var flightBuilder = new FlightBuilder();
            var flights       = flightBuilder.GetFlights();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nBeforeNowDepartureFlightFilter Results:");
            Console.ResetColor();
            foreach (var flight in flights.Filter(filterCase1))
            {
                flight.DisplayInfo();
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nArrivalBeforeDepartureFilter Results:");
            Console.ResetColor();
            foreach (var flight in flights.Filter(filterCase2))
            {
                flight.DisplayInfo();
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nTwoHoursDelayFilter Results:");
            Console.ResetColor();
            foreach (var flight in flights.Filter(filterCase3))
            {
                flight.DisplayInfo();
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nAll Filters Results:");
            Console.ResetColor();
            foreach (var flight in flights.Filter(filterExtraCase))
            {
                flight.DisplayInfo();
            }
        }
Exemple #10
0
        public void AddFlight()
        {
            var src      = Source.ToList();
            int segCount = Reader.NumberOfSegments();

            DateTime[] dateTimes;
            try
            {
                dateTimes = Reader.DepartArriveDates(segCount);
            }
            catch (Exception)
            {
                return;
            }
            var flight = FlightBuilder.CreateFlight(dateTimes);

            src.Add(flight);
            Source = src;
            src    = Flights.ToList();
            src.Add(flight);
            Flights = src;
        }
Exemple #11
0
        static void Main(string[] args)
        {
            FlightBuilder fb      = new FlightBuilder();
            List <Flight> flights = (List <Flight>)fb.GetFlights();
            List <Rule>   rules   = new List <Rule> {
                IsDepartureBeforeNow, IsArrivalsBeforeDeparture, IsGroundTimeMoreThenTwoHours
            };

            //Filtering flights by rule "Departure before now"
            List <Flight> filteredByFirstRuleFlights = FilterFlights((List <Flight>)fb.GetFlights(), rules[0]);

            Console.WriteLine("Flights filtered by rule \"Departure before now\":\n");
            foreach (Flight flight in filteredByFirstRuleFlights)
            {
                Console.WriteLine(flight.Description);
            }
            Console.WriteLine("\n");

            //Filtering flights by rule "Have segments where arrival before departure"
            List <Flight> filteredBySecondRuleFlights = FilterFlights((List <Flight>)fb.GetFlights(), rules[1]);

            Console.WriteLine("Flights filtered by rule \"Have segments where arrival before departure\":\n");
            foreach (Flight flight in filteredBySecondRuleFlights)
            {
                Console.WriteLine(flight.Description);
            }
            Console.WriteLine("\n");

            //Filtering flights by rule "Total ground time is more than two hours"
            List <Flight> filteredByThirdRuleFlights = FilterFlights((List <Flight>)fb.GetFlights(), rules[2]);

            Console.WriteLine("Flights filtered by rule \"Total ground time is more than two hours\":\n");
            foreach (Flight flight in filteredByThirdRuleFlights)
            {
                Console.WriteLine(flight.Description);
            }
            Console.WriteLine("\n");
        }
Exemple #12
0
        static void Main(string[] args)
        {
            FlightBuilder flightBuilder = new FlightBuilder();
            var           flights       = flightBuilder.GetFlights();
            List <Filter> filters       = new List <Filter> {
                new TimeFilter(), new SegmentFilter(), new GroundFilter()
            };

            Print(flights, filters, flights);
            while (true)
            {
                string input = Console.ReadLine();
                if (input.ToLower() == "exit")
                {
                    break;
                }
                else
                {
                    if (input == "")
                    {
                        Print(flights, filters, flights);
                    }
                    else
                    {
                        if (input.Contains(" "))
                        {
                            string[] nums       = input.Split(' ');
                            var      tmpFlights = flights;
                            bool     flag       = false;
                            foreach (var num in nums)
                            {
                                if (num == "")
                                {
                                    continue;
                                }
                                try
                                {
                                    tmpFlights = ChooseFilter(num, filters, tmpFlights);
                                }
                                catch (Exception)
                                {
                                    Error();
                                    Default(filters);
                                    flag = true;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                continue;
                            }
                            Print(tmpFlights, filters, flights);
                        }
                        else
                        {
                            try
                            {
                                Print(ChooseFilter(input, filters, flights), filters, flights);
                            }
                            catch (Exception)
                            {
                                Error();
                                Default(filters);
                                continue;
                            }
                        }
                    }
                }
            }
        }