public static void Main(string[] args) { try { string path = ""; bool ContinueMainMenu = true; Options CurrentOptions = new Options(); Validator ValidatorInstance = new Validator(); // First try Execution with Parameters if (!IsNullOrEmpty(args)) { Parser.Default.ParseArguments <CommandLineOptions>(args) .WithParsed(options => { if (!String.IsNullOrEmpty(options.path)) { if (!File.Exists(@options.path) || !(Path.GetExtension(@options.path).ToUpper() == ".AML")) { // Path is not Valid or File is not an AML File PrintHelper.Exit("Please provide a valid path"); ContinueMainMenu = false; } else if (!options.validate && !options.compress) { // No Defined Parameter given PrintHelper.Exit("Please provide either the Parameter --validate for validating or --compress for compressing"); ContinueMainMenu = false; } else if (options.validate && options.compress) { // Too much Parameters given PrintHelper.Exit("Please just provide just --validate or --compress"); ContinueMainMenu = false; } else { // Parameters are Valid if (options.validate) { path = options.path; //validate file Console.Clear(); CAEXDocument CDokument = LoadFile(ref path); Console.WriteLine(path); if (CDokument != null) { ValidatorInstance.validate(CDokument, path, ref CurrentOptions); } // Empty path for next Validation path = ""; } else if (options.compress) { AMLXCompress(@options.path); } } } }); } else { while (ContinueMainMenu) { PrintHelper.loopExplanation(); switch (Console.ReadLine().ToUpper()) { case "VALIDATE": case "1": //validate file Console.Clear(); CAEXDocument CDokument = LoadFile(ref path); Console.WriteLine(path); if (CDokument != null) { ValidatorInstance.validate(CDokument, path, ref CurrentOptions); } // Empty path for next Validation path = ""; break; case "COMPRESS": case "2": AMLXCompress(); break; case "DECOMPRESS": case "3": AMLXDeCompress(); break; case "OPTIONS": case "4": EditOptions(ref CurrentOptions); break; case "EXIT": case "QUIT": case "5": ContinueMainMenu = false; break; default: Console.WriteLine("Invalid Input \n"); continue; } } // Wait for 3 Seconds before closing, so the User can see the message PrintHelper.Exit("Thanks for using this Console Application. Exiting... "); } CurrentOptions.SaveOptions(); } catch (Exception e) { Console.WriteLine("Exception: " + e.ToString()); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("SCHWERER AUSNAHMEFEHLER. PROGRAMM WIRD IN 20 SEKUNDEN BEENDET"); System.Threading.Thread.Sleep(20000); } }
private static void EditOptions(ref Options CurrentOptions) { bool Continue = true; bool ExceptionHappend = false; do { PrintHelper.printOptions(CurrentOptions.AutoRepair, CurrentOptions.PrintAllVal); string SelectedOption = Console.ReadLine().ToUpper(); switch (SelectedOption) { case "": case "EXIT": case "QUIT": Continue = false; break; case "AUTOREPAIR": PrintHelper.printOptionAutoRepair(CurrentOptions.AutoRepair); try { CurrentOptions.AutoRepair = bool.Parse(Console.ReadLine()); } catch (Exception) { Console.Clear(); PrintHelper.printCentredLine(PrintHelper.line() + "\n\n"); PrintHelper.println("Invalid Value. Did not Change Config\n\n", ConsoleColor.Red); ExceptionHappend = true; } if (!ExceptionHappend) { Console.Clear(); PrintHelper.printCentredLine(PrintHelper.line() + "\n\n"); } Console.WriteLine("Do you want to Edit another Value? (Yes/No)\n"); PrintHelper.printCentredLine(PrintHelper.line() + "\n\n"); if (Console.ReadLine().ToUpper() == "NO") { Continue = false; } break; case "PRINTALLVAL": PrintHelper.printOptionPrintAllVal(CurrentOptions.PrintAllVal); try { CurrentOptions.PrintAllVal = bool.Parse(Console.ReadLine()); } catch (Exception) { Console.Clear(); PrintHelper.printCentredLine(PrintHelper.line() + "\n\n"); PrintHelper.println("Invalid Value. Did not Change Config\n\n", ConsoleColor.Red); ExceptionHappend = true; } if (!ExceptionHappend) { Console.Clear(); PrintHelper.printCentredLine(PrintHelper.line() + "\n\n"); } Console.WriteLine("Do you want to Edit another Value? (Yes/No)\n"); PrintHelper.printCentredLine(PrintHelper.line() + "\n\n"); if (Console.ReadLine().ToUpper() == "NO") { Continue = false; } break; default: Console.Clear(); PrintHelper.printCentredLine(PrintHelper.line() + "\n\n"); PrintHelper.printCentredLine("This Option does not Exist.\n\n"); PrintHelper.printCentredLine("Do you want to try again? (Yes/No)\n\n"); PrintHelper.printCentredLine(PrintHelper.line() + "\n\n"); if (Console.ReadLine().ToUpper() == "NO") { Continue = false; } break; } } while (Continue); Console.Clear(); PrintHelper.Exit("Redirecting to Main Menu"); }