示例#1
0
        /// <summary>
        /// Prints the rotor key list.
        /// </summary>
        private void PrintRotorKeys(MenuDriver menuDriver)
        {
            int[] keys = menuDriver.Interpreter.GetRotorKeys();
            if (keys == null)
            {
                PrintError($"No rotor keys are loaded!");
                return;
            }

            // +1 because the last letter does not need a space after it.
            int keysPerRow = (ScreenWidth - RotorKeysMargin + 1) / RotorKeyWidth;

            Console.ForegroundColor = ConsoleColor.Blue;
            int i = 0;

            while (i < keys.Length)
            {
                StringBuilder str = new StringBuilder();
                for (int j = 0; i < keys.Length && j < keysPerRow; i++, j++)
                {
                    str.Append(keys[i].ToString().PadLeft(RotorKeyWidth - 1).PadRight(RotorKeyWidth));
                }
                PrintLine(str.ToString().TrimEnd());
            }
            Console.ResetColor();
        }
        /// <summary>
        /// Prints the missing files menu to the screen.
        /// </summary>
        protected override void PrintScreen(MenuDriver screenDriver)
        {
            Console.Clear();

            Console.ForegroundColor = ConsoleColor.Red;
            if (!File.Exists(FilePath))
            {
                // Missing MissingFilesMenu text file, print a hardcoded menu instead
                Console.WriteLine();
                PrintLine("Unhandled Exception!");
                Console.WriteLine();
                PrintLine("The following error occurred while running the program:");
                Console.WriteLine();
                PrintException();
                Console.WriteLine();
            }
            else
            {
                // Read the text for the menu
                string[] lines = ReadScreenFile(FilePath);
                foreach (string line in lines)
                {
                    // Insert the letterset into the menu
                    if (line.Trim() == ExceptionMarker)
                    {
                        PrintException();
                    }
                    else
                    {
                        PrintLine(line);
                    }
                }
            }
            Console.ResetColor();
        }
示例#3
0
        /// <summary>
        /// Prints the missing files menu to the screen.
        /// </summary>
        protected override void PrintScreen(MenuDriver screenDriver)
        {
            Console.Clear();

            Console.ForegroundColor = ConsoleColor.Red;
            if (!File.Exists(FilePath))
            {
                // Missing MissingFilesMenu text file, print a hardcoded menu instead
                Console.WriteLine();
                PrintLine("Missing Files!");
                Console.WriteLine();
                PrintLine("The following files required for runtime are missing, including the file to display this error menu!");
                Console.WriteLine();
                PrintMissingFiles();
                Console.WriteLine();
            }
            else
            {
                // Read the text for the menu
                string[] lines = ReadScreenFile(FilePath);
                foreach (string line in lines)
                {
                    // Insert the letterset into the menu
                    if (line.Trim() == MissingFilesMarker)
                    {
                        PrintMissingFiles();
                    }
                    else
                    {
                        PrintLine(line);
                    }
                }
            }
            Console.ResetColor();
        }
示例#4
0
 /// <summary>
 /// Prints the missing file list.
 /// </summary>
 private void PrintMissingFiles(MenuDriver menuDriver)
 {
     foreach (string file in MissingFiles)
     {
         PrintLine(file);
     }
 }
示例#5
0
        /// <summary>
        /// Prints the letterset list.
        /// </summary>
        private void PrintLetterset(MenuDriver menuDriver)
        {
            string[] letters = menuDriver.Interpreter.GetEscapedLetterSet();
            if (letters == null)
            {
                PrintError($"No letterset is loaded!");
                return;
            }

            // +1 because the last letter does not need a space after it.
            int lettersPerRow = (ScreenWidth - LettersetMargin + 1) / LetterWidth;

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            int i = 0;

            while (i < letters.Length)
            {
                StringBuilder str = new StringBuilder();
                for (int j = 0; i < letters.Length && j < lettersPerRow; i++, j++)
                {
                    str.Append(letters[i].PadRight(LetterWidth));
                }
                PrintLine(str.ToString().TrimEnd());
            }
            Console.ResetColor();
        }
 /// <summary>
 /// Runs the screen.
 /// </summary>
 /// <returns>The action to perform after a screen choice.</returns>
 protected override sealed MenuAction RunScreen(MenuDriver screenDriver)
 {
     RunScreen(screenDriver.Interpreter);
     Console.Write("Press Enter: ");
     Console.ReadLine();
     return(screenDriver.MainMenu);
 }
