/// <summary> /// Create an AMLX file with the aml file as string input /// </summary> /// <param name="caex">the complete aml file as a string</param> /// <param name="filename">the path to the original gsdml/iodd file</param> /// <returns>the result message as a string</returns> private string createAMLXFromString(string caex, string filename) { // create the CAEXDocument from byte string byte[] bytearray = System.Text.Encoding.Unicode.GetBytes(caex); CAEXDocument document = CAEXDocument.LoadFromBinary(bytearray); // create the amlx file string name = Path.GetFileNameWithoutExtension(filename); AutomationMLContainer amlx = new AutomationMLContainer(".\\modellingwizard\\" + name + ".amlx", FileMode.Create); // create the aml package path Uri partUri = PackUriHelper.CreatePartUri(new Uri("/" + name + "-root.aml", UriKind.Relative)); // create a temp aml file string path = Path.GetTempFileName(); document.SaveToFile(path, true); // copy the new aml into the package PackagePart root = amlx.AddRoot(path, partUri); // copy the original file into the package Uri gsdURI = new Uri(new FileInfo(filename).Name, UriKind.Relative); Uri gsdPartURI = PackUriHelper.CreatePartUri(gsdURI); amlx.AddAnyContent(root, filename, gsdPartURI); amlx.Save(); amlx.Close(); return("Sucessfully imported device!\nCreated File " + Path.GetFullPath(".\\modellingwizard\\" + name + ".amlx")); }
/// <summary> /// Creates an AMLX package. /// </summary> /// <param name="inputPath">The path to the IODD file.</param> /// <param name="outputPath">The path to the AML file.</param> /// <param name="amlxOutputPath">The output path for the AMLX package.</param> public void CreatePackage(string inputPath, string outputPath, string amlxOutputPath) { PathToIodd = inputPath; PathToAml = outputPath; var pathToSourceFolder = Directory.GetParent(inputPath); // Set path for AMLX package to IODD file path if amlxOutoutPath is null. var pathToAmlxPackage = amlxOutputPath ?? CreateAmlxPackageName(PathToIodd); var files = pathToSourceFolder.GetFiles(); // Deletes an existing AMLX package which would cause errors. if (File.Exists(pathToAmlxPackage)) { File.Delete(pathToAmlxPackage); } // Gets all paths of images needed for the AMLX package. foreach (var file in files) { if (file.Extension.Contains("jpeg") || file.Extension.Contains("jpg") || file.Extension.Contains("png")) { PathsToImages.Add(file.FullName); } } // Creates a new AutomationMLContainer using (var container = new AutomationMLContainer(pathToAmlxPackage)) { // Sets the root of the container to the AML file, adds the schema, the iodd and the icons. var root = container.AddRoot(PathToAml, new Uri("/" + Path.GetFileName(PathToAml), UriKind.RelativeOrAbsolute)); container.AddCAEXSchema(Assembly.GetExecutingAssembly().GetManifestResourceStream("Iodd2AmlConverter.Library.Resources.CAEX_ClassModel_V2.15.xsd"), new Uri("/CAEX_ClassModel_V2.15.xsd", UriKind.RelativeOrAbsolute)); foreach (var pathToImage in PathsToImages) { container.AddAnyContent(root, pathToImage, new Uri("/" + Path.GetFileName(pathToImage), UriKind.RelativeOrAbsolute)); } container.AddAnyContent(root, PathToIodd, new Uri("/" + Path.GetFileName(PathToIodd), UriKind.RelativeOrAbsolute)); container.Close(); } }