Exemple #1
0
        protected Tuple <float, float, string> AnimalParams()
        {
            //Повторяющиеся действия с проверкой корректности и считывания можно было вынести с отдельный
            //сервис или Extension
            NotificationService.Write("Введите рост:");
            float height;

            while (!float.TryParse(ReaderService.ReadLine(), out height))
            {
                NotificationService.Write("Не корректрый формат данных.");
                NotificationService.Write("Введите рост:");
            }
            NotificationService.Write("Введите вес:");
            float weight;

            while (!float.TryParse(ReaderService.ReadLine(), out weight))
            {
                NotificationService.Write("Не корректрый формат данных.");
                NotificationService.Write("Введите вес:");
            }
            NotificationService.Write("Введите цвет глаз:");
            string eyeColor = ReaderService.ReadLine();

            //Tuple - удобно, но не очень объектно-ориентировано, надо об этом подумать
            return(new Tuple <float, float, string>(height, weight, eyeColor));
        }
Exemple #2
0
        public void PerformAction()
        {
            string i;

            do
            {
                System.Console.Clear();
                PrintAnimalsList(_zoo);                 // TODO: Удалить в релизе
                PrintMenu(_dict);
                i = _reader.ReadLine();
                try
                {
                    if (_dict.ContainsKey(i))
                    {
                        _dict[i].Execute();
                        System.Console.ReadKey();
                    }
                    else
                    {
                        _notification.Write("Нет такой команды.\n");
                        System.Console.ReadKey();
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    _notification.Write("Индекс вне области\n");
                    System.Console.ReadKey();
                }
                catch (IncorrectActionException e)
                {
                    _notification.Write(e.Message + "\n");
                    System.Console.ReadKey();
                }
            } while (i != "0");
        }
Exemple #3
0
        public static int ReadIndex(this CommandBase command, INotificationService notificationService, IReaderService readerService)
        {
            notificationService.Write("Введите номер животного: ");
            int index;

            while (!int.TryParse(readerService.ReadLine(), out index))
            {
                notificationService.Write("Неверный ввод.\n");
                notificationService.Write("Введите индекс животного: ");
            }
            return(--index);
        }