示例#7
0
        /// <summary>
        /// Prints the steckering list.
        /// </summary>
        private void PrintSteckering(MenuDriver menuDriver)
        {
            string[] letters    = menuDriver.Interpreter.GetEscapedLetterSet();
            int[]    steckering = menuDriver.Interpreter.GetSteckering();
            if (letters == null)
            {
                PrintError($"No letterset is loaded!");
                return;
            }
            else if (steckering == null)
            {
                PrintError($"No steckering is loaded!");
                return;
            }

            // +1 because the last letter does not need a space after it.
            int steckersPerRow = (ScreenWidth - SteckeringMargin + 1) / SteckerWidth;

            Console.ForegroundColor = ConsoleColor.Magenta;
            int i = 0;

            while (i < steckering.Length)
            {
                StringBuilder str = new StringBuilder();
                for (int j = 0; i < steckering.Length && j < steckersPerRow; i++, j++)
                {
                    str.Append(letters[i].PadLeft(2));
                    str.Append("=");
                    str.Append(letters[steckering[i]].PadRight(2));
                    str.Append(" ");
                }
                PrintLine(str.ToString().TrimEnd());
            }
            Console.ResetColor();
        }
        /// <summary>
        /// Prints the letterset list.
        /// </summary>
        private void PrintLetterset(MenuDriver screenDriver)
        {
            string letterText;

            try {
                letterText = File.ReadAllText(screenDriver.Interpreter.LetterSetFile);
            }
            catch (Exception ex) {
                PrintError($"Failed to load letterset: {ex.Message}");
                return;
            }
            string[] letters = letterText.Replace("\r", "").Split('\n');

            // +1 because the last letter does not need a space after it.
            int lettersPerRow = (ScreenWidth - LettersetMargin + 1) / 3;

            int i = 0;

            while (i < letters.Length)
            {
                string currentLine = string.Empty;
                for (int j = 0; i < letters.Length && j < lettersPerRow; i++, j++)
                {
                    currentLine += letters[i].PadRight(3);
                }
                PrintLine(currentLine.TrimEnd());
            }
        }
示例#9
0
 public void CheckAfterConstruct()
 {
     this.driver = new MenuDriver ();
     Assert.AreEqual ("#", this.driver.Prompt);
     Assert.IsNotNull (this.driver.Current);
     Assert.AreEqual (0, this.driver.Current.ChildContexts.Count ());
     Assert.AreEqual (0, this.driver.Current.Commands.Count ());
 }
示例#10
0
 /// <summary>
 /// Copies the rotor keys and uses the same screen to state that the keys were copied.
 /// </summary>
 private static Screen CopyRotorKeysInternal(MenuDriver menuDriver)
 {
     TextCopy.Clipboard.SetText(string.Join(" ", menuDriver.Interpreter.GetRotorKeys()));
     Console.WriteLine();
     Console.Write("Rotor Keys Copied! Press Enter: ");
     Console.ReadLine();
     return(menuDriver.MainMenu);
 }
示例#11
0
 /// <summary>
 /// Prints the missing file list.
 /// </summary>
 private void PrintException(MenuDriver menuDriver)
 {
     Console.ForegroundColor = ConsoleColor.Yellow;
     foreach (string line in Exception.ToString().SplitLines())
     {
         PrintLine(line);
     }
     Console.ForegroundColor = ConsoleColor.Red;
 }
示例#12
0
        /// <summary>
        /// Prints the menu to the screen.
        /// </summary>
        protected virtual void PrintScreen(MenuDriver screenDriver)
        {
            Console.Clear();

            // Read the text for the menu
            string[] lines = ReadScreenFile(FilePath);
            foreach (string line in lines)
            {
                PrintLine(line);
            }
        }
