Ejemplo n.º 1
0
 /// <summary>
 /// Write wrong option message
 /// </summary>
 /// <param name="selectedOptionText"></param>
 /// <param name="consoleSelect"></param>
 private void WrongOption(string selectedOptionText, ConsoleSelect consoleSelect)
 {
     Console.ForegroundColor = ConsoleColor.DarkRed;
     Console.WriteLine(Messages.WrongOption, selectedOptionText);
     Console.ResetColor();
     ReadSelectedOption(consoleSelect);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Wait user input, verify if is a correct option and set option to selected
        /// </summary>
        /// <param name="consoleSelect"></param>
        private void ReadSelectedOption(ConsoleSelect consoleSelect)
        {
            Console.WriteLine();
            Console.Write(Messages.ChooseOption);

            string selectedOptionText = Console.ReadLine();

            int selectedOption = 0;

            if (int.TryParse(selectedOptionText, out selectedOption) && IsValidRange(consoleSelect, --selectedOption))
            {
                this.SelectedOption = consoleSelect.Options[selectedOption];
            }
            else if (selectedOption == consoleSelect.Options.Count)
            {
                this.Previous();
            }
            else if (selectedOption == 98)
            {
                this.Exit();
            }
            else
            {
                this.WrongOption(selectedOptionText, consoleSelect);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Write node
        /// </summary>
        /// <param name="node">Node</param>
        /// <param name="deep">Deep</param>
        private static void WriteNode(ConsoleOption node, int deep)
        {
            deep++;
            RenderNode(node, deep);

            if (node is ConsoleSelect)
            {
                ConsoleSelect select = node as ConsoleSelect;
                foreach (ConsoleOption item in select.Options)
                {
                    WriteNode(item, deep);
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Create a new console state machine
 /// </summary>
 /// <param name="description">Description</param>
 /// <param name="initialSelect">Initial menu</param>
 public ConsoleMachine(string description, ConsoleSelect initialSelect)
 {
     this.Description    = description;
     this.SelectedOption = initialSelect;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Create and start new console state machine
        /// </summary>
        /// <param name="select">Initial menu</param>
        /// <param name="description">Description</param>
        public static void Start(ConsoleSelect select, string description = "Untitled")
        {
            ConsoleMachine machine = new ConsoleMachine(description, select);

            machine.Execute();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Verify if selected option is valid in range
 /// </summary>
 /// <param name="consoleSelect">Current console select</param>
 /// <param name="selectedOption">Next selected option</param>
 /// <returns></returns>
 private bool IsValidRange(ConsoleSelect consoleSelect, int selectedOption)
 {
     return(selectedOption > -1 && selectedOption < consoleSelect.Options.Count);
 }