Ejemplo n.º 1
0
 public void Start()
 {
     WriteSystemText(Environment.NewLine + "Starting X console.Please wait....");
     Thread.Sleep(2000);
     ;
     if (Config[CONSOLE_ENABL_KEY] == "1" || Config[CONSOLE_ENABL_KEY] == "yes")
     {
         WelcomeMessage();
         while (true)
         {
             Writer.Write(Prompt, ConsoleColor.Black, ConsoleColor.White);
             Writer.Write(" ");
             string command = Console.ReadLine();
             if (command == "quit" || command == "exit")
             {
                 Quit();
             }
             if (command == "clear" || command == "cls")
             {
                 Console.Clear();
                 WelcomeMessage();
             }
             else
             {
                 if (command == "help")
                 {
                     command = "list-commands";
                 }
                 var commandClass = FindCommand(command);
                 if (commandClass != null)
                 {
                     IXCommand instance = null;
                     try
                     {
                         instance = CreateCommandInstance(commandClass);
                     }
                     catch (Exception ex)
                     {
                         WriteSystemText("Error creating command instance.");
                         Writer.WriteLine(ex.Message, ConsoleColor.DarkRed);
                         instance = null;
                     }
                     if (instance != null)
                     {
                         try
                         {
                             instance.Run(this).GetAwaiter().GetResult();
                         }
                         catch (Exception ex)
                         {
                             WriteSystemText("Unhandled exception thrown while running the command.");
                             Writer.WriteLine(ex.Message, ConsoleColor.DarkRed);
                         }
                     }
                     else
                     {
                         WriteSystemText("Command instance is null. Cannot continue.");
                     }
                 }
                 else
                 {
                     WriteSystemText($"Could not find the command {command}.");
                 }
             }
         }
     }
     else
     {
         WriteSystemText("Console is disabled.");
         Quit();
     }
 }