static void Main(string[] args) { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); CarInfoDB carInfoDB = NewCarInfoDBCreate(); int signal = 0; while (true) { Console.Write("Enter command: "); string command = Console.ReadLine(); Invoker invoker = new Invoker(); switch (command) { case "count types": TypesCounter typesCounter = new TypesCounter(); CountTypesCommand countTypes = new CountTypesCommand(typesCounter, carInfoDB.CarsInformation); invoker.SetCommand(countTypes); invoker.Run(); break; case "count all": AllCounter allCounter = new AllCounter(); CountAllCommand countAll = new CountAllCommand(allCounter, carInfoDB.CarsInformation); invoker.SetCommand(countAll); invoker.Run(); break; case "average price": AveragePriceCalculator averegePriceCalculator = new AveragePriceCalculator(); AveragePriceCommand averagePrice = new AveragePriceCommand(averegePriceCalculator, carInfoDB.CarsInformation); invoker.SetCommand(averagePrice); invoker.Run(); break; case "exit": ProgramExit programExit = new ProgramExit(); ExitCommand exit = new ExitCommand(programExit); invoker.SetCommand(exit); invoker.Run(); break; default: foreach (CarInformation carInfo in carInfoDB.CarsInformation) { if (command.Contains("average price " + carInfo.Type)) { AveragePriceOfTypeCalculator averagePriceOfTypeCalculator = new AveragePriceOfTypeCalculator(); AveragePriceTypeCommand averagePriceType = new AveragePriceTypeCommand(averagePriceOfTypeCalculator, carInfoDB.CarsInformation, carInfo.Type); invoker.SetCommand(averagePriceType); invoker.Run(); signal++; break; } } if (signal == 0) { Console.WriteLine("Incorrect command. Try again."); } signal = 0; break; } } }
public CountAllCommand(AllCounter allCounter, List <CarInformation> carsInformation) { this.allCounter = allCounter; this.carsInformation = carsInformation; }