public void Run() { var databaseInitializerService = serviceProvider.GetService <IDatabaseInitializerService>(); databaseInitializerService.InitializeDatabase(); var commandDispatcher = new CommandDispatcher(this.serviceProvider); while (true) { var input = Console.ReadLine(); var commandTokens = input.Split(); var commandName = commandTokens.First(); var commandArgs = commandTokens.Skip(1).ToArray(); try { var command = commandDispatcher.ParseCommand(commandName); var result = command.Execute(commandName, commandArgs); Console.WriteLine(result); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
public void Run() { var dbInitializeService = serviceProvider.GetService <IDatabaseInitializerService>(); dbInitializeService.InitializeDatabase(); var commandDispatcher = new CommandDispatcher(serviceProvider); while (true) { try { Console.Write("Enter a command: "); var input = Console.ReadLine().Trim(); var data = input.Split(' '); var commandName = data.First(); var commandArgs = data.Length == 1 ? data.Take(1).ToArray() : data.Skip(1).ToArray(); var command = commandDispatcher.ParseCommand(commandName); var result = command.Execute(commandArgs); Console.WriteLine(result); if (result.Equals("Bye-bye!")) { Environment.Exit(0); } } catch (Exception e) { Console.WriteLine(e.Message); } } }