public Engine(IMenuNavigator menuNavigator, IMenuOutputService menuOutputService, IConsoleManipulator consoleManipulator, IMenu menu) { this.menuNavigator = menuNavigator; this.consoleManipulator = consoleManipulator; this.menuOutputService = menuOutputService; this.menu = menu; }
public void ConfigureMenuItems(IMenuNavigator navigator, IList <MenuItem> menuItems) { menuItems.Add(new MenuItem("Enter TestMenu2", () => navigator.GoTo(new TestMenu2()))); menuItems.Add(new MenuItem("Enter TestMenu3", () => navigator.GoTo(new TestMenu3()))); menuItems.Add(new MenuItem("Add two numbers", () => AddNumbers(navigator))); menuItems.Add(new MenuItem("Exit", () => Environment.Exit(0))); }
private void AddNumbers(IMenuNavigator navigator) { Console.Clear(); int a = Prompt("Enter a number: "); int b = Prompt("Enter another number: "); Console.WriteLine($"The sum is {a + b}.\nPress Enter to continue..."); Console.ReadLine(); navigator.StayInCurrentMenu(); }
public void ConfigureMenuItems(IMenuNavigator navigator, IList <MenuItem> menuItems) { menuItems.Add(new MenuItem("Go back", () => navigator.GoBack())); }
public Menu(IMenuNavigator menuNavigator) { _MenuNavigator = menuNavigator; SubMenus = new List<IMenu>(); }
internal static void ShowSelectedIndexMenu(ICodeSearcherManager manager, ICodeSearcherIndex selectedIndex, ITextBasedUserInterface tui, IMenuNavigator nav) { string answer; do { tui.WriteLine($"ID:\t\t{selectedIndex.ID}"); tui.WriteLine($"Source:\t\t{selectedIndex.SourcePath}"); tui.Write($"File Extensions:\t\t"); foreach (var extension in selectedIndex.FileExtensions) { tui.Write($"{extension}, "); } tui.WriteLine(); tui.WriteLine($"Created on: {selectedIndex.CreatedTime.ToString("yyyy-MM-dd H:mm:ss")}"); tui.WriteLine("[1] Search in Index"); tui.WriteLine("[2] Delete Index"); tui.WriteLine("[3] Return to main menu"); tui.WriteLine("Please choose: "); answer = tui.ReadLine(); if (int.TryParse(answer, out int selection)) { if (1.Equals(selection)) { var logic = GetCodeSearcherLogicByIndex(selectedIndex); logic.SearchWithinExistingIndex( startCallback: () => { }, getSearchWord: () => { bool exit = ReadWordToSearch(out string word); word?.Trim(); return(word, exit); }, getMaximumNumberOfHits: () => { return(200); }, getHitsPerPage: () => { return(50); }, getExporter: () => { return(false, null); }, getSingleResultPrinter: () => { return(new WildcardResultPrinter()); }, finishedCallback: (timeSpan) => { Console.WriteLine("Press any key to continue"); Console.ReadKey(); }, endOfSearchCallback: () => { }, wildcardSearch: true ); } else if (2.Equals(selection)) { manager.DeleteIndex(selectedIndex.ID); tui.WriteLine($"Index with ID {selectedIndex.ID} deleted!"); } else if (3.Equals(selection)) { nav.GoToMainMenu(tui); } } } while (tui.ShouldLoop()); }
internal static void ShowAllIndexesMenu(ICodeSearcherManager manager, ITextBasedUserInterface tui, IMenuNavigator nav) { string answer; do { tui.Clear(); var indexes = manager.GetAllIndexes().ToList(); int count = 0; foreach (var index in indexes) { tui.WriteLine($"[{++count}] - ID {index.ID} - SourcePath {index.SourcePath}"); } if (indexes.Count == 0) { tui.WriteLine("There are currently no folders indexed!"); } tui.WriteLine($"[{++count}] Return to main menu"); tui.WriteLine("Please choose: "); answer = tui.ReadLine(); if (int.TryParse(answer, out int selection)) { if (indexes.Count > 0 && selection < count) { var selectedIndex = indexes[selection - 1]; nav.GoToSelectedIndexMenu(manager, selectedIndex, tui); } else { nav.GoToMainMenu(tui); } } } while (tui.ShouldLoop()); }
internal static void ShowCreateNewIndexMenu(ICodeSearcherManager manager, ITextBasedUserInterface tui, IMenuNavigator nav) { string answer; // Source path string sourcePath = null; do { tui.WriteLine("Please enter Path with Sources to Index:"); answer = tui.ReadLine(); if (Directory.Exists(answer)) { sourcePath = answer; tui.WriteLine($"Path with files to Index: {sourcePath}"); break; } tui.WriteLine("Path do not exist!"); } while (tui.ShouldLoop()); // file extensions var extensions = new List <String>(); tui.WriteLine("Please select file extension to index (form .ext1,.ext2)"); tui.WriteLine("Leave empty to use (.cs,.xml,.csproj) "); answer = tui.ReadLine(); if (string.IsNullOrWhiteSpace(answer)) { extensions.Add(".cs"); extensions.Add(".xml"); extensions.Add(".csproj"); } else { foreach (var extension in answer.Split(new[] { ',' })) { extensions.Add(extension); } } tui.WriteLine("Looking for files with extensions: "); extensions.ForEach((ext) => tui.WriteLine($"File Extension: {ext}")); if (!string.IsNullOrWhiteSpace(sourcePath) && extensions.Count > 0) { var id = manager.CreateIndex(sourcePath, extensions); tui.WriteLine($"New Index created with ID: {id}"); do { tui.WriteLine("[1] Search in new created index"); tui.WriteLine("[2] Back to main menu"); tui.WriteLine("Please choose: "); answer = tui.ReadLine(); if (int.TryParse(answer, out int selection)) { if (1.Equals(selection)) { var selectedIndex = manager.GetIndexById(id); nav.GoToSelectedIndexMenu(manager, selectedIndex, tui); } else if (2.Equals(selection)) { nav.GoToMainMenu(tui); } } } while (tui.ShouldLoop()); } }
internal static void ShowConsoleMainMenu(ICodeSearcherManager manager, ITextBasedUserInterface tui, IMenuNavigator nav) { do { tui.Clear(); tui.WriteLine("[1] Create New Index"); tui.WriteLine("[2] Show all Indexes"); tui.WriteLine("[3] Exit"); tui.WriteLine("Please choose: "); var answer = tui.ReadLine(); if (int.TryParse(answer, out int selection)) { if (1.Equals(selection)) //Create New Index { nav.GoToCreateNewIndexMenu(manager, tui); } else if (2.Equals(selection)) //Show All Indexes { nav.GoToShowAllIndexesMenu(manager, tui); } else if (3.Equals(selection)) //Exit { nav.ExitMenu(); } } } while (nav.MenuLoopActive()); }