-
Notifications
You must be signed in to change notification settings - Fork 8
Libraries
This topic contains the following examples:
- Adding new libraries to a CAEX Document
- Import of AutomationML Standard libraries into a CAEX Document
- Import of libraries form a source document into a target document
- Export libraries form a source into a target document (Splitting)
These examples show how to create and traverse CAEX libraries. The class hierarchy is shown in the diagram. The CAEX Classes are all defined in the Aml.Engine.CAEX
namespace.
using Aml.Engine.CAEX;
void CreateLibraries (CAEXDocument document)
{
// libraries are added to the CAEXFile property of a document
// each library type is added to the appropriate sequence
// InstanceHierarchies are added to the InstanceHierarchy sequence
document.CAEXFile.InstanceHierarchy.Append ("InstanceHierarchy_1");
document.CAEXFile.InstanceHierarchy.Append ("InstanceHierarchy_2");
// RoleClassLibraries are added to the RoleClassLib sequence
document.CAEXFile.RoleClassLib.Append ("Rlib_1");
document.CAEXFile.RoleClassLib.Append ("Rlib_2");
// SystemUnitClassLibraries are added to the SystemUnitClassLib sequence
document.CAEXFile.SystemUnitClassLib.Append ("Slib_1");
// InterfaceClassLibraries are added to the InterfaceClassLib sequence
document.CAEXFile.InterfaceClassLib.Append ("Ilib_1");
// AttributeTypeLibraries are added to the AttributeTypeLib sequence
document.CAEXFile.AttributeTypeLib.Append ("ATlib_1");
}
References
The AutomationML standard libraries can be added to a CAEXDocument
. The AMLEngine selects the appropriate libraries, according to the documents CAEX schema. AutomationML standard libraries are not part of the CAEX Class model but are implemented in the Aml.Engine.AmlObjects
namespaces.
using Aml.Engine.CAEX;
using Aml.Engine.AmlObjects;
void ImportStandardLibraries (CAEXDocument document)
{
// AutomationML defines standard class libraries which can be
// imported into an existing CAEX document. Objects, which are defined by AutomationML and are
// specific implementations of CAEX objects are provided in the Aml.Engine.AmlObjects namespace.
// Gets or imports the standard AutomationMLInterfaceClassLib into the document
var amlBaseICLib = AutomationMLInterfaceClassLibType.InterfaceClassLib(document);
// Gets or imports the standard AutomationMLRoleClassLib into the document
var amlBaseRCLib = AutomationMLBaseRoleClassLibType.RoleClassLib(document);
// Gets or imports the standard AutomationMLAttributeTypeLib into the document
var amlBaseICLib = AutomationMLBaseAttributeTypeLibType.AttributeTypeLib(document);
}
References
AutomationMLInterfaceClassLibType
AutomationMLBaseRoleClassLibType
AutomationMLBaseAttributeTypeLibType
Methods to import libraries from a source into a target document are defined in the Aml.Engine.CAEX.Extensions
namespace. It has to be ensured, that the documents are based on the same CAEX schema.
using Aml.Engine.CAEX;
using Aml.Engine.CAEX.Extensions;
void ImportLibraries (CAEXDocument sourceDocument, CAEXDocument targetDocument)
{
if (sourceDocument.Schema != targetDocument.Schema)
{
return;
}
// Traverse the source document libraries and import them into the targetDocument.
foreach (var library in sourceDocument.CAEXFile)
{
switch (library)
{
case RoleClassLibType rLib:
targetDocument.CAEXFile.ImportRoleClassLib (rlib);
break;
case InterfaceClassLibType iLib:
targetDocument.CAEXFile.ImportInterfaceClassLib(ilib);
break;
case AttributeTypeLibType aLib:
targetDocument.CAEXFile.ImportAttributeTypeLib(alib);
break;
case InstanceHierarchyType iH:
targetDocument.CAEXFile.ImportInstanceHierarchy(iH);
break;
case SystemUnitClassLibType sLib:
targetDocument.CAEXFile.ImportSystemUnitClassLib(slib);
break;
default:
break;
}
}
}
References
ImportRoleClassLib
ImportInterfaceClassLib
ImportAttributeTypeLib
ImportSystemUnitClassLib
ImportInstanceHierarchy
Specific features like splitting a document are provided by dedicated services, implemented in the Aml.Engine.Services
namespace. Libraries in CAEX implement the ISplitPoint
Interface and are suitable for split operations. SplitPoints can also be defined for InternalElementType
objects. Exporting libraries using the SplitService
ensures, that remaining references to the exported library from the source document are rebuild, according to the alias referencing scheme.
using Aml.Engine.CAEX;
using Aml.Engine.Services;
void ExportLibraries (CAEXDocument sourceDocument)
{
// Exporting the AutomationML Base RoleClass Lib using the SplitService.
// Instantiating a split service.
var service = SplitService.Register();
// Setting the BaseRoleClass Library as a SplitPoint
service.SetSplitPoint (AutomationMLBaseRoleClassLibType.RoleClassLib(sourceDocument));
// Creation of a target document, containing the exported library.
// External references are added to the source document using the provided alias name if needed.
var targetDocument = service.Split(sourceDocument, alias:"BaseRole", filePath:"BaseRoleLib.aml");
// Service is not needed any more
SplitService.UnRegister();
}
Reference
Home | Installation | API | Solutions
Getting Started
- Install
- First Steps with CAEX
- Working with CAEX Libraries
- Working with CAEX Relations
- Managing Inheritance
- Attribut Values
- Document Versions
Extended Examples
API Reference Guide