Пример #1
0
 private static void DisplayExceptionDetails(Exception ex)
 {
     C.Wl("\n**********\nERROR!: " + ex.Message + "\n**********\n");
     if (C.PromptUser("stacktrace?:").ToUpper().StartsWith("Y", StringComparison.Ordinal))
     {
         C.Wl(ex.StackTrace);
     }
 }
Пример #2
0
        /// <summary>
        /// Starts the shell loop. Prior to entering the loop any Intro text
        /// will be printed to the console, and the PreLoop method will be
        /// executed.
        ///
        /// </summary>
        public void CmdLoop()
        {
            if (_isInLoop)
            {
                return;            // just in case of multithreaded shennanigans
            }
            _isInLoop = true;

            if (!_isInitialized)
            {
                InitCommandDictionary();
            }

            if (!string.IsNullOrWhiteSpace(Intro) && Intro.Length > 0)
            {
                C.Wl(Intro);
            }

            PreLoop();
            var editor = new LineEditor(HistoryFileName);

            if (DoAutoComplete)
            {
                var list = new List <string>(_commands.Keys);
                editor.SetAutoCompleteCommandList(list);
            }
            IsExiting = false; // We should reset the exit condition priort to entering.
            while (!IsExiting)
            {
                try
                {
                    var userInput = editor.Edit(CommandPrompt, "");
                    userInput = PreCmd(userInput);

                    if (userInput == null)
                    {
                        // ctrl-D will return null, this should exit the loop
                        // without running the PostCmd method.
                        ExitLoop();
                        continue;
                    }

                    HandleCommandString(userInput);
                    PostCmd(userInput);

                    // At this point it is safe to save the command history.
                    // Any commands that cause an exception should not be saved to
                    // history.
                    editor.SaveHistory();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }

            PostLoop();
        }
Пример #3
0
 public virtual void Default(string line)
 {
     if (string.IsNullOrWhiteSpace(line))
     {
         C.Wl("Illegal command entered.");
     }
     else
     {
         var cmdName = line.Split(" ".ToCharArray());
         C.Wl($"Command '{cmdName[0]}' is not defined.");
     }
 }