Example #1
0
        /// <summary>
        /// Proofs if all executioners have finished working before it calls a method to stop the application.
        /// </summary>
        /// <param name="sender">The sending object.</param>
        /// <param name="eventArgs">The key the user pressed.</param>
        /// <exception cref="ArgumentNullException">
        /// If eventArgs is null.
        /// </exception>
        private void CheckIfExecutionersFinished(object sender, OnKeyPressedEventArgs eventArgs)
        {
            if (eventArgs == null)
            {
                throw new ArgumentNullException();
            }

            bool result = true;

            foreach (Executioner executioner in this.executioners)
            {
                if (result)
                {
                    result = executioner.IsFinished;
                }
                else
                {
                    break;
                }
            }

            if (result)
            {
                this.TerminateApplication();
            }
        }
Example #2
0
 /// <summary>
 /// Fires the <see cref="OnKeyPressed"/> event.
 /// </summary>
 /// <param name="e">The arguments for the event.</param>
 protected virtual void FireOnKeyPressed(OnKeyPressedEventArgs e)
 {
     if (this.OnKeyPressed != null)
     {
         this.OnKeyPressed(this, e);
     }
 }
Example #3
0
        /// <summary>
        /// Is responsible for the correct work off of the key the user pressed.
        /// </summary>
        /// <param name="sender">The sending object.</param>
        /// <param name="eventArgs">The key the user pressed.</param>
        /// <exception cref="ArgumentNullException">
        /// If eventArgs is null.
        /// </exception>
        public void UseKey(object sender, OnKeyPressedEventArgs eventArgs)
        {
            if (eventArgs == null)
            {
                throw new ArgumentNullException();
            }

            ConsoleKeyInfo cki = eventArgs.KeyInfo;

            switch (cki.Key)
            {
            case ConsoleKey.Enter:
                if (!string.IsNullOrWhiteSpace(this.handler.Text))
                {
                    IEditorCommand command = this.parser.Parse(this.handler.Text);
                    this.errorMessage.Message = string.Empty;

                    if (command == null)
                    {
                        this.errorMessage.Message = "This is not a valid command.";
                    }
                    else
                    {
                        try
                        {
                            this.handler.Text = string.Empty;
                            this.handler.Accept(command);
                            this.user.Accept(command);
                        }
                        catch
                        {
                            this.errorMessage.Accept(command);
                        }
                    }
                }

                if (this.user.EditingIsFinished)
                {
                    this.keyBoardWatcher.OnKeyPressed -= this.UseKey;
                    this.InitializeExecution();
                    this.keyBoardWatcher.OnKeyPressed += this.CheckIfExecutionersFinished;
                }

                break;

            default:
                this.errorMessage.Message = string.Empty;
                this.handler.Start(cki);
                break;
            }

            this.handler.Accept(this.editorRenderer);
            this.errorMessage.Accept(this.editorRenderer);
        }