Example #1
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);
        }