示例#1
0
        public string DisplayItems(IEnumerable <string> input)
        {
            var selection = input.ToList();

            int currentIndex = 1;

            int offSetFromTop = int.Parse(selection[selection.Count - 2]);
            int startingRow   = int.Parse(selection[selection.Count - 1]);

            for (int i = 0; i < selection.Count - 2; i++)
            {
                //Последните два елемента са ни координатите
                //Ако i == 0, то принтим най-отгоре с големи букви секцията на менюто, в която сме
                PrintAtPosition(i == 0 ? selection[i].ToUpper() : selection[i],
                                i * startingRow + offSetFromTop, i == currentIndex ? true : false);
            }

            //Тук проверяваме дали индекса ни е равен на настоящия селектиран елемент
            ConsoleKeyInfo key = alphaConsole.ReadKey(true);

            while (key.Key != ConsoleKey.Enter)
            {
                if (key.Key == ConsoleKey.UpArrow && currentIndex > 1)
                {
                    PrintAtPosition(selection[currentIndex]
                                    , currentIndex * startingRow + offSetFromTop, false);

                    PrintAtPosition(selection[--currentIndex],
                                    currentIndex * startingRow + offSetFromTop, true);
                }
                else if (key.Key == ConsoleKey.DownArrow && currentIndex < selection.Count - 3)
                {
                    PrintAtPosition(selection[currentIndex],
                                    currentIndex * startingRow + offSetFromTop, false);

                    PrintAtPosition(selection[++currentIndex],
                                    currentIndex * startingRow + offSetFromTop, true);
                }

                key = alphaConsole.ReadKey(true);
            }

            //Принтим просто "празно място", за по-бързо триене от конзолата
            for (int i = 0; i < selection.Count - 2; i++)
            {
                PrintAtPosition(new string(' ', selection[i].Length), i * startingRow + offSetFromTop, false);
            }

            return(selection[currentIndex]);
        }
示例#2
0
        public override IEnumerable <string> Execute(IEnumerable <string> input)
        {
            var parameters    = input.ToList();
            int offSetFromTop = int.Parse(parameters[parameters.Count - 2]);
            int startingRow   = int.Parse(parameters[parameters.Count - 1]);

            List <string> displayItems = new List <string>()
            {
                "UserInfo"
            };

            displayItems = new List <string>
            {
                parameters[0],
                "Retry",
                "Back",
                "Home"
            };

            string enterUserName = "******";
            int    currentRow    = startingRow * 0;

            selector.PrintAtPosition(displayItems[0].ToUpper(), currentRow++ + offSetFromTop, false);
            selector.PrintAtPosition(enterUserName, currentRow++ + offSetFromTop, false);

            string inputDetails = selector.ReadAtPosition(currentRow++ + offSetFromTop, enterUserName, false, 250);

            string[] userDetails = inputDetails.Split('|');
            displayItems.Add(offSetFromTop.ToString());
            displayItems.Add(startingRow.ToString());

            try
            {
                var userName = userDetails[0];
                if (userDetails.Length != 2)
                {
                    throw new ArgumentException("Please enter two arguments");
                }
                if (string.IsNullOrEmpty(userName))
                {
                    throw new ArgumentException("User name cannot be empty");
                }
                if (!int.TryParse(userDetails[1].Trim(), out int age))
                {
                    throw new ArgumentException("Age must be integer number");
                }
                //Just clear enterUserName string from the console
                selector.PrintAtPosition(new string(' ', enterUserName.Length), startingRow * 1 + offSetFromTop, false);

                //Find user by name
                int userID = this.userServices.GetID(userName);

                //Get projections that user has been on them
                var projections = this.userServices.GetProjectionsByUserID(userID);

                currentRow = offSetFromTop + 1;
                //Display all projections
                foreach (var projection in projections)
                {
                    selector.PrintAtPosition(projection.ToString(), currentRow++, false);
                }

                string endOfResluts = "Press any key to return";

                selector.PrintAtPosition(endOfResluts, currentRow, false);
                // TODO - HELP
                cinemaConsole.ReadKey(true);

                currentRow = offSetFromTop + 1;
                foreach (var projection in projections)
                {
                    selector.PrintAtPosition(new string(' ', projection.ToString().Length), currentRow++, false);
                }// Тук просто затриваме това което е било принтирано
                selector.PrintAtPosition(new string(' ', endOfResluts.Length), currentRow, false);

                return(parameters.Skip(1));//Извикваме предишната команда
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException || ex is EntityDoesntExistException)
                {
                    string wrongParametersDetails = ex.Message;

                    selector.PrintAtPosition(new string(' ', enterUserName.Length), 1 + offSetFromTop, false);                        //Затрива stringa enterAgeRange
                    selector.PrintAtPosition(wrongParametersDetails, startingRow * 4 + offSetFromTop, false);                         //Изписва error message-a

                    string selected = selector.DisplayItems(displayItems);                                                            //Изписва избора на бутон

                    selector.PrintAtPosition(new string(' ', wrongParametersDetails.Length), startingRow * 4 + offSetFromTop, false); //Затрива error message-a

                    if (selected == "Retry")
                    {
                        return(parameters);
                    }
                    else if (selected == "Back")
                    {
                        return(parameters.Skip(1));
                    }
                    else if (selected == "Home")
                    {
                        return(parameters.Skip(2));
                    }
                }
                return(ex.Message.ToString().Split());
            }
        }
