/// <summary>
        /// Converts a DD input file and returns the resulting AML file as a string.
        /// </summary>
        /// <param name="inputFile">The path to the input file.</param>
        /// <param name="strictValidation">A flag which indicates if the DD should be checked for correctness.</param>
        /// <returns>The AML object serialized to a XML string.</returns>
        public static string Convert(string inputFile, bool strictValidation = true)
        {
            Util.RelativeFilePath = "/" + Path.GetFileName(inputFile);

            if (Util.RelativeFilePath.Contains(" "))
            {
                int index = Util.RelativeFilePath.IndexOf(" ");
                index += 1;
                String message = "The given DD-filename includes a space at position " + index + ". Please, rename your file and try again.";
                Logger?.Log(LogLevel.Error, message);
                throw new InvalidDataException(message);
            }

            Logger?.Log(LogLevel.Info, "Conversion to string started.");
            StartConversion(inputFile, Util.GetOutputFileName(inputFile), strictValidation);

            using (var stringwriter = new StringWriter())
            {
                if (CAEXVersion == 2)
                {
                    var serializer = new XmlSerializer(AmlObject.GetType());
                    serializer.Serialize(stringwriter, AmlObject);
                }
                else
                {
                    var serializer = new XmlSerializer(AmlObject3.GetType());
                    serializer.Serialize(stringwriter, AmlObject3);
                }

                return(stringwriter.ToString());
            }
        }
        /// <summary>
        /// Deserializes the translation table and the input file. Then it checks the input file for validity.
        /// After that it starts the conversion process.
        /// </summary>
        /// <param name="inputFile">The path to the input file.</param>
        /// <param name="outputFile">The path to the output file.</param>
        /// <param name="strictValidation">A flag which indicates if the DD should be checked for correctness.</param>
        private static void StartConversion(string inputFile, string outputFile, bool strictValidation)
        {
            if (strictValidation)
            {
                Util.CheckGsdFileForCorrectness(inputFile);
            }

            // Load the DD and the translation table XML document.
            GsdDocument = Util.LoadXmlDocument(inputFile);
            var translationTable = Util.LoadTranslationTable();

            if (translationTable.DocumentElement == null)
            {
                throw new XmlException("Could not load a XML file.");
            }

            // Add all conversion rules to a list.
            foreach (XmlNode node in translationTable.DocumentElement.ChildNodes)
            {
                TranslationRules.Add(node);
            }

            // Set FileName property of CAEX-element.
            if (CAEXVersion == 2)
            {
                AmlObject.GetType().GetProperties().FirstOrDefault(p => p.Name.Equals("FileName"))?.SetValue(AmlObject, new FileInfo(outputFile).Name);
                Logger?.Log(LogLevel.Debug, "Added the FileName attribute to the CAEXFile element.");

                Logger?.Log(LogLevel.Info, "Start the Handle function.");
                Handle(GsdDocument.DocumentElement, AmlObject);
                Logger?.Log(LogLevel.Info, "Successfully ended the Handle function.");
            }
            else
            {
                AmlObject3.GetType().GetProperties().FirstOrDefault(p => p.Name.Equals("FileName"))?.SetValue(AmlObject3, new FileInfo(outputFile).Name);
                Logger?.Log(LogLevel.Debug, "Added the FileName attribute to the CAEXFile element.");

                Logger?.Log(LogLevel.Info, "Start the Handle function.");
                Handle(GsdDocument.DocumentElement, AmlObject3);
                Logger?.Log(LogLevel.Info, "Successfully ended the Handle function.");
            }
        }
        /// <summary>
        /// Converts a DD input file and creates the .amlx package.
        /// </summary>
        /// <param name="inputFile">The path to the input file.</param>
        /// <param name="outputFile">The path to the output file.</param>
        /// <param name="overwriteFile">A flag which indicates if the file should be overwritten if it exists.</param>
        /// <param name="strictValidation">A flag which indicates if the DD should be checked for correctness.</param>
        public static void Convert(string inputFile, string outputFile, bool overwriteFile, bool strictValidation = true)
        {
            Util.RelativeFilePath = Path.GetFileName(inputFile);

            if (Util.RelativeFilePath.Contains(" "))
            {
                int index = Util.RelativeFilePath.IndexOf(" ");
                index += 1;
                String message = "The given DD-filename includes a space at position " + index + ". Please, rename your file and try again.";
                Logger?.Log(LogLevel.Error, message);
                throw new InvalidDataException(message);
            }

            Logger?.Log(LogLevel.Info, "Conversion to file started.");
            StartConversion(inputFile, outputFile, strictValidation);

            var serializer = new XmlSerializer(AmlObject.GetType());

            if (CAEXVersion != 2)
            {
                serializer = new XmlSerializer(AmlObject3.GetType());
            }
            var temporaryPath = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(outputFile) + ".aml");
            var inputPath     = Path.GetDirectoryName(inputFile);

            using (var textWriter = new StreamWriter(temporaryPath))
            {
                if (CAEXVersion == 2)
                {
                    serializer.Serialize(textWriter, AmlObject);
                }
                else
                {
                    serializer.Serialize(textWriter, AmlObject3);
                }
            }

            var resources = new List <string> {
                inputFile
            };

            if (Util.filetype != 3)
            {
                if (Util.IterateThroughGsdDocument(Util.CGraphicPath) != null)
                {
                    foreach (XmlNode xmlNode in Util.IterateThroughGsdDocument(Util.CGraphicPath).GetElementsByTagName(Util.CRealGraphicName))
                    {
                        var xmlNodeAttributes = xmlNode.Attributes;
                        if (xmlNodeAttributes.Count > 1)
                        {
                            var file = xmlNodeAttributes?[Util.CRealValueGraphicName].Value;
                            file += string.IsNullOrEmpty(Path.GetExtension(file)) ? ".bmp" : string.Empty;
                            resources.Add(Path.Combine(Path.GetDirectoryName(inputFile) ?? throw new InvalidOperationException("Invalid input file path."), file));
                        }
                    }
                }
            }
            else if (Util.filetype == 3)
            {
                var files = Directory.GetFiles(inputPath, "*.png", SearchOption.AllDirectories);
                if (files.Length < 1)
                {
                    files = Directory.GetFiles(inputPath, "*.bmp", SearchOption.AllDirectories);
                }
                var ImageFile = files[0];
                resources.Add(Path.Combine(Path.GetDirectoryName(inputFile) ?? throw new InvalidOperationException("Invalid input file path."), ImageFile));
            }

            AMLPackager.Compress(temporaryPath, outputFile, resources.ToArray(), overwriteFile);

            File.Delete(temporaryPath);
        }