Esempio n. 1
0
        public static void Compress(string sourceAMLFile, string file_target, List <string> OtherFiles)
        {
            try
            {
                PrintHelper.printCentredLine("What should be the Name of the Compressed AMLX-File?\n");
                string FileName = Path.Combine(file_target, Console.ReadLine());
                PrintHelper.printCentredLine("\n");
                while (File.Exists(@FileName))
                {
                    PrintHelper.printCentredLine("File already exists in Directory. Please Choose another name.\n");
                    FileName = Path.Combine(file_target, Console.ReadLine());
                    PrintHelper.printCentredLine("\n");
                }
                // creates empty AMLX / ZIP in target directory

                // Create AML Container
                var container = new Aml.Engine.AmlObjects.AutomationMLContainer(FileName, FileMode.Create);

                // Add Root-Element of AMLX-File
                var Root = container.AddRoot(sourceAMLFile, new Uri("/" + Path.GetFileName(sourceAMLFile), UriKind.Relative));

                //Add More Files if User wants more
                foreach (string NextFile in OtherFiles)
                {
                    if (Path.GetExtension(NextFile).ToUpper() == ".XSD")
                    {
                        container.AddCAEXSchema(NextFile, new Uri("/" + Path.GetFileName(NextFile), UriKind.Relative));
                    }
                    else
                    {
                        container.AddAnyContent(Root, NextFile, new Uri("/" + Path.GetFileName(NextFile), UriKind.Relative));
                    }
                }
                // Finally Close File
                container.Close();

                PrintHelper.printCentredLine("Sucessfully Created AMLX-File \n \n");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.ToString());
                PrintHelper.println("Could not Create AMLX-File", ConsoleColor.Red);
            }

            PrintHelper.Exit("Returning to Main Menu");
        }
Esempio n. 2
0
 public static void DeCompress(string file_path_src, string folder_path_target)
 {
     try
     {
         var container = new Aml.Engine.AmlObjects.AutomationMLContainer(file_path_src);
         container.ExtractAllFiles(folder_path_target);
         PrintHelper.printCentredLine("\nSuccessfully Extracted Files");
     }
     catch (IOException ex)
     {
         PrintHelper.println($"Error occured ( {ex})", ConsoleColor.Red);
         PrintHelper.println("\n Cannot find file..", ConsoleColor.Red);
     }
     catch (Exception e)
     {
         Console.WriteLine("Exception: " + e.ToString());
         PrintHelper.println("\nCould not Extract Files", ConsoleColor.Red);
     }
     PrintHelper.Exit("\n\nReturning to Main Menu");
 }
Esempio n. 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");
        }
        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");
        }