This repository has been archived by the owner on Jun 22, 2019. It is now read-only.
examples
AutomationML edited this page May 15, 2019
·
2 revisions
These code examples show basic principles for AutomationML Application Development using the AMLEngine.
-
Loading a Document
C#
// using CAEX_ClassModel; var document = CAEXDocument.LoadFromFile ("myFile.aml");
-
Saving a Document
C#
// using CAEX_ClassModel; CAEXDocument.SaveToFile ("myFile.aml", true);
-
Traversing a Document with the CAEXFile.
C#
// using CAEX_ClassModel; var document = CAEXDocument.LoadFromFile("myFile.aml"); // browse the Instance Hierarchies in the file foreach (var instanceHierary in document.CaexFile.InstanceHierarchies()) { // browse all InternalElements deep and import the internal Elements to your system foreach (var internalElement in instanceHierarchy.Descendants (typeof(InternalElementType)) ) { // ToDo: import internal Element } }
-
Validating a Document
C#
// using CAEX_ClassModel; CEXDocument document = CAEXDocument.LoadFromFile (filepath); // update the tables document.Tables.UpdateAllTables(); // validate all elements (needs an updated Element Registry) foreach ( var isValidated in document.ValidateAll()) { // check for the GenerateUniqueIDForDoubles - Option to repair if (isValidated.AvailableRepairOptions.HasFlag (RepairTypeEnum.GenerateUniqueIDForDoubles)) { bool isRepaired = document.Repair (isValidated, RepairTypeEnum.GenerateUniqueIDForDoubles); if (isRepaired) { // ToDo: display isValidated.RepairResult } } }
-
Accessing all InternalElement which have References to a specific RoleClass using: RegisteredReferences
C#
// using CAEX_ClassModel; CAEXDocument document = CAEXDocument.LoadFromFile (filepath); // update the tables document.Tables.UpdateAllTables(); // use the RoleClass-Path as Key string myRolePath = "MyRoleClassLib/MyRole"; // get the RoleClass from the PathTable RoleClassType myRole = document.Tables.PathTable.CaexElement (myRolePath) as RoleClassType; if (myRole != null) { // get the RegisteredReferences foreach ( var roleReference in document.Tables.RegisteredReferences(myRole)) { var parent = roleReference.GetParent (); if (parent is InternalElementType) { // this internal Element has a RoleReference to the Role "MyRoleClassLib/MyRole". // the Role Reference is a RoleRequirement or a SupportedRoleClass } } }
-
Accessing all InternalElement - References to a specific RoleClass and its Specializations
C#
// using CAEX_ClassModel; // using System.Linq; // loading the document CAEXDocument document = CAEXDocument.LoadFromFile (filepath); // update the tables document.Tables.UpdateAllTables(); // use the RoleClass-Path string myRolePath = "MyRoleClassLib/MyRole"; // find the keys for the Specializations. Look at all keys, that start with 'myRolePath' var keys = document.Tables.PathRefTable.Keys.Where (key => key.StartsWith (myRolePath)); foreach ( var key in keys ) { // get Elements from the PathRefTable for each found key foreach (var reference in document.Tables.PathRefTable.CaexElements(key)) { var parent = roleReference.GetParent (); if (parent is InternalElementType) { // this internal Element has a RoleReference to the Role "MyRoleClassLib/MyRole" or to one of the // derived roles. The Role Reference is a RoleRequirement or a SupportedRoleClass } } }
AMLEngine Documentation
Send comments on this topic to [AutomationML office](mailto:office%40automationml.org?Subject=AMLEngine Documentation)- Introduction
- [Version History](Version history)
- [Version 3.5](Version 3.4)
- [Version 3.1](Version 3.0)
- [Version 2.1](Version 2.1)
- [Version 2.0](Version 2.0)
- [Getting Started](Getting started)
- Examples
- AMLEngine API
- AttributeType
- AttributeValueRequirementType
- CAEXBasicObject
- CAEXDocument
- CAEXFileType
- CAEXObject
- ChangeModeStates
- CopyrightType
- DescriptionType
- ExternalInterfaceType
- ExternalReferenceType
- InstanceHierarchyType
- InterfaceClassLibType
- InterfaceClassType
- InterfaceFamilyType
- InterfaceNameMappingType
- InternalElementType
- InternalLinkType
- MappingType
- NominalScaledTypeType
- ObjectWithAttributes
- OrdinalScaledTypeType
- RefSemanticType
- RevisionType
- RoleClassLibType
- RoleClassType
- RoleFamilyType
- RoleRequirementsType
- SupportedRoleClassType
- SystemUnitClassLibType
- SystemUnitClassType
- SystemUnitFamilyType
- UnknownTypeType
- VersionType
- IClassWithBaseClassReference
- IInstantiable
- IObjectWithAttributes
- IObjectWithExternalInterface
- IObjectWithRoleReference
- CAEXPathReferenceTable Class
- CAEXTable(T) Class
- CAEXTables Class
- ElementCollection(T) Class
- PathReferenceElement Class
- ReferenceElement Class
- RepairTypeEnum Enumeration
- UpdateActionEnum Enumeration
- UpdateEventArgs Class
- ValidationElement Class
- ValidationKey Class
- ValidationTypeEnum Enumeration
- CAEX_ClassModel.XmlExtension Namespace