public void Run()
        {
            IDbInitializerService dbInitializerService = this.serviceProvider.GetService <IDbInitializerService>();

            dbInitializerService.InitializeDatabase();

            CommandParser cmdParser = new CommandParser(this.serviceProvider);

            while (true)
            {
                Console.Write("Enter command: ");

                string[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                string   commandName = input[0];
                string[] commandArgs = input.Skip(1).ToArray();

                try
                {
                    ICommand command = cmdParser.TryParseCommand(commandName);
                    string   result  = command.Execute(commandArgs);

                    Console.WriteLine(result);
                }
                catch (IndexOutOfRangeException)
                {
                    Console.WriteLine("Invalid command.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
예제 #2
0
        public void Run()
        {
            IDbInitializerService initialzeDb = this.serviceProvider.GetService <IDbInitializerService>();

            initialzeDb.InitializeDatabase();

            ICommandInterpreter commandInterpreter = this.serviceProvider.GetService <ICommandInterpreter>();

            while (true)
            {
                string[] input  = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   result = commandInterpreter.Read(input);
                Console.WriteLine(result);
            }
        }