private static bool DrawProcessGroups() { ProcessItemGroupController process = new ProcessItemGroupController(); if (process.ProcessGroups.Count == 0) { Console.WriteLine("Process Groups not found! You can add new Process Group - [A]"); return(false); } else { Console.WriteLine($"{new string('-', 15)}[Process-Groups]{new string('-', 15)}"); // [Processes] 11 - [Process-Groups] 16 int count = process.ProcessGroups.Count; for (int i = 0; i < count; i++) { Console.WriteLine($"-> {process.ProcessGroups[i].ToString()}"); } Console.WriteLine(new string('-', 46)); return(true); } }
private static void Main(string[] args) { Console.Title = Assembly.GetExecutingAssembly().GetName().Name; Wr(ConsoleColor.White, ConsoleColor.DarkYellow, true, " [ProcessManager] "); Jump(2); while (true) { Console.WriteLine($"\n{new string('-', 12)}[TODO]{new string('-', 12)}"); Console.WriteLine($"[E] -> Start Process(es)"); Console.WriteLine($"[G] -> Process Groups"); Console.WriteLine($"[F] -> Show list Processes"); Console.WriteLine($"[A] -> Add new Process"); Console.WriteLine($"[D] -> Remove Process"); Console.WriteLine($"[C] -> Change Process"); Console.WriteLine($"[H] -> Help"); Console.WriteLine($"[Q] -> Exid"); Console.WriteLine(new string ('-', 30)); Jump(1); Console.Write("-> "); ConsoleKey key = Console.ReadKey().Key; switch (key) { case ConsoleKey.E: // Start Process(es) #region Start Process(es) Console.Write(" [Start Process(es)]"); Jump(2); ProcessItemController processItemController = new ProcessItemController(); if (DrawProcesses()) { List <string> par = ParseParametrs("-> ", 1); foreach (string item in par) { processItemController.StartProcess(item.ToLower()); } Jump(1); } #endregion break; case ConsoleKey.G: // Process Groups #region Proces-Groups Console.Write(" [Process Groups]"); Jump(2); bool back = false; while (true) { Console.WriteLine($"{new string('-', 10)}[TODO]{new string('-', 10)}"); Console.WriteLine($"[E] -> Start Process Group(s)"); Console.WriteLine($"[F] -> Show list Process Groups"); Console.WriteLine($"[A] -> Add Process Group"); Console.WriteLine($"[D] -> Remove Process Group"); Console.WriteLine($"[C] -> Change Process Group"); Console.WriteLine($"[Q] -> Back"); Console.WriteLine(new string('-', 26)); Jump(1); Console.Write("-> "); ConsoleKey keyGroup = Console.ReadKey().Key; switch (keyGroup) { case ConsoleKey.E: // Start Process Groups #region Start-Process-Group Console.Write(" [Start Process Groups]"); Jump(2); ProcessItemGroupController groupController = new ProcessItemGroupController(); if (DrawProcessGroups()) { List <string> par = ParseParametrs("-> ", 1); foreach (string item in par) { groupController.StartProcessGroup(item); } Jump(1); } #endregion break; case ConsoleKey.F: // Show list Process Groups #region Show-list-Process-Group Console.Write(" [Show list Procrss Groups]"); Jump(2); DrawProcessGroups(); #endregion break; case ConsoleKey.A: // Add Process Group #region Add-Process-Group Console.Write(" [Add Process Group]"); Jump(2); ProcessItemGroupController groupController2 = new ProcessItemGroupController(); ProcessItemController processItemController2 = new ProcessItemController(); DrawProcessGroups(); int groupId = ParseInt32("-> ID: ", 1); string groupName = ParseString("-> Name: "); Jump(1); DrawProcesses(); List <string> groupList = ParseParametrs("-> Processes: ", 1); List <ProcessItem> processes = processItemController2.GetProcessesByNameOrID(groupList); try { ProcessItemGroup group = new ProcessItemGroup(groupId, groupName, processes); if (groupController2.AddProcessGroup(group)) { Console.WriteLine("Done!\n"); } else { Console.WriteLine("Error!\n"); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } #endregion break; case ConsoleKey.D: // Remove Process Group #region Remove-Process-Group Console.Write(" [Remove Process Group]"); Jump(2); ProcessItemGroupController groupController3 = new ProcessItemGroupController(); if (DrawProcessGroups()) { string parametr = ParseString("-> Name/ID: ", 1); try { ProcessItemGroup group = groupController3.GetProcessGroupByNameOrID(parametr.ToLower()); if (group != null) { if (groupController3.RemoveProcessGroup(group)) { Console.WriteLine("Done!\n"); } else { Console.WriteLine("Error!\n"); } } } catch (FormatException) { Console.WriteLine("Process group not found!"); } } #endregion break; case ConsoleKey.C: // Change Process Group #region Change-Process-Group Console.Write(" [Change Process Group]"); Jump(2); ProcessItemGroupController groupController4 = new ProcessItemGroupController(); ProcessItemController processItemController5 = new ProcessItemController(); if (DrawProcessGroups()) { string parametr = ParseString("-> Name/ID: ", 1); try { ProcessItemGroup group2 = groupController4.GetProcessGroupByNameOrID(parametr); if (group2 != null) { int? newId = ParseInt32("-> New ID: ", 1); string newName = ParseString("-> New Name: ", 0, true); Jump(1); DrawProcesses(); List <string> groupList2 = ParseParametrs("-> New Processes: ", 1); List <ProcessItem> processes2 = processItemController5.GetProcessesByNameOrID(groupList2); if (groupController4.ChangeProcessGroup(ref group2, newId == 0 ? null : newId, string.IsNullOrWhiteSpace(newName) ? null : newName, processes2)) { Console.WriteLine("Done!\n"); } else { Console.WriteLine("Error!\n"); } } } catch (FormatException) { Console.WriteLine("Process group not found!"); } } #endregion break; case ConsoleKey.Q: // Back back = true; break; default: Console.WriteLine(" - key not found!"); Jump(1); continue; } if (back) { Console.WriteLine(" - [Press Enter]"); break; } else { Console.ReadLine(); } } #endregion break; case ConsoleKey.F: // Show list Processes #region Show-list_Processes Console.Write(" [Show list Processes]"); Jump(2); DrawProcesses(); #endregion break; case ConsoleKey.A: // Add Process #region Add-Process Console.Write(" [Add Process]"); Jump(2); ProcessItemController p = new ProcessItemController(); DrawProcesses(); int id = ParseInt32("-> ID: ", 1); string name = ParseString("-> Name: "); string directory = ParseString("-> Directory: "); string description = ParseString("-> Description: ", 0, true); try { ProcessItem item = new ProcessItem(id, name, directory, description); if (p.AddProcess(item)) { Console.WriteLine("Done!\n"); } else { Console.WriteLine("Error!\n"); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } #endregion break; case ConsoleKey.D: // Remove Process #region Remove-Process Console.Write(" [Remove Process]"); Jump(2); ProcessItemController p2 = new ProcessItemController(); if (DrawProcesses()) { string parametr = ParseString("-> Name/ID: ", 1); try { ProcessItem item2 = p2.GetProcessByNameOrID(parametr.ToLower()); if (item2 != null) { if (p2.RemoveProcess(item2)) { Console.WriteLine("Done!\n"); } else { Console.WriteLine("Error!\n"); } } else { throw new FormatException(); } } catch (FormatException) { Console.WriteLine("Process not found!"); } } #endregion break; case ConsoleKey.C: // Change Process #region Change-Process Console.Write(" [Change Process]"); Jump(2); ProcessItemController p3 = new ProcessItemController(); if (DrawProcesses()) { string parametr2 = ParseString("-> Name/ID: ", 1); try { ProcessItem item3 = p3.GetProcessByNameOrID(parametr2.ToLower()); if (item3 != null) { int? id2 = ParseInt32("-> New ID: ", 1); string name2 = ParseString("-> New Name: ", 0, true); string directory2 = ParseString("-> New Directory: ", 0, true); string description2 = ParseString("-> New Description: ", 0, true); if (p3.ChangeProcess(ref item3, id2 == 0 ? null : id2, name2, directory2, description2)) { Console.WriteLine("Done!\n"); } else { Console.WriteLine("Error!\n"); } } else { throw new FormatException(); } } catch (FormatException) { Console.WriteLine("Process not found!"); } } #endregion break; case ConsoleKey.H: // Help #region Help Console.Write(" [Help]"); #endregion break; case ConsoleKey.Q: // Eqid Environment.Exit(0); break; default: Console.WriteLine(" - key not found!"); Jump(1); continue; } Console.ReadLine(); } }