예제 #1
0
        private static IConsoleRunnable SelectConsoleRunnableService(Queue <string> commands)
        {
            IEnumerable <Type> allTypes = Utils.FindAssignableClasses <IConsoleRunnable>();

            foreach (Type type in allTypes)
            {
                IConsoleRunnable consoleRunnable = Activator.CreateInstance(type) as IConsoleRunnable;
                if (consoleRunnable.GetCode() == commands.Peek())
                {
                    commands.Dequeue();
                    return(consoleRunnable);
                }
            }
            throw new Exception("Could not found command");
        }
예제 #2
0
 public static void Main()
 {
     DisplayWelcomeScreen();
     while (true)
     {
         try
         {
             string[] args = Utils.ReadCommand().Split(' ');
             Utils.Assert(args != null && args.Length != 0, "", fatal: true);
             if (args[0] == programCode)
             {
                 Queue <string> commands = new Queue <string>(args);
                 commands.Dequeue(); // programCode
                 IConsoleRunnable consoleService = SelectConsoleRunnableService(commands);
                 consoleService.Run(commands);
             }
             else
             {
                 if (args[0] == "clear")
                 {
                     Console.Clear();
                     System.Threading.Thread.Sleep(200);
                 }
                 else if (args[0] == "exit")
                 {
                     Environment.Exit(0);
                 }
                 else
                 {
                     throw new Exception("Command not found");
                 }
             }
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
             Console.WriteLine(e.StackTrace);
         }
     }
 }