Ejemplo n.º 1
0
 /// <summary>
 /// Subscribe method, once sorting will be completed
 /// </summary>
 /// <param name="args">event args</param>
 public void OnArrayWasSorted(ArrayWasSortedEventArgs args)
 {
     lock (locker)
     {
         Console.WriteLine("\n\nArray was sorted with:<{0}>. \nWith Elapsed time:<{1}>: \n______", args.SorterName, args.stopWatch.Elapsed);
         SortUtil.Print2DArrayToConsole(SortUtil.Convert1DArraTo2D(args.Array1D, current2DArray.GetLength(0), current2DArray.GetLength(1)));
         counterForOutputs++;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Mathod which is representing the main menu;
        /// </summary>
        public void ShowMenu()
        {
            //objects and fields init:
            bool isExit = false;

            current2DArray = SortUtil.Generate2DArray(10, 10);

            //Menu:
            while (!isExit)
            {
                //Menu generator:
                Console.Clear();
                int sorterListMenuItemCounter = menuNumberConst;

                //TODO: create array of string and print
                Console.WriteLine(
                    "\t\tChoose your actions:\n" +
                    "(1) - Generate new custom 2D array\n" +
                    "(2) - Import array from DB\n" +
                    "(3) - Print 2D array\n\n" +
                    "(4) - Sort simultaneously with all sorters"
                    );

                //generating dynamic menu, according to incoming List of sorters
                foreach (ISorter sorter in sorterList)
                {
                    Console.WriteLine("({0}) - {1}", sorterListMenuItemCounter, sorter);
                    sorterListMenuItemCounter++;
                }

                //Display last step - exit
                Console.WriteLine("({0}) - Exit", sorterList.Count + menuNumberConst);

                //Reading user selection and parse for correct value:
                userSelectionMainMenu = SortUtil.ValidateInputNumberForIntValue(Console.ReadLine(), 1, sorterList.Count + menuNumberConst);

                //User selection 1-3 handler:
                switch (userSelectionMainMenu)
                {
                case 1:
                    MenuDialog_GenerateNew2DArray();
                    break;

                case 2:
                    current2DArray = sqlConnectionUtil.Get2DArrayFromDB();
                    Console.Clear();
                    Console.WriteLine("Array was readed from DB, please press any key...");
                    Console.ReadKey();
                    break;

                case 3:
                    Console.Clear();
                    Console.WriteLine("Please see below printed 2D array:\n\n");
                    SortUtil.Print2DArrayToConsole(current2DArray);
                    Console.WriteLine("To continue, please press any key...");
                    Console.ReadKey();
                    break;

                case 4:
                    MenuDialog_SortingMenuHandler(true);
                    break;

                default:
                    break;
                }

                //sub menu (for list of sorters) selection, in case of user selected sorting methods:
                if (Enumerable.Range(menuNumberConst, sorterList.Count).Contains(userSelectionMainMenu))
                {
                    MenuDialog_SortingMenuHandler(false);
                }

                //exit logic
                else if (userSelectionMainMenu == sorterList.Count + menuNumberConst)
                {
                    isExit = true;
                }
            }
        }