Ejemplo n.º 1
0
        public static IntValidation ParseInt(string input)
        {
            //Assume that validation does not pass
            var result = new IntValidation {
                IsValid = false, Number = 0
            };

            int number;

            if (!Int32.TryParse(input, out number))
            {
                return(result);
            }

            result.IsValid = true;
            result.Number  = number;

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates a string input as valid number for the main menu
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private static IntValidation ValidateMainMenuInput(string input)
        {
            //Assume that validation does not pass
            var result = new IntValidation {
                IsValid = false, Number = 0
            };

            int number;

            if (!Int32.TryParse(input, out number) || !mainMenuItems.ContainsKey(number))
            {
                Console.WriteLine(_enterANumber);
                return(result);
            }

            result.IsValid = true;
            result.Number  = number;

            return(result);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            GenerateMainMenu();

            string        input           = null;
            IntValidation inputValidation = null;

            do
            {
                input           = Console.ReadLine();
                inputValidation = ValidateMainMenuInput(input);
            }while (!inputValidation.IsValid);

            var taskManager = GetTaskManager(inputValidation.Number);

            taskManager.GenerateMenu();

            inputValidation = new IntValidation {
                IsValid = false, Number = 0
            };
            do
            {
                Console.Write(_enterANumberInline);
                input           = Console.ReadLine();
                inputValidation = StringHelper.ParseInt(input);
            }while (!inputValidation.IsValid);

            Globals.Task task = taskManager.GenerateTask(inputValidation.Number);
            while (task == null)
            {
                Console.WriteLine(_enterANumber);
                task = taskManager.GenerateTask(inputValidation.Number);
            }

            task.Run();
        }