コード例 #1
0
 private void ExecuteExtendedCommand(ConsoleCommand command)
 {
     try
     {
         if (command is TimerCommand)
         {
             this._timerEnabled = !this._timerEnabled;
             if (this._timerEnabled)
             {
                 Console.WriteLine("Timer enabled.");
             }
             else
             {
                 Console.WriteLine("Timer disabled.");
             }
             return;
         }
         if (command is CommandTimeoutCommand)
         {
             int timeout = ((CommandTimeoutCommand)command).Timeout;
             if (timeout < 0)
             {
                 Console.WriteLine("Invalid command timeout specified. Must be a positive integer.");
             }
             else
             {
                 this._engine.ConnectionManager.ConnectionOptions.CommandTimeout = timeout;
                 if (timeout == 0)
                 {
                     Console.WriteLine("Command timeout set to 0 (unlimited).");
                 }
                 else if (timeout > 0)
                 {
                     Console.WriteLine("Command timeout set to " + timeout + " second(s).");
                 }
             }
             return;
         }
         if (command is ShowHistoryCommand)
         {
             this.ShowHistory(((ShowHistoryCommand)command).CommandCount);
             return;
         }
         if (command is SaveHistoryCommand)
         {
             this.SaveHistory(((SaveHistoryCommand)command).FilePath);
             return;
         }
         if (command is ClearHistoryCommand)
         {
             this._addToHistory = false;
             this._history.Clear();
             Console.WriteLine("History cleared.");
             return;
         }
         if (command is OpenLogCommand)
         {
             if (ConsoleHandler.IsLogOpen)
             {
                 throw new Exception("Log is already opened. To create a new log file, first close the current log using 'logclose'.");
             }
             ConsoleHandler.StartLog(((OpenLogCommand)command).FilePath, "> " + Settings.ConsoleCommandPrefix + "logopen", new string[] { ((OpenLogCommand)command).FilePath });
             Console.WriteLine("Log opened.");
             return;
         }
         if (command is CloseLogCommand)
         {
             if (!ConsoleHandler.IsLogOpen)
             {
                 throw new Exception("Log is already closed.");
             }
             ConsoleHandler.StopLog();
             Console.WriteLine("Log closed.");
             return;
         }
         Console.WriteLine("Extended command not recognized.");
     }
     catch (Exception exception)
     {
         Console.WriteLine("Error processing extended command.");
         if (!string.IsNullOrEmpty(exception.Message))
         {
             Console.WriteLine(exception.Message);
         }
     }
     Console.WriteLine("");
 }
コード例 #2
0
 internal void RunCommand(ConsoleCommand command)
 {
     this.EnsureInitialized();
     this.ExecuteExtendedCommand(command);
 }