private static void AMLXCompress(string sourceAMLFile = "")
        {
            string        target, newFile;
            bool          AnotherFile;
            List <string> FilesToAdd = new List <string>();

            PrintHelper.DeCompressor_Choosage(true);

            if (String.IsNullOrEmpty(sourceAMLFile))
            {
                PrintHelper.printCentredLine("What is your Input AML-File?\n\n");
                sourceAMLFile = PrintHelper.GetFile("AML-File", "*.AML");
            }
            // User Aborted Compress
            if (String.IsNullOrEmpty(sourceAMLFile))
            {
                return;
            }

            PrintHelper.printCentredLine("Do you want to add another File?(Yes/No)\n\n");
            AnotherFile = Console.ReadLine().ToUpper() == "YES";
            while (AnotherFile)
            {
                newFile = PrintHelper.GetFile();
                if (!String.IsNullOrEmpty(newFile))
                {
                    if (FilesToAdd.Contains(newFile) || newFile == sourceAMLFile)
                    {
                        PrintHelper.printCentredLine("You already added this File");
                    }
                    else
                    {
                        FilesToAdd.Add(newFile);
                    }
                    PrintHelper.printCentredLine("Do you want to add more Files?(Yes/No)\n\n");
                    AnotherFile = Console.ReadLine().ToUpper() == "YES";
                }
                else
                {
                    break;
                }
            }

            PrintHelper.printCentredLine("Where do you want to save the Output?\n\n\n");
            target = PrintHelper.GetDirectory();
            if (String.IsNullOrEmpty(target))
            {
                return;
            }
            DeCompressor.Compress(sourceAMLFile, target, FilesToAdd);
        }
Exemple #2
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");
        }
 private static CAEXDocument LoadFile(ref string AMLFile)
 {
     PrintHelper.printCentredLine(PrintHelper.line() + "\n\n");
     if (String.IsNullOrEmpty(AMLFile))
     {
         // Ask for File
         PrintHelper.printCentredLine("Which File do you want to validate?\n");
         AMLFile = PrintHelper.GetFile("AML-File", "*.AML");
     }
     // look up input is actual file
     if (String.IsNullOrEmpty(AMLFile))
     {
         return(null);
     }
     else
     {
         return(CAEXDocument.LoadFromFile(AMLFile));
     }
 }
Exemple #4
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");
 }
        private static void AMLXDeCompress()
        {
            string src, target;

            PrintHelper.DeCompressor_Choosage(false);

            PrintHelper.printCentredLine("What is your Input?\n\n");
            src = PrintHelper.GetFile("AMLX-File", "*.AMLX");
            if (String.IsNullOrEmpty(src) || (Path.GetExtension(src).ToUpper() != ".AMLX"))
            {
                return;
            }

            PrintHelper.printCentredLine("Where do you want to save the Output?\n\n");
            target = PrintHelper.GetDirectory();
            if (String.IsNullOrEmpty(target))
            {
                return;
            }
            DeCompressor.DeCompress(src, target);
        }
Exemple #6
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");
        }
        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");
        }