/// <summary> /// build a topology, starting from the root element. /// </summary> /// <param name="amlDocument">The aml document.</param> private static void C_BuildATopology(CAEXDocument amlDocument) { // get the object from the document using the assigned ID var amlObject = amlDocument.FindByID("ROOT") as InternalElementType; // the topology should consist of 4 levels var level = 4; AMLObjectChildren.AddElementChildren(amlObject, ref level); }
private InstanceHierarchyType getInstanceHierarchy(string indexer, CAEXDocument caex) { var hierarchy = caex.CAEXFile.InstanceHierarchy[indexer]; if (hierarchy == null) { throw new Exception($"Cannot find InstanceHierarchyType {indexer}"); } return(hierarchy); }
public MainWindow() { InitializeComponent(); AMLToolkit.ViewModel.AMLLayout.DefaultLayout.ShowClassReference = false; AMLToolkit.ViewModel.AMLLayout.DefaultLayout.ShowRoleReference = false; var path = System.IO.Path.Combine(Environment.CurrentDirectory, @"TestFile/Test1.aml"); var doc = CAEXDocument.LoadFromFile(path); undoRedoManager = new AMLToolkit.Tools.AMLUndoRedoManager(); this.IHTree.TreeViewModel = new AMLToolkit.ViewModel.AMLTreeViewModel((XmlElement)doc.CAEXFile.Node, AMLToolkit.ViewModel.AMLTreeViewTemplate.CompleteInstanceHierarchyTree); this.ICTree.TreeViewModel = new AMLToolkit.ViewModel.AMLTreeViewModel((XmlElement)doc.CAEXFile.Node, AMLToolkit.ViewModel.AMLTreeViewTemplate.InterfaceClassLibTree); this.SUCTree.TreeViewModel = new AMLToolkit.ViewModel.AMLTreeViewModel((XmlElement)doc.CAEXFile.Node, AMLToolkit.ViewModel.AMLTreeViewTemplate.CompleteSystemUnitClassLibTree); this.RCTree.TreeViewModel = new AMLToolkit.ViewModel.AMLTreeViewModel((XmlElement)doc.CAEXFile.Node, AMLToolkit.ViewModel.AMLTreeViewTemplate.ExtendedRoleClassLibTree); // test layout options System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(testFilter); dispatcherTimer.Interval = new TimeSpan(0, 0, 12); //dispatcherTimer.Start(); // test layout options System.Windows.Threading.DispatcherTimer dispatcherTimer2 = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer2.Tick += new EventHandler(testReferenceDisplay); dispatcherTimer2.Interval = new TimeSpan(0, 0, 7); //dispatcherTimer2.Start(); this.IHTree.AllowDrop = true; this.SUCTree.AllowDrop = true; AMLToolkit.ViewModel.AMLTreeViewModel.CanDragDropPredicate CanDragDrop = delegate(AMLTreeViewModel tree, AMLNodeViewModel source, AMLNodeViewModel target) { return((source.CAEXNode.Name == CAEX_ClassModel.CAEX_CLASSModel_TagNames.INTERNALELEMENT_STRING && target.CAEXNode.Name == CAEX_ClassModel.CAEX_CLASSModel_TagNames.INTERNALELEMENT_STRING) || (source.CAEXNode.Name == CAEX_ClassModel.CAEX_CLASSModel_TagNames.INTERNALELEMENT_STRING && target.CAEXNode.Name == CAEX_ClassModel.CAEX_CLASSModel_TagNames.SYSTEMUNITCLASS_STRING) || (source.CAEXNode.Name == CAEX_ClassModel.CAEX_CLASSModel_TagNames.SYSTEMUNITCLASS_STRING && target.CAEXNode.Name == CAEX_ClassModel.CAEX_CLASSModel_TagNames.SYSTEMUNITCLASS_STRING)); }; AMLToolkit.ViewModel.AMLTreeViewModel.DoDragDropAction DoDragDrop = delegate(AMLTreeViewModel tree, AMLNodeViewModel source, AMLNodeViewModel target) { AMLInsertCopyFromSourceCommand.ExcuteAndInsertCommand(undoRedoManager, target, source); }; this.IHTree.TreeViewModel.CanDragDrop = CanDragDrop; this.IHTree.TreeViewModel.DoDragDrop = DoDragDrop; this.SUCTree.TreeViewModel.DoDragDrop = DoDragDrop; this.SUCTree.TreeViewModel.CanDragDrop = CanDragDrop; }
private void loadDocument() { // load a document var caexDocument = CAEXDocument.LoadFromFile("myfile.aml"); // get the InstanceHierarchy var myIH = caexDocument.CAEXFile.InstanceHierarchy[0]; // add more content myIH.InternalElement.Append("Ie1"); }
/// <summary> /// Save CAEX-File /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_SaveCAEX_Click(object sender, EventArgs e) { myErrorListBox.Items.Clear(); saveFileDialog.Filter = @"AML files|*.aml"; if (saveFileDialog.ShowDialog() != DialogResult.OK) { return; } _fileName = saveFileDialog.FileName; _myDoc.SaveToFile(_fileName, true); _myDoc = CAEXDocument.LoadFromFile(_fileName); }
/// <summary> /// Utility method to get the Document URI. /// </summary> internal static Uri DocumentUri(CAEXDocument document) { var documentPath = document.CAEXFile.GetFileNamePath(); var documentDirectory = Path.GetDirectoryName(documentPath); Uri.TryCreate(documentDirectory, UriKind.Absolute, out var documentBaseURI); if (documentBaseURI == null) { MessageBox.Show(string.Format("Could not create a Document URI {0}", documentDirectory)); } return(documentBaseURI); }
/// <summary> /// Loads a CAEX file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_OpenCAEX_Click(object sender, EventArgs e) { myErrorListBox.Items.Clear(); if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } _myDoc = null; CAEXTreeView.Nodes.Clear(); _fileName = openFileDialog.FileName; lbl_FileName.Text = _fileName; _myDoc = CAEXDocument.LoadFromFile(_fileName); ShowMyTree(CAEXTreeView, _myDoc); }
public void Test1() { const string asm1Name = "Slider"; const string asm2Name = "Bed Assembly"; const string part1Name = "Base"; const string part2Name = "Bed"; const string part3Name = "Flange"; var doc = new AmlDocument(); var project = new ProjectViewModel(doc); doc.CaexDocument.CAEXFile.InstanceHierarchy.Insert(project.CaexObject as InstanceHierarchyType); var asm1 = new AssemblyViewModel(doc) { Name = asm1Name }; var asm2 = new AssemblyViewModel(doc) { Name = asm2Name }; var part1 = new PartViewModel(doc) { Name = part1Name }; var part2 = new PartViewModel(doc) { Name = part2Name }; var part3 = new PartViewModel(doc) { Name = part3Name }; project.Parts.Add(asm1); asm1.Parts.Add(asm2); asm1.Parts.Add(part1); asm2.Parts.Add(part2); asm2.Parts.Add(part3); var stream = doc.CaexDocument.SaveToStream(true); var caex = CAEXDocument.LoadFromStream(stream); var doc2 = new AmlDocument(caex); var ih = doc2.CaexDocument.CAEXFile.InstanceHierarchy.First; var vm = new ProjectViewModel(ih, doc2); }
/// <summary> /// Handling the event of the open CAEX button /// </summary> private void _BopenCAEX_Click(object sender, EventArgs e) { if (_openFile.ShowDialog() == DialogResult.OK) { this._CTV.PathSeparator = "/"; this.myDoc = null; this._CTV.Nodes.Clear(); this.fileName = _openFile.FileName; // Gets or sets a string containing the file name selected in the file dialog box. _FileName.Text = fileName; myDoc = CAEXDocument.LoadFromFile(fileName); this.myShowTree(_CTV, myDoc); this._CTV.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(GenerateEnable); this.Open(); } }
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); }
private InstanceHierarchyType searchForElement(string element, CAEXDocument caex) { foreach (var instanceHierarchy in caex.CAEXFile.InstanceHierarchy) { if (instanceHierarchy.InternalElement.ElementName == element) { return(instanceHierarchy); } //foreach(var internalElement in instanceHierarchy.InternalElement) { //if(internalElement == element) { // return internalElement.instanceHierarchy; // dont know, if possible? // } //} } throw new Exception("element not found!"); }
private static void ShowResult(CAEXDocument document, string method) { Console.Write($"Show Result of {method}"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write($" Y/N?"); var answer = Console.ReadKey().KeyChar; if (answer == 'y' || answer == 'Y') { document.SaveToFile($"{method}.aml", true); ShowFile(method, document); System.Threading.Thread.Sleep(5000); } Console.ResetColor(); Console.WriteLine(); }
internal void Open(string filePath) { var template = new HashSet <string> (AMLTreeViewTemplate.CompleteInstanceHierarchyTree .Concat(AMLTreeViewTemplate.CompleteSystemUnitClassLibTree) .Concat(AMLTreeViewTemplate.ExtendedRoleClassLibTree) .Concat(AMLTreeViewTemplate.InterfaceClassLibTree) .Concat(AMLTreeViewTemplate.AttributeTypeLibTree).Distinct()); AMLDocumentTreeViewModel?.ClearAll(); Document = null; FilePath = filePath; Document = CAEXDocument.LoadFromFile(filePath); AMLDocumentTreeViewModel = new AMLTreeViewModel(Document.CAEXFile.Node, template); PropagateFileOpenEventToPlugins(FilePath); }
private void AddStandardRoleClassReference() { var caexDocument = CAEXDocument.New_CAEXDocument(); // adds the base libraries to the document AutomationMLInterfaceClassLibType.InterfaceClassLib(caexDocument); AutomationMLBaseRoleClassLibType.RoleClassLib(caexDocument); // add an InstanceHierarchy to the ROOT CAEXFile element var myIH = caexDocument.CAEXFile.New_InstanceHierarchy("myIH"); // add an InternalElement var ie = myIH.InternalElement.Append("ie"); // assign the AutomationMLBaseRole ie.AddRoleClassReference(AutomationMLBaseRoleClassLib.AutomationMLBaseRole); }
public void SerDesTest() { var provider = new AmlDocument(); var expected = new KinematicJointValue(provider) { Name = "foobar", Value = 1d, DefaultValue = 3d, Minimum = -10d, Maximum = 20d }; var value = new KinematicJointValue((AttributeType)expected.CaexObject, provider); Assert.Equal(expected.Name, value.Name); Assert.Equal(expected.Value, value.Value); Assert.Equal(expected.Minimum, value.Minimum); Assert.Equal(expected.Maximum, value.Maximum); var ie = provider.CaexDocument.Create <InternalElementType>(); var ih = provider.CaexDocument.Create <InstanceHierarchyType>(); ie.Attribute.Insert((AttributeType)expected.CaexObject); ih.InternalElement.Insert(ie); provider.CaexDocument.CAEXFile.InstanceHierarchy.Insert(ih); var fullPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); provider.CaexDocument.SaveToFile(fullPath, true); var d = CAEXDocument.LoadFromFile(fullPath); var p = new AmlDocument(d); File.Delete(fullPath); value = new KinematicJointValue(d.CAEXFile.InstanceHierarchy.First().InternalElement.First().Attribute.First(), provider); Assert.Equal(expected.Name, value.Name); Assert.Equal(expected.Value, value.Value); Assert.Equal(expected.Minimum, value.Minimum); Assert.Equal(expected.Maximum, value.Maximum); }
/// <summary> /// The <see cref="OpenFileCommand"/> Execution Action. /// </summary> private void OpenFileCommandExecute(object parameter) { OpenFileDialog ofd = new OpenFileDialog { Title = "Open AML File", DefaultExt = ".aml", Filter = "AML Files (*.aml)|*.aml" }; var result = ofd.ShowDialog(); if (result.HasValue && (bool)result) { FilePath = ofd.FileName; Document = CAEXDocument.LoadFromFile(ofd.FileName); AMLDocumentTreeViewModel = new AMLTreeViewModel(Document.CAEXFile.Node, AMLTreeViewTemplate.CompleteInstanceHierarchyTree); PropagateFileOpenEventToPlugins(FilePath); } }
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)); } }
/// <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; if (name.Contains(".amlx")) { amlx = new AutomationMLContainer(".\\modellingwizard\\" + name, FileMode.Create); } else { 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")); }
public void LoadStream( MtpVisualObjectLib objectLib, IMtpDataSourceFactoryOpcUa dataSourceFactory, MtpDataSourceOpcUaPreLoadInfo preLoadInfo, MtpDataSourceSubscriber subscriber, Stream stream, MtpSymbolMapRecordList makeUpConfigRecs = null) { // check if (stream == null) { return; } // try open file var doc = CAEXDocument.LoadFromStream(stream); if (doc == null) { return; } // load dynamic Instances var refIdToDynamicInstance = MtpAmlHelper.FindAllDynamicInstances(doc.CAEXFile); // load data sources if (dataSourceFactory != null) { MtpAmlHelper.CreateDataSources(dataSourceFactory, preLoadInfo, doc.CAEXFile); } // index pictures var pl = MtpAmlHelper.FindAllMtpPictures(doc.CAEXFile); foreach (var pi in pl) { var p = MtpPicture.ParsePicture(objectLib, subscriber, refIdToDynamicInstance, pi.Item2, makeUpConfigRecs); if (p != null) { this.PictureCollection.Add(pi.Item1, p); } } }
/// <summary> /// <see href="https://github.com/AutomationML/AMLEngine2.1/wiki/Mirrors#Attribute-Mirrors"></see> /// </summary> /// <param name="document"></param> internal static void UsingAttributeMirrors(CAEXDocument document) { var instanceHierarchy = document.CAEXFile.InstanceHierarchy.Append("ih1"); var element1 = instanceHierarchy.InternalElement.Append("element1"); var attribute1 = element1.SetAttributeValue("attribute1", 1.0); // creates an attribute mirror from 'attribute1' and inserts the mirror to element1 // as the first element element1.Insert(attribute1.CreateMirror()); // the attribute1 is a master attribute, because it has a mirror attribute Debug.Assert(attribute1.IsMaster()); // the first attribute is a mirror attribute var mirrorAttribute = element1.Attribute[0]; // the name of the mirror has to be different, because it is inserted // in the same attribute collection as the master mirrorAttribute.Name = "mirror"; Debug.Assert(mirrorAttribute.IsMirror); // the master of the mirror is attribute1 Debug.Assert(mirrorAttribute.Master == attribute1); // the reference to the master is stored in the RefAttributeType property; // the reference is set to the CAEXPath of the master Debug.Assert(mirrorAttribute.RefAttributeType == attribute1.CAEXPath()); // gets the attribute value of the master as a string representation var aValue = mirrorAttribute.Master.Value; Debug.Assert(double.Parse(aValue) == 1.0); // gets the decoded value, according to its attribute data type var dValue = mirrorAttribute.Master.AttributeValue; Debug.Assert(dValue is double); // sets a new value using the encoding property mirrorAttribute.Master.AttributeValue = 4.0; }
/// <summary> /// <see href="https://github.com/AutomationML/AMLEngine2.1/wiki/Relations#externalinterface-creation-by-class-instantiation"/> /// </summary> /// <param name="document"></param> internal static void CreateInterfaceClassInstance(CAEXDocument document) { // add a new logistic project as an Instance Hierarchy var logisticsProject = document.CAEXFile.InstanceHierarchy.Append("LogisticsProject"); // import the standard AutomationML Interfaceclass library into the document var interfaceClassLib = AutomationMLInterfaceClassLibType.InterfaceClassLib(document); // add a distributing switch to your project var dswitch = logisticsProject.New_InternalElement("distributing switch"); // the switch should contain one input and two outputs // the standard interface class 'order' is used to model the distribution var order = document.FindByPath(AutomationMLInterfaceClassLib.Order) as InterfaceFamilyType; if (order == null) { throw new Exception("The standard interface class 'Order' doesnot exist"); } // create three new class instances (ExternalInterface), // the instances contain the interface class attribute 'Direction' var input = order.CreateClassInstance("in"); var out1 = order.CreateClassInstance("out1"); var out2 = order.CreateClassInstance("out2"); // the direction value is needed, because CAEX doesnot // provide directed instance to instance relations input.Attribute["Direction"].Value = "In"; out1.Attribute["Direction"].Value = "Out"; out2.Attribute["Direction"].Value = "Out"; // the direction attribute is defined in the standard attribute type library // the possible values are defined in a nominal value constraint // you can ensure, that the assigned values are in the nominal value collection // see the attrubte examples in the wiki for details. dswitch.Insert(input); dswitch.Insert(out1, asFirst: false); dswitch.Insert(out2, asFirst: false); }
/// <summary> /// <see href="https://github.com/AutomationML/AMLEngine2.1/wiki/Basic#Insertion-of-Elements"/> /// </summary> /// <param name="document"></param> internal static void InsertElements(CAEXDocument document) { // adding a Class library and a class with element and attribute var systemUnitClassLib = document.CAEXFile.SystemUnitClassLib.Append("Slib"); var suc1 = systemUnitClassLib.SystemUnitClass.Append("s1"); var element = suc1.InternalElement.Append("element1"); var attribute = suc1.Attribute.Append("attribute1"); // insert an element copy to the class; the element is automatically // appended to the InternalElement collection of the class. suc1.Insert(element.Copy("afterElement1"), asFirst: false); // inserts a copy of the element before the element. element.InsertBefore((InternalElementType)element.Copy("beforeElement1")); // inserts a copy of the element at position 1 of the InternalElement collection // (it becomes the 2nd. element in the collection) suc1.InternalElement.InsertAt(1, (InternalElementType)element.Copy("atPosition1")); // inserts an attribute copy at the first position suc1.Insert(attribute.Copy("firstAttribute"), asFirst: true); }
/// <summary> /// <see href="https://github.com/AutomationML/AMLEngine2.1/wiki/Basic#Copying-Elements"/> /// </summary> /// <param name="document"></param> internal static void CopyElements(CAEXDocument document) { // adding a Class library and some classes organized in a class tree var systemUnitClassLib = document.CAEXFile.SystemUnitClassLib.Append("SLib"); var suc1 = systemUnitClassLib.SystemUnitClass.Append("s1"); var suc2 = suc1.SystemUnitClass.Append("s2"); suc2.SystemUnitClass.Append("s3").BaseClass = suc2; // adding some elements to the class suc1.InternalElement.Append("ie1"); // copies the full class tree including the elements var suc1Tree = suc1.Copy(deepCopy: true, assignNewIDs: true, includeSubClasses: true); ((CAEXObject)suc1Tree).Name = "s1_TreeCopy"; systemUnitClassLib.Insert(suc1Tree, false); // copies the full class tree including the elements and redirect class reference _ = suc1.CopyTreeAndChangeReferences(systemUnitClassLib, "s1_TreeCopyWithRedirectedRelations"); // change the name of suc2 and update the references suc2.ChangeNameAndReferences("s2_source"); // copies only suc1, omitting the nested classes var suc1Class = suc1.Copy(deepCopy: true, true, false); ((CAEXObject)suc1Class).Name = "s1_ClassCopy"; systemUnitClassLib.Insert(suc1Class, false); // copies only suc1, omitting the nested classes and elements var suc1ClassWithoutElements = suc1.Copy(deepCopy: false, true, false); ((CAEXObject)suc1ClassWithoutElements).Name = "s1_ClassOnlyCopy"; systemUnitClassLib.Insert(suc1ClassWithoutElements, false); }
private static void ShowFile(string method, CAEXDocument document) { if (_editorChannel == null) { CreateCommunication(); } _editorChannel.SendNote($"{method} - example."); _editorChannel.SendCommand(EditorComandEnum.OpenDocumentCommand, System.IO.Path.GetFullPath($"{method}.aml")); string caexPath = null; foreach (var lib in document.CAEXFile) { caexPath = lib.CAEXPath(); if (caexPath != null) { _editorChannel.SendCommand(EditorComandEnum.SetActiveHierarchyCommand, CAEX_CLASSModel_TagNames.SYSTEMUNITCLASSLIB_STRING); // _editorChannel.SendCommand(EditorComandEnum.SelectByPathCommand, caexPath); _editorChannel.SendCommand(EditorComandEnum.ExpandByPathCommand, caexPath); } } }
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"); }
/// <summary> /// Create the AMLX File with the correct AML File and optional pictures /// </summary> /// <param name="device">The device which will be created</param> /// <param name="isEdit">true if an amlx file get update, false if a new file will be created</param> /// <returns></returns> public string CreateDevice(MWDevice device, bool isEdit) { CAEXDocument document = null; AutomationMLContainer amlx = null; // Init final .amlx Filepath //first of all create a folder on "Vendor Name" string vendorCompanyName = device.vendorName; string vendorCompanyNameFilePath = ""; string fileName = device.fileName; string amlFilePath = System.IO.Path.Combine(device.filepath, fileName + ".amlx"); FileInfo file = new FileInfo(amlFilePath); // Create directory if it's not existing file.Directory.Create(); // Init CAEX Document if (isEdit) { // Load the amlx file amlx = new AutomationMLContainer(amlFilePath, FileMode.Open); IEnumerable <PackagePart> rootParts = amlx.GetPartsByRelationShipType(AutomationMLContainer.RelationshipType.Root); // We expect the aml to only have one root part if (rootParts.First() != null) { PackagePart part = rootParts.First(); // load the aml file as an CAEX document document = CAEXDocument.LoadFromStream(part.GetStream()); } else { // the amlx contains no aml file document = CAEXDocument.New_CAEXDocument(); } } else { // create a new CAEX document document = CAEXDocument.New_CAEXDocument(); try { amlx = new AutomationMLContainer(amlFilePath, FileMode.Create); } catch (Exception) {} } // Init the default Libs AutomationMLBaseRoleClassLibType.RoleClassLib(document); AutomationMLInterfaceClassLibType.InterfaceClassLib(document); var structureRoleFamilyType = AutomationMLBaseRoleClassLibType.RoleClassLib(document).Structure; SystemUnitFamilyType systemUnitClass = null; // Create the SystemUnitClass for our device if (!isEdit) { systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(device.deviceName); device.listWithURIConvertedToString = new List <AttachablesDataGridViewParameters>(); foreach (AttachablesDataGridViewParameters eachparameter in device.dataGridAttachablesParametrsList) { if (eachparameter.FilePath.Contains("https://") || eachparameter.FilePath.Contains("http://") || eachparameter.FilePath.Contains("www") || eachparameter.FilePath.Contains("WWW")) { interneturl(eachparameter.FilePath, eachparameter.ElementName.ToString(), "ExternalDataConnector", systemUnitClass); } else { Boolean myBool; Boolean.TryParse(eachparameter.AddToFile, out myBool); if (myBool == true) { } Uri eachUri = null; AttachablesDataGridViewParameters par = new AttachablesDataGridViewParameters(); eachUri = createPictureRef(eachparameter.FilePath, eachparameter.ElementName.ToString(), "ExternalDataConnector", systemUnitClass); par.ElementName = eachUri.ToString(); par.FilePath = eachparameter.FilePath; device.listWithURIConvertedToString.Add(par); } } foreach (var pair in device.DictionaryForRoleClassofComponent) { SupportedRoleClassType supportedRoleClass = null; Match numberfromElectricalConnectorType = Regex.Match(pair.Key.ToString(), @"\((\d+)\)"); string initialnumberbetweenparanthesisofElectricalConnectorType = numberfromElectricalConnectorType.Groups[1].Value; // string stringinparanthesis = Regex.Match(pair.Key.ToString(), @"\{(\d+)\}").Groups[1].Value; string supportedRoleClassFromDictionary = Regex.Replace(pair.Key.ToString(), @"\(.+?\)", ""); supportedRoleClassFromDictionary = Regex.Replace(supportedRoleClassFromDictionary, @"\{.+?\}", ""); var SRC = systemUnitClass.SupportedRoleClass.Append(); var attributesOfSystemUnitClass = systemUnitClass.Attribute; foreach (var valueList in pair.Value) { foreach (var item in valueList) { if (item.AttributePath.Contains("/") || item.AttributePath.Contains(".")) { int count = 2; int counter = 0; Stack <char> stack = new Stack <char>(); string searchAttributeName = item.AttributePath.Substring(0, item.AttributePath.Length - item.Name.Length); foreach (var character in searchAttributeName.Reverse()) { if (!char.IsLetterOrDigit(character)) { counter++; if (counter == count) { break; } } if (char.IsLetterOrDigit(character)) { stack.Push(character); } } string finalAttributeName = new string(stack.ToArray()); foreach (var attribute in systemUnitClass.Attribute) { if (attribute.Name == finalAttributeName) { var eachattribute = attribute.Attribute.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } SRC.RefRoleClassPath = item.SupportesRoleClassType; } if (attribute.Attribute.Exists) { SearchForAttributesInsideAttributesofAutomationComponent(finalAttributeName, attribute, item, SRC); } } } else { var eachattribute = attributesOfSystemUnitClass.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } SRC.RefRoleClassPath = item.SupportesRoleClassType; } } } foreach (var pairofList in device.DictionaryForExternalInterfacesUnderRoleClassofComponent) { Match numberfromElectricalConnectorPins = Regex.Match(pairofList.Key.ToString(), @"\((\d+)\)"); string initialnumberbetweenparanthesisElectricalConnectorPins = numberfromElectricalConnectorPins.Groups[1].Value; string electricalConnectorPinName = Regex.Replace(pairofList.Key.ToString(), @"\(.*?\)", ""); electricalConnectorPinName = Regex.Replace(electricalConnectorPinName, @"\{.*?\}", ""); electricalConnectorPinName = electricalConnectorPinName.Replace(supportedRoleClassFromDictionary, ""); /*if (initialnumberbetweenparanthesisofElectricalConnectorType == initialnumberbetweenparanthesisElectricalConnectorPins) * { * supportedRoleClass.RoleReference = pairofList.Key.ToString(); * * systemUnitClass.SupportedRoleClass.Append(supportedRoleClass); * systemUnitClass.BaseClass.Name = supportedRoleClassFromDictionary; * * var attributesOfSystemUnitClassattributes = systemUnitClass.Attribute; * * foreach (var valueList in pairofList.Value) * { * foreach (var item in valueList) * { * var eachattribute = attributesOfSystemUnitClassattributes.Append(item.Name.ToString()); * eachattribute.Value = item.Value; * eachattribute.DefaultValue = item.Default; * eachattribute.Unit = item.Unit; * //eachattribute.AttributeDataType = * eachattribute.Description = item.Description; * eachattribute.Copyright = item.CopyRight; * * eachattribute.ID = item.ID; * * * * // systemUnitClass.BaseClass.Name = item.RefBaseClassPath; * } * } * }*/ } } } else { // check if our format is given in the amlx file if not: create it bool foundSysClassLib = false; foreach (var sysclasslib in document.CAEXFile.SystemUnitClassLib) { if (sysclasslib.Name.Equals("ComponentSystemUnitClassLib")) { bool foundSysClass = false; foreach (var sysclass in sysclasslib.SystemUnitClass) { if (sysclass.Name.Equals(device.deviceName)) { foundSysClass = true; systemUnitClass = sysclass; break; } } if (!foundSysClass) { systemUnitClass = sysclasslib.SystemUnitClass.Append(device.deviceName); } foundSysClassLib = true; } } if (!foundSysClassLib) { systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(device.deviceName); } } // Create the internalElement Electrical Interfaces if (device.vendorName != null) { InternalElementType electricalInterface = null; RoleRequirementsType roleRequirements = null; foreach (var internalElement in systemUnitClass.InternalElement) { if (internalElement.Name.Equals("ElectricalInterfaces")) { electricalInterface = internalElement; roleRequirements = electricalInterface.RoleRequirements.Append(); roleRequirements.RefBaseRoleClassPath = structureRoleFamilyType.CAEXPath(); break; } } if (electricalInterface == null) { electricalInterface = systemUnitClass.InternalElement.Append("ElectricalInterfaces"); } roleRequirements = electricalInterface.RoleRequirements.Append(); roleRequirements.RefBaseRoleClassPath = structureRoleFamilyType.CAEXPath(); foreach (var pair in device.DictionaryForInterfaceClassesInElectricalInterfaces) { InternalElementType internalElementofElectricalConnectorType = null; ExternalInterfaceType electricalConnectorType = null; ExternalInterfaceType electricalConnectorPins = null; Match numberfromElectricalConnectorType = Regex.Match(pair.Key.ToString(), @"\((\d+)\)"); string initialnumberbetweenparanthesisofElectricalConnectorType = numberfromElectricalConnectorType.Groups[1].Value; string electricalConnectorTypeName = Regex.Replace(pair.Key.ToString(), @"\(.+?\)", ""); electricalConnectorTypeName = Regex.Replace(electricalConnectorTypeName, @"\{.+?\}", ""); internalElementofElectricalConnectorType = electricalInterface.InternalElement.Append(electricalConnectorTypeName); electricalConnectorType = internalElementofElectricalConnectorType.ExternalInterface.Append(electricalConnectorTypeName); var attributesOfConnectorType = electricalConnectorType.Attribute; foreach (var valueList in pair.Value) { foreach (var item in valueList) { if (item.AttributePath.Contains("/") || item.AttributePath.Contains(".")) { int count = 2; int counter = 0; Stack <char> stack = new Stack <char>(); string searchAttributeName = item.AttributePath.Substring(0, item.AttributePath.Length - item.Name.Length); foreach (var character in searchAttributeName.Reverse()) { if (!char.IsLetterOrDigit(character)) { counter++; if (counter == count) { break; } } if (char.IsLetterOrDigit(character)) { stack.Push(character); } } string finalAttributeName = new string(stack.ToArray()); foreach (var attribute in electricalConnectorType.Attribute) { if (attribute.Name == finalAttributeName) { var eachattribute = attribute.Attribute.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } electricalConnectorType.RefBaseClassPath = item.RefBaseClassPath; } if (attribute.Attribute.Exists) { SearchAttributesInsideAttributesOFElectricConnectorType(finalAttributeName, attribute, item, electricalConnectorType); } } } else { var eachattribute = attributesOfConnectorType.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } electricalConnectorType.RefBaseClassPath = item.RefBaseClassPath; } } } foreach (var pairofList in device.DictionaryForExternalInterfacesUnderInterfaceClassInElectricalInterfaces) { Match numberfromElectricalConnectorPins = Regex.Match(pairofList.Key.ToString(), @"\((\d+)\)"); string initialnumberbetweenparanthesisElectricalConnectorPins = numberfromElectricalConnectorPins.Groups[1].Value; string electricalConnectorPinName = Regex.Replace(pairofList.Key.ToString(), @"\(.*?\)", ""); electricalConnectorPinName = Regex.Replace(electricalConnectorPinName, @"\{.*?\}", ""); electricalConnectorPinName = electricalConnectorPinName.Replace(electricalConnectorTypeName, ""); if (initialnumberbetweenparanthesisofElectricalConnectorType == initialnumberbetweenparanthesisElectricalConnectorPins) { electricalConnectorPins = electricalConnectorType.ExternalInterface.Append(electricalConnectorPinName); var attributesOfConnectorPins = electricalConnectorPins.Attribute; foreach (var valueList in pairofList.Value) { foreach (var item in valueList) { if (item.AttributePath.Contains("/") || item.AttributePath.Contains(".")) { int count = 2; int counter = 0; Stack <char> stack = new Stack <char>(); string searchAttributeName = item.AttributePath.Substring(0, item.AttributePath.Length - item.Name.Length); foreach (var character in searchAttributeName.Reverse()) { if (!char.IsLetterOrDigit(character)) { counter++; if (counter == count) { break; } } if (char.IsLetterOrDigit(character)) { stack.Push(character); } } string finalAttributeName = new string(stack.ToArray()); foreach (var attribute in electricalConnectorPins.Attribute) { if (attribute.Name == finalAttributeName) { var eachattribute = attribute.Attribute.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } electricalConnectorPins.RefBaseClassPath = item.RefBaseClassPath; } if (attribute.Attribute.Exists) { SearchAttributesInsideAttributesOFElectricConnectorType(finalAttributeName, attribute, item, electricalConnectorPins); } } } else { var eachattribute = attributesOfConnectorPins.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } electricalConnectorPins.RefBaseClassPath = item.RefBaseClassPath; } } } } } } } // create the PackageUri for the root aml file Uri partUri = PackUriHelper.CreatePartUri(new Uri("/" + fileName + "-root.aml", UriKind.Relative)); // tcreate the aml file as a temporary file string path = Path.GetTempFileName(); document.SaveToFile(path, true); if (isEdit) { // delete the old aml file amlx.Package.DeletePart(partUri); // delete all files in the amlx package. // Directory.Delete(Path.GetFullPath(amlx.ContainerFilename), true); } // write the new aml file into the package PackagePart root = amlx.AddRoot(path, partUri); if (!isEdit) { foreach (AttachablesDataGridViewParameters listWithUri in device.listWithURIConvertedToString) { if (listWithUri.ElementName != null) { Uri newuri = null; newuri = new Uri(listWithUri.ElementName, UriKind.Relative); amlx.AddAnyContent(root, listWithUri.FilePath.ToString(), newuri); } } } DirectoryInfo directory = new DirectoryInfo(Path.GetDirectoryName(amlFilePath)); foreach (FileInfo fileInfos in directory.GetFiles()) { if (fileInfos.Extension != ".amlx") { fileInfos.Delete(); } } amlx.Save(); amlx.Close(); if (isEdit) { return("Sucessfully updated device!\nFilepath " + amlFilePath); } else { return("Device description file created!\nFilepath " + amlFilePath); } }
/// <summary> /// Load the amlx container and try to load it as an <see cref="MWObject"/> /// </summary> /// <param name="file">The full path to the amlx file</param> /// <returns></returns> public MWObject loadObject(string file) { try { FileInfo fileInfo = new FileInfo(file); string objectName = fileInfo.Name; // Load the amlx container from the given filepath AutomationMLContainer amlx = new AutomationMLContainer(file); // Get the root path -> main .aml file IEnumerable <PackagePart> rootParts = amlx.GetPartsByRelationShipType(AutomationMLContainer.RelationshipType.Root); // We expect the aml to only have one root part if (rootParts.First() != null) { PackagePart part = rootParts.First(); // load the aml file as an CAEX document CAEXDocument document = CAEXDocument.LoadFromStream(part.GetStream()); // Iterate over all SystemUnitClassLibs and SystemUnitClasses and scan if it matches our format // since we expect only one device per aml(x) file, return after on is found foreach (SystemUnitClassLibType classLibType in document.CAEXFile.SystemUnitClassLib) { foreach (SystemUnitFamilyType classLib in classLibType.SystemUnitClass) { // check if it matches our format foreach (InternalElementType internalElement in classLib.InternalElement) { // is the DeviceIdentification there? if (internalElement.Name.Equals("DeviceIdentification")) { // is it an interface or a device? if (internalElement.Attribute.GetCAEXAttribute("InterfaceNumber") != null) { MWInterface mWInterface = new MWInterface(); mWInterface.numberOfInterface = Convert.ToInt32(internalElement.Attribute.GetCAEXAttribute("InterfaceNumber").Value); // read the attributes and write them directly into the interface fillInterfaceWithData(mWInterface, internalElement.Attribute); amlx.Close(); return(mWInterface); } else if (internalElement.Attribute.GetCAEXAttribute("DeviceName") != null) { MWDevice mWDevice = new MWDevice(); // read the attributes and write them directly into the device fillDeviceWithData(mWDevice, internalElement.Attribute); // check if there are pictures provided foreach (InternalElementType ie in classLib.InternalElement) { switch (ie.Name) { case "ManufacturerIcon": try { mWDevice.vendorLogo = ie.ExternalInterface.First().Attribute.GetCAEXAttribute("refURI").Value; } catch (Exception) { // No vendorLogo } break; case "ComponentPicture": try { mWDevice.devicePicture = ie.ExternalInterface.First().Attribute.GetCAEXAttribute("refURI").Value; } catch (Exception) { // No vendorLogo } break; case "ComponentIcon": try { mWDevice.deviceIcon = ie.ExternalInterface.First().Attribute.GetCAEXAttribute("refURI").Value; } catch (Exception) { // No vendorLogo } break; } } amlx.Close(); return(mWDevice); } } } } } } amlx.Close(); return(null); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Error while loading the AMLX-File", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return(null); } }
/// <summary> /// Create a new amlx file using <paramref name="newInterface"/> /// </summary> /// <param name="newInterface">the object to create</param> /// <param name="isEdit">true if an amlx file get update, false if a new file will be created</param> /// <returns></returns> public string CreateInterface(MWInterface newInterface, bool isEdit) { // Anlegen des AML / XML's // Siehe TINF17C/software-engineering-1/modelling-wizard/modellingwizardplugin#25 AutomationMLContainer amlx = null; CAEXDocument document = null; // init the filepath string fileName = newInterface.numberOfInterface + "-V.1.0-" + DateTime.Now.Date.ToShortDateString(); string amlFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\modellingwizard\\" + newInterface.numberOfInterface + ".amlx"; FileInfo file = new FileInfo(amlFilePath); file.Directory.Create(); // Init new CAEX Document if (isEdit) { // Load the amlx file amlx = new AutomationMLContainer(amlFilePath, FileMode.Open); IEnumerable <PackagePart> rootParts = amlx.GetPartsByRelationShipType(AutomationMLContainer.RelationshipType.Root); // We expect the aml to only have one root part if (rootParts.First() != null) { PackagePart part = rootParts.First(); // load the aml file as an CAEX document document = CAEXDocument.LoadFromStream(part.GetStream()); } else { // the amlx contains no aml file document = CAEXDocument.New_CAEXDocument(); } } else { // create a new CAEX document document = CAEXDocument.New_CAEXDocument(); amlx = new AutomationMLContainer(amlFilePath, FileMode.Create); } // Init the default Libs AutomationMLBaseRoleClassLibType.RoleClassLib(document); AutomationMLInterfaceClassLibType.InterfaceClassLib(document); SystemUnitFamilyType systemUnitClass = null; // Create the SystemUnitClass for our device if (!isEdit) { systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(newInterface.numberOfInterface.ToString()); } else { bool foundSysClassLib = false; foreach (var sysclasslib in document.CAEXFile.SystemUnitClassLib) { if (sysclasslib.Name.Equals("ComponentSystemUnitClassLib")) { bool foundSysClass = false; foreach (var sysclass in sysclasslib.SystemUnitClass) { if (sysclass.Name.Equals(newInterface.numberOfInterface.ToString())) { foundSysClass = true; systemUnitClass = sysclass; break; } } if (!foundSysClass) { sysclasslib.SystemUnitClass.Append(newInterface.numberOfInterface.ToString()); } foundSysClassLib = true; } } if (!foundSysClassLib) { systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(newInterface.numberOfInterface.ToString()); } } // create the DeviceIdentification InternalElement InternalElementType ie = null; foreach (var internalelement in systemUnitClass.InternalElement) { if (internalelement.Name.Equals("DeviceIdentification")) { ie = internalelement; break; } } if (ie == null) { ie = systemUnitClass.InternalElement.Append("DeviceIdentification"); } // make sure that the attributes are initialized initCAEXAttribute("InterfaceNumber", "xs:integer", ie); initCAEXAttribute("Description", "xs:string", ie); initCAEXAttribute("ConnectorType", "xs:string", ie); initCAEXAttribute("PinCount", "xs:integer", ie); // special handling for the pinlist AttributeType pinlistAtt = null; if (ie.Attribute.GetCAEXAttribute("PinAttributes") == null) { pinlistAtt = ie.Attribute.Append("PinAttributes"); } else { pinlistAtt = ie.Attribute.GetCAEXAttribute("PinAttributes"); pinlistAtt.Attribute.Remove(); } // assign the values for the pinlist foreach (MWPin pin in newInterface.pinList) { pinlistAtt.Attribute.Append(pin.pinNumber.ToString()).Value = pin.attribute; } // assign the values for the 'normal' attributes writeIfNotNull(ie.Attribute.GetCAEXAttribute("InterfaceNumber"), newInterface.numberOfInterface); writeIfNotNull(ie.Attribute.GetCAEXAttribute("Description"), newInterface.interfaceDescription); writeIfNotNull(ie.Attribute.GetCAEXAttribute("ConnectorType"), newInterface.connectorType); writeIfNotNull(ie.Attribute.GetCAEXAttribute("PinCount"), newInterface.amountPins); // create the aml package part Uri partUri = PackUriHelper.CreatePartUri(new Uri("/" + fileName + "-root.aml", UriKind.Relative)); // create a temp file with the new aml string path = Path.GetTempFileName(); document.SaveToFile(path, true); if (isEdit) { // delete the old aml file amlx.Package.DeletePart(partUri); } // copy the new aml file into the package PackagePart root = amlx.AddRoot(path, partUri); amlx.Save(); amlx.Close(); if (isEdit) { return("Sucessfully updated interface!\nFilepath " + amlFilePath); } else { return("Sucessfully created interface!\nFilepath " + amlFilePath); } }
/// <summary> /// Creates a new instance of the <see cref="AmlDocument"/> class with a given <see cref="CaexDocument"/> instance. /// </summary> public AmlDocument(CAEXDocument document) { CaexDocument = document; }
/// <summary> /// Creates a new instance of the <see cref="AmlDocument"/> class. /// </summary> public AmlDocument() { CaexDocument = CAEXDocument.New_CAEXDocument(CAEXDocument.CAEXSchema.CAEX3_0); }