示例#1
0
        public string validate(CAEXDocument doc, string path)
        {
            // start validating aml

            string validation_result = "";

            ValidatorService service = ValidatorService.Register();

            var enumerator = service.ValidateAll(doc).GetEnumerator();

            while (enumerator.MoveNext())
            {
                validation_result += print_Error(enumerator.Current) + "//";
            }

            ValidatorService.UnRegister();
            // no Errors in mistake
            if (enumerator.Current == null)
            {
                println("No errors found", ConsoleColor.Green);
                return("No errors found");
            }

            return(validation_result);
        }
示例#2
0
        public string validate_and_repair(CAEXDocument doc, string path)
        {
            // start validating aml
            string validation_result = "";

            ValidatorService service = ValidatorService.Register();

            var  enumerator  = service.ValidateAll(doc).GetEnumerator();
            bool FileChanged = false;

            while (enumerator.MoveNext())
            {
                // option for printing all options
                //printALLData_for_ValidationElement(enumerator.Current);

                // print Error
                validation_result += print_Error(enumerator.Current);
                println("\nType yes for repairing option", ConsoleColor.Yellow);

                // ToDo: Implement Option to automatically repair all
                // try reparing
                if (Console.ReadLine().ToUpper().Trim() == "YES")
                {
                    //start reparing
                    FileChanged = true;
                    service.Repair(enumerator.Current);
                    println($"Repair results:  {enumerator.Current.RepairResult}", ConsoleColor.Cyan);

                    validation_result += $"|{enumerator.Current.RepairResult}";
                }
                validation_result += "//";
            }

            // no Errors in mistake
            if (enumerator.Current == null)
            {
                println("No errors found", ConsoleColor.Green);
                return("No errors found");
            }
            else if (FileChanged)
            {
                doc.SaveToFile(@path, true);
                println($"saved to file {path}", ConsoleColor.Cyan);
            }
            ValidatorService.UnRegister();

            return(validation_result);
        }
示例#3
0
        public void validate(CAEXDocument doc, string path, ref Options CurrentOptions)
        {
            // start validating aml
            try
            {
                ValidatorService service = ValidatorService.Register();

                var  enumerator  = service.ValidateAll(doc).GetEnumerator();
                bool FileChanged = false;

                while (enumerator.MoveNext())
                {
                    if (CurrentOptions.PrintAllVal)
                    {
                        printALLData_for_ValidationElement(enumerator.Current);
                    }

                    // print Error
                    print_Error(enumerator.Current);

                    if (!CurrentOptions.AutoRepair)
                    {
                        PrintHelper.println("Type yes to repair the error\n\n", ConsoleColor.Yellow);
                    }

                    // try reparing
                    if (CurrentOptions.AutoRepair || "YES".StartsWith(Console.ReadLine().ToUpper().Trim()))
                    {
                        // start reparing
                        FileChanged = true;
                        service.Repair(enumerator.Current);
                        PrintHelper.println($"Repair results:  {enumerator.Current.RepairResult}\n\n", ConsoleColor.Cyan);
                    }
                }

                // no Errors in mistake
                if (enumerator.Current == null)
                {
                    Console.WriteLine("\n\n");
                    PrintHelper.println("No errors found\n\n", ConsoleColor.Green);
                }
                else if (FileChanged)
                {
                    PrintHelper.println("Override file ? (Yes/No)\n\n", this.default_foreground);

                    // if override file
                    if ("YES".StartsWith(Console.ReadLine().ToUpper().Trim()))
                    {
                        doc.SaveToFile(path, true);

                        PrintHelper.println($"saved to file {path}\n\n", ConsoleColor.Cyan);
                    }
                    else
                    {
                        // save to new file
                        PrintHelper.printCentredLine("Please insert the Path for the File you want to save:\n\n");
                        string new_path = PrintHelper.GetDirectory();
                        // Only when User entered a valid Path
                        if (!String.IsNullOrEmpty(new_path))
                        {
                            PrintHelper.printCentredLine("What should be the Name of the Repaired AML-File?\n");
                            string FileName = Path.Combine(new_path, Console.ReadLine());
                            PrintHelper.printCentredLine("\n");
                            while (File.Exists(@FileName))
                            {
                                PrintHelper.printCentredLine("File already exists in Directory. Please Choose another name.\n");
                                FileName = Path.Combine(new_path, Console.ReadLine());
                                PrintHelper.printCentredLine("\n");
                            }
                            doc.SaveToFile(FileName, true);
                            PrintHelper.println($"saved to file {FileName}\n\n", ConsoleColor.Cyan);
                        }
                    }
                }
                ValidatorService.UnRegister();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.ToString() + "\n\n");
                PrintHelper.println("Couldn't Validate File\n\n", ConsoleColor.Red);
            }
            PrintHelper.Exit("Returning to Main Menu");
        }