示例#13
0
        /// <summary>
        /// Runs the menu and choice input.
        /// </summary>
        /// <returns>The choice index that was made.</returns>
        protected override MenuAction RunScreen(MenuDriver screenDriver)
        {
            if (Choices == null)
            {
                throw new ArgumentNullException("Menu has no Choices to execute!");
            }
            int index;

            PrintScreen(screenDriver);
            while (!ReadChoice(out index))
            {
                PrintScreen(screenDriver);
                PrintInvalidChoice();
            }
            return(Choices[index]);
        }
        /// <summary>
        /// Prints the letterset menu to the screen.
        /// </summary>
        protected override void PrintScreen(MenuDriver screenDriver)
        {
            Console.Clear();

            // Read the text for the menu
            string[] lines = ReadScreenFile(FilePath);
            foreach (string line in lines)
            {
                // Insert the letterset into the menu
                if (line.Trim() == LettersetMarker)
                {
                    PrintLetterset(screenDriver);
                }
                else
                {
                    PrintLine(line);
                }
            }
        }
示例#15
0
        /// <summary>
        /// Prints the menu to the screen.
        /// </summary>
        protected override void PrintScreen(MenuDriver menuDriver)
        {
            Console.Clear();

            // Read the text for the menu
            string[] lines = ReadScreenFile(FilePath);
            foreach (string line in lines)
            {
                // Check for token commands
                if (tokenCommands.TryGetValue(line.Trim(), out var printCommand))
                {
                    printCommand(menuDriver);
                }
                else
                {
                    PrintLine(line);
                }
            }
            Console.WriteLine();
        }
示例#16
0
 /// <summary>
 /// Prints the missing files menu to the screen.
 /// </summary>
 protected override void PrintScreen(MenuDriver menuDriver)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     if (!File.Exists(FilePath))
     {
         Console.Clear();
         // Missing MissingFilesMenu text file, print a hardcoded menu instead
         Console.WriteLine();
         PrintLine("Missing Files!");
         Console.WriteLine();
         PrintLine("The following files required for runtime are missing, including the file to display this error menu!");
         Console.WriteLine();
         PrintMissingFiles(menuDriver);
         Console.WriteLine();
     }
     else
     {
         base.PrintScreen(menuDriver);
     }
     Console.ResetColor();
     Console.WriteLine();
 }
示例#17
0
 /// <summary>
 /// Prints the missing files menu to the screen.
 /// </summary>
 protected override void PrintScreen(MenuDriver menuDriver)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     if (!File.Exists(FilePath))
     {
         Console.Clear();
         // Missing MissingFilesMenu text file, print a hardcoded menu instead
         Console.WriteLine();
         PrintLine("Unhandled Exception!");
         Console.WriteLine();
         PrintLine("The following error occurred while running the program:");
         Console.WriteLine();
         PrintException(menuDriver);
         Console.WriteLine();
     }
     else
     {
         base.PrintScreen(menuDriver);
     }
     Console.ResetColor();
     Console.WriteLine();
 }
示例#18
0
 public virtual MenuDriver Put(MenuDriver menuDriver)
 {
     _menuDriverCommands.ActiveUser = Models.ApiContext.ActiveUser;
     return(_menuDriverCommands.Put(menuDriver));
 }
