示例#1
0
        public static void RunInteractiveMode(ICollection <IPlugin> plugins, string arg)
        {
            log.Information("Running app with a parameter: " + arg);

            bool shouldfinish           = false;
            ConsoleCommandHolder holder = new ConsoleCommandHolder();

            holder.AddRange(new ConsoleCommand[] { new SimpleCommand("Stop application", new string[] { "stop" },
                                                                     (x) =>
                {
                    Console.WriteLine("Do you really want to stop? (type 'yes' to stop)");
                    string acceptString = Console.ReadLine();
                    if (acceptString == "yes")
                    {
                        shouldfinish = true;
                    }
                }),
                                                   new SimpleCommand("HELP", new string[] { "help" }, (x) => DisplayHelpWithLogging()), });

            foreach (var plugin in plugins)
            {
                holder.Add(new SimpleCommand(plugin.Name, new string[] { plugin.Name.ToLower() }, (x) => ExecutePlugin(plugin)));
            }

            while (shouldfinish == false)
            {
                string         command   = Console.ReadLine();
                ConsoleCommand toExecute = holder.Find(command);
                if (toExecute != null)
                {
                    toExecute.Do(command);
                }
                else
                {
                    Console.WriteLine(holder);
                }
            }
        }
 public void Add(ConsoleCommand toAdd)
 {
     unique.Add(toAdd);
 }