示例#3
0
        public override IEnumerable <string> Execute(IEnumerable <string> input)
        {
            var parameters    = input.ToList();
            int offSetFromTop = int.Parse(parameters[parameters.Count - 2]);
            int startingRow   = int.Parse(parameters[parameters.Count - 1]);

            List <string> displayItems = new List <string>
            {
                parameters[0],
                "Retry",
                "Back",
                "Home"
            };

            string enterAgeRange = "Format: MinAge | MaxAge";
            int    currentRow    = startingRow * 0;

            selector.PrintAtPosition(displayItems[0].ToUpper(), currentRow++ + offSetFromTop, false);
            selector.PrintAtPosition(enterAgeRange, currentRow++ + offSetFromTop, false);

            string ages = selector.ReadAtPosition(currentRow++ + offSetFromTop, enterAgeRange, false, 250);

            displayItems.Add(offSetFromTop.ToString());
            displayItems.Add(startingRow.ToString());

            string[] agesDetails = ages.Split('|');

            try
            {
                if (agesDetails.Length != 2)
                {
                    throw new ArgumentException("Please enter two arguments");
                }

                if (!int.TryParse(agesDetails[0].Trim(), out int minAge))
                {
                    throw new ArgumentException("Min Age must be integer number");
                }
                if (!int.TryParse(agesDetails[1].Trim(), out int maxAge))
                {
                    throw new ArgumentException("Max Age must be integer number");
                }

                selector.PrintAtPosition(new string(' ', enterAgeRange.Length), startingRow * 1 + offSetFromTop, false);//Затрива stringa enterAgeRange

                var results = userServices.GetMoviesByUserAge(minAge, maxAge);
                currentRow = offSetFromTop + 1;
                foreach (var result in results)
                {
                    selector.PrintAtPosition(result.ToString(), currentRow++, false);
                }

                string endOfResluts = "Press any key to return to Information";
                selector.PrintAtPosition(endOfResluts, currentRow, false);

                cinemaConsole.ReadKey(true);

                currentRow = offSetFromTop + 1;
                foreach (var result in results)
                {
                    selector.PrintAtPosition(new string(' ', result.ToString().Length), currentRow++, false);
                }// Тук просто затриваме това което е било принтирано
                selector.PrintAtPosition(new string(' ', endOfResluts.Length), currentRow, false);

                return(parameters.Skip(1));//Извикваме предишната команда
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException)
                {
                    string wrongParametersDetails = ex.Message;

                    selector.PrintAtPosition(new string(' ', enterAgeRange.Length), 1 + offSetFromTop, false);//Затрива stringa enterAgeRange
                    selector.PrintAtPosition(wrongParametersDetails, startingRow * 4 + offSetFromTop, false);

                    string selected = selector.DisplayItems(displayItems);

                    selector.PrintAtPosition(new string(' ', wrongParametersDetails.Length), startingRow * 4 + offSetFromTop, false);

                    if (selected == "Retry")
                    {
                        return(parameters);
                    }
                    else if (selected == "Back")
                    {
                        return(parameters.Skip(1));
                    }
                    else if (selected == "Home")
                    {
                        return(parameters.Skip(2));
                    }
                }
                return(ex.Message.ToString().Split());
            }
        }