示例#19
0
        public void Init()
        {
            this.driver = new MenuDriver ();

            var root_context = new MenuContext ("", "");
            root_context.AddCommand (new MenuCommand ("a", ""));
            root_context.AddCommand (new MenuCommand ("aaa", ""));
            root_context.AddCommand (new MenuCommand ("aab", ""));
            root_context.AddCommand (new MenuCommand ("ccc", ""));

            var context1 = new MenuContext ("context1",
                                            "",
                                            new MenuItemParameter ("param1", ""),
                                            new MenuItemParameter ("param2", ""));
            context1.AddCommand (new MenuCommand ("", ""));
            context1.AddCommand (new MenuCommand ("cmd", ""));

            var context2 = new MenuContext ("context2", "");
            context2.AddCommand (new MenuCommand ("cmd", ""));

            var context = new MenuContext ("context",
                                           "",
                                           new MenuItemParameter ("param1", ""),
                                           new MenuItemParameter ("param2", ""),
                                           new MenuItemParameter ("param3", ""));
            context.AddCommand (new MenuCommand ("cmd", ""));

            var context10 = new MenuContext ("context10", "", new MenuItemParameter ("param1", ""));
            context10.AddCommand (new MenuCommand ("cmd", ""));

            var sub_a = new MenuContext ("sub_A", "");
            sub_a.AddCommand (new MenuCommand ("command", ""));
            sub_a.AddCommand (new MenuCommand ("command1", ""));
            sub_a.AddCommand (new MenuCommand ("command2", ""));
            sub_a.AddCommand (new MenuCommand ("command12", ""));

            var sub_b = new MenuContext ("Sub_B", "");
            sub_b.AddCommand (new MenuCommand ("aaa", ""));
            sub_b.AddCommand (new MenuCommand ("bbb", ""));
            sub_b.AddCommand (new MenuCommand ("ccc", ""));

            var ctx = new MenuContext ("ctx", "", new MenuItemParameter ("param1", ""));
            ctx.AddCommand (new MenuCommand ("cmd", ""));

            var myctx = new MenuContext ("myctx",
                                         "",
                                         new MenuItemParameter ("param1", ""),
                                         new MenuItemParameter ("param2", ""),
                                         new MenuItemParameter ("param3", ""),
                                         new MenuItemParameter ("param4", ""));
            myctx.AddCommand (new MenuCommand ("cmd", ""));

            var context2__sub = new MenuContext ("sub", "", new MenuItemParameter ("param1", ""));

            var context__sub = new MenuContext ("sub", "", new MenuItemParameter ("param1", ""));
            context__sub.AddCommand (new MenuCommand ("cmd", ""));

            var sub_b__a = new MenuContext ("a", "");

            sub_b.AddSubContext (sub_b__a);
            context.AddSubContext (context__sub);
            context2.AddSubContext (context2__sub);
            context1.AddSubContext (sub_a);
            context1.AddSubContext (sub_b);
            context1.AddSubContext (ctx);
            context1.AddSubContext (myctx);
            root_context.AddSubContext (context);
            root_context.AddSubContext (context1);
            root_context.AddSubContext (context2);
            root_context.AddSubContext (context10);

            this.driver.SetRootContext (root_context);
        }
示例#20
0
        public void CheckSetRootContext_NotRoot_ToRoot()
        {
            this.driver = new MenuDriver ();

            var root = new MenuContext ("root", "");
            root.AddCommand (new MenuCommand ("cmd-1", ""));
            root.AddCommand (new MenuCommand ("cmd-2", ""));

            var sub = new MenuContext ("sub", "");
            sub.AddCommand (new MenuCommand ("cmd", ""));

            root.AddSubContext (sub);
            this.driver.SetRootContext (sub);
            this.driver.ToRoot ();

            Assert.AreEqual (sub, this.driver.Current);
        }
示例#21
0
 /// <summary>
 /// Prints the Enigma Machine status.
 /// </summary>
 private void PrintStatus(MenuDriver screenDriver)
 {
     screenDriver.Interpreter.PrintMachineStatus();
 }
示例#22
0
 /// <summary>
 /// Runs the screen.
 /// </summary>
 /// <returns>The action to perform after a screen choice.</returns>
 protected abstract MenuAction RunScreen(MenuDriver screenDriver);
示例#23
0
 /// <summary>
 /// Prints the Enigma Machine status.
 /// </summary>
 private void PrintStatus(MenuDriver menuDriver)
 {
     menuDriver.Interpreter.PrintMachineStatus();
 }
示例#24
0
 /// <summary>
 /// Publishes and runs the screen.
 /// </summary>
 /// <returns>The action to perform after a screen choice.</returns>
 public virtual MenuAction Publish(MenuDriver screenDriver)
 {
     PrintScreen(screenDriver);
     return(RunScreen(screenDriver));
 }