static void Main(string[] args) { try { // Creates a command manager instance _commandService = CommandServiceFactory.CreateInstance(); // Display welcome message ShowWelcomeMessage(); while (true) { // Gets the user's input InputCommand inputCommand = new InputCommand(Console.ReadLine()); // Checks if input command is valid if (!inputCommand.IsValid()) { ShowErrorMessage("Command cannot be empty. Please type 'help' for instructions."); continue; } // Check if the command exists Command command = _commandService.GetCommand(inputCommand.CommandName, inputCommand.Parameters); if (command == null) { ShowErrorMessage("Command is not valid. Please type 'help' for instructions."); continue; } Console.WriteLine("\n"); // Validates the command's parameters OperationReturn <string> response = command.ValidateParameters(); if (response.Success == false) { ShowErrorMessage(response.MessageList); continue; } // Executes the command response = command.Process(); if (response.Success == false) { ShowErrorMessage(response.MessageList); continue; } Console.WriteLine(response.Data); } } catch (Exception ex) { //TODO: Log exception ShowErrorMessage($"Internal Server error: {ex.Message}"); Thread.Sleep(10000); } }
private static void RegisterCommands(IIocContainer container) { ContractServices.LoadDependentAssemblies(typeof(ApiCoordinationTypeMark).Assembly); var commandContracts = ContractServices.GetAllServices(".Contracts", "Command"); container.RegisterPerGraph( new[] { typeof(IProxyContainer) }, typeof(ProxyContainer)); container.RegisterAllServicesFactoryTransient((r, type) => { var optPack = r.Resolver(typeof(IOptimizationPackage)) as IOptimizationPackage; var proxyContainer = r.Resolver(typeof(IProxyContainer)) as IProxyContainer; return(CommandServiceFactory.CreateCommandService(type, proxyContainer, optPack)); }, commandContracts); }