Пример #1
0
            /// <summary>
            /// logs display string of <paramref name="menuDialog"/> to console,
            /// blocks until user selects a menu option,
            /// and returns selected menu option index.
            /// </summary>
            /// <seealso cref="LogNotice(string, eOutputReportType, bool)"/>
            /// <seealso cref="int.TryParse(string, out int)"/>
            /// <param name="menuDialog"></param>
            /// <param name="outputReportType"></param>
            /// <returns>
            /// menu option index user selected
            /// </returns>
            /// <exception cref="ObjectDisposedException">
            /// <seealso cref="LogNotice(string, eOutputReportType, bool)"/>
            /// </exception>
            public int ShowMenuDialog(MenuDialog menuDialog, eOutputReportType outputReportType)
            {
                // display menu dialog
                LogNotice(menuDialog.DisplayString, outputReportType);

                // read user input
                string userInput = base.ReadLine();

                // parse int from user input
                bool parseSuccessful = int.TryParse(userInput, out int userSelectedOptionIndex);

                // keep requesting input so long as it's not valid
                while (!(parseSuccessful && menuDialog.IsValidOptionIndex(userSelectedOptionIndex)))
                {
                    LogNoticeFormat(
                        false,
                        outputReportType,
                        "Invalid input, please select an option in range [{0} - {1}]:",
                        menuDialog.MinValidOptionIndex,
                        menuDialog.MaxValidOptionIndex);

                    userInput       = base.ReadLine();
                    parseSuccessful = int.TryParse(userInput, out userSelectedOptionIndex);
                }

                return(userSelectedOptionIndex);
            }