/// <summary> /// Adds internal element children to the provided container. /// InternalElement containers are InternalElements and InstanceHierarchies. /// </summary> /// <param name="container">The container.</param> internal static void AddElementChildren(IInternalElementContainer container, ref int levels) { // add a single child var newElement = AMLObject.AddObjectWithoutClassReference(container, "Child_1"); if (levels > 0) { // add some grand childs, if last level not reached levels--; AddElementChildren(newElement, ref levels); } // add a child using an alternative method AMLObject.AddObjectWithClassReference(container, "Child_2"); }
/// <summary> /// Creates a sample aml document with automationml standard libraries and one aml object. /// </summary> /// <returns></returns> private static CAEXDocument A_CreateSampleAMLDocument() { // creates a new aml document using the default schema, which is CAEX3.0 var amlDocument = CAEXDocument.New_CAEXDocument(); // add some meta data var documentInformation = amlDocument.CAEXFile.SourceDocumentInformation.First(); documentInformation.OriginID = typeof(Program).Assembly.GetName().Name; documentInformation.OriginName = typeof(Program).Assembly.GetName().Name; documentInformation.OriginRelease = typeof(Program).Assembly.GetName().Version.ToString(); documentInformation.OriginVersion = typeof(Program).Assembly.GetName().Version.ToString(); documentInformation.OriginVendor = "AutomationML"; documentInformation.OriginVendorURL = "https://github.com/AutomationML/AMLEngine2.1"; documentInformation.OriginProjectID = "AMLEngine2.1"; documentInformation.OriginProjectTitle = "AMLEngine2.1 samples"; documentInformation.LastWritingDateTime = DateTime.Now; // adds the standard base libraries to the document AutomationMLInterfaceClassLibType.InterfaceClassLib(amlDocument); AutomationMLBaseRoleClassLibType.RoleClassLib(amlDocument); // only CAEX3.0 documents allow to add an attribute type library. This should // be true for the new document if (amlDocument.Schema == CAEXDocument.CAEXSchema.CAEX3_0) { AutomationMLBaseAttributeTypeLibType.AttributeTypeLib(amlDocument); } // now you can use the standard role and interface classes // we will create some internal elements with standard class assignments now var ih = amlDocument.CAEXFile.InstanceHierarchy.Append("SomeAMLObjects"); // you can reference the instance hierarchy like this: Debug.Assert(ih.Equals(amlDocument.CAEXFile.InstanceHierarchy[0])); Debug.Assert(ih.Equals(amlDocument.CAEXFile.InstanceHierarchy["SomeAMLObjects"])); // an automationML object InternalElement is added and named var line = AMLObject.AddObjectWithoutClassReference(ih, "Root"); // we override the id, generated by the engine for this object line.ID = "ROOT"; // the element gets an assigned role class. The standard role class path is used line.AddRoleClassReference(AutomationMLBaseRoleClassLib.ResourceStructure); // There exists an overload for this method which accepts the role class object. // To get the roleclass object, you have to search for it. It should be found because // the library has been added to the document before. var roleClass = amlDocument.FindByPath(AutomationMLBaseRoleClassLib.Resource) as RoleFamilyType; if (roleClass != null) { line.AddRoleClassReference(roleClass); } // the element has two rolereferences now. Debug.Assert(line.RoleReferences.Count() == 2); return(amlDocument); }