Skip to content
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

Basic examples

These code examples show basic principles for AutomationML Application Development using the AMLEngine.

Basic Examples

 

  1. Loading a Document

    C#

    // using CAEX_ClassModel;
    
    var document = CAEXDocument.LoadFromFile ("myFile.aml");
  2. Saving a Document

    C#

    // using CAEX_ClassModel;
    
    CAEXDocument.SaveToFile ("myFile.aml", true);
  3. 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
        }
    }
  4. 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
            }
        }
    }
  5. 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
            }
        }
    }
  6. 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
            }
        }
    }
 
  • 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
BEST Practice Content

Extensions

CAEX Elements

AutomationML

Utilities

Interfaceclasses

Exceptions

Objecttables and Document validation

Clone this wiki locally