Ejemplo n.º 1
0
        public void ExportBrowseNameTest()
        {
            UANodeSet _tm = TestData.CreateNodeSetModel();
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();

            _asMock.Setup(x => x.GetNamespace(0)).Returns <ushort>(x => "tempuri.org");
            UANode _nodeFactory = new UAVariable()
            {
                NodeId       = "ns=1;i=47",
                BrowseName   = "EURange",
                ParentNodeId = "ns=1;i=43",
                DataType     = "i=884",
                DisplayName  = new XML.LocalizedText[] { new XML.LocalizedText()
                                                         {
                                                             Value = "EURange"
                                                         } }
            };
            UANodeContext _node = new UANodeContext(NodeId.Parse("ns=1;i=47"), _asMock.Object);

            _node.Update(_nodeFactory, x => Assert.Fail());
            XmlQualifiedName _resolvedName = _node.ExportNodeBrowseName();

            _asMock.Verify(x => x.GetNamespace(0), Times.Once);
            Assert.IsNotNull(_resolvedName);
            Assert.AreEqual <string>("tempuri.org:EURange", _resolvedName.ToString());
        }
Ejemplo n.º 2
0
        public void UpdateDuplicatedNodeIdTest()
        {
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();
            UANodeContext _newNode = new UANodeContext(NodeId.Parse("ns=1;i=11"), _asMock.Object);
            Mock <IBuildErrorsHandling> _traceMock   = new Mock <IBuildErrorsHandling>();
            List <TraceMessage>         _traceBuffer = new List <TraceMessage>();

            _traceMock.Setup(x => x.TraceEvent(It.IsAny <TraceMessage>())).Callback <TraceMessage>(x => _traceBuffer.Add(x));
            _newNode.Log = _traceMock.Object;
            UAVariable _nodeFactory = new UAVariable()
            {
                NodeId       = "ns=1;i=47",
                BrowseName   = "EURange",
                ParentNodeId = "ns=1;i=43",
                DataType     = "i=884",
                DisplayName  = new XML.LocalizedText[] { new XML.LocalizedText()
                                                         {
                                                             Value = "EURange"
                                                         } }
            };

            _newNode.Update(_nodeFactory, x => Assert.Fail());
            _newNode.Update(_nodeFactory, x => Assert.Fail());
            Assert.AreEqual <int>(1, _traceBuffer.Count);
            Assert.AreEqual <string>(_traceBuffer[0].BuildError.Identifier, BuildError.NodeIdDuplicated.Identifier);
        }
Ejemplo n.º 3
0
        public void EqualsUAVariableTestMethod()
        {
            UAVariable _derivedNode = new UAVariable()
            {
                NodeId       = "ns=1;i=47",
                BrowseName   = "EURange",
                ParentNodeId = "ns=1;i=43",
                DataType     = "i=884",
                DisplayName  = new XML.LocalizedText[] { new XML.LocalizedText()
                                                         {
                                                             Value = "EURange"
                                                         } }
            };
            UANode _baseNode = new UAVariable()
            {
                NodeId       = "i=17568",
                BrowseName   = "EURange",
                ParentNodeId = "i=15318",
                DataType     = "i=884",
                DisplayName  = new XML.LocalizedText[] { new XML.LocalizedText()
                                                         {
                                                             Value = "EURange"
                                                         } }
            };
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();
            IUANodeContext _derivedNodeContext       = new UANodeContext(NodeId.Parse("ns=1;i=47"), _asMock.Object);

            _derivedNodeContext.Update(_derivedNode, x => Assert.Fail());
            UANodeContext _baseNodeContext = new UANodeContext(NodeId.Parse("i=17568"), _asMock.Object);

            _baseNodeContext.Update(_baseNode, x => Assert.Fail());
            Assert.IsTrue(_derivedNode.Equals(_baseNode));
            Assert.IsTrue(_derivedNodeContext.Equals(_baseNodeContext));
        }
Ejemplo n.º 4
0
        //Asset Creation

        private static string CreateView(AdminShellV20.View view)
        {
            UAVariable var = new UAVariable();

            var.NodeId     = "ns=1;i=" + masterID.ToString();
            var.BrowseName = "1:" + view.idShort;
            masterID++;
            List <Reference> refs = new List <Reference>();

            refs.Add(CreateHasTypeDefinition("1:AASViewType"));

            if (view.description != null)
            {
                refs.Add(CreateReference("HasComponent", CreateReferable(view.category, view.description.langString)));
            }

            foreach (AdminShellV20.ContainedElementRef con in view.containedElements.reference)
            {
                refs.Add(CreateReference("HasComponent", createContainedElement(con)));
            }


            var.References = refs.ToArray();
            root.Add((UANode)var);
            return(var.NodeId);
        }
Ejemplo n.º 5
0
        private static string CreateProperty(string value, string type, string BrowseName, string datatype)
        {
            //Creates a Property with a single Value

            UAVariable prop = new UAVariable();

            prop.NodeId     = "ns=1;i=" + masterID.ToString();
            prop.BrowseName = "1:" + BrowseName;
            prop.DataType   = datatype;
            masterID++;
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

            //Remove ':', because it's not allowed in XML
            if (datatype.Contains(':'))
            {
                var strings = datatype.Split(':');
                datatype = strings[1];
            }

            //Create XMLElement to store Value in
            System.Xml.XmlElement element = doc.CreateElement(
                "uax", datatype, "http://opcfoundation.org/UA/2008/02/Types.xsd");
            element.InnerText = value;
            prop.Value        = element;

            prop.References = new Reference[1];

            prop.References[0] = CreateHasTypeDefinition(type);
            root.Add((UANode)prop);

            return(prop.NodeId);
        }
Ejemplo n.º 6
0
        private static string CreateSemanticId(AdminShellV20.SemanticId sem)
        {
            if (sem == null)
            {
                return(null);
            }

            UAVariable ident = new UAVariable();

            ident.NodeId     = "ns=1;i=" + masterID.ToString();
            ident.BrowseName = "1:AASSemanticId";
            masterID++;
            List <Reference> refs = new List <Reference>();

            refs.Add(CreateHasTypeDefinition("1:AASSemanticIdType"));

            foreach (AdminShellV20.Key key in sem.Keys)
            {
                refs.Add(
                    CreateReference(
                        "HasComponent", CreateKey(key.idType, key.local.ToString(), key.type, key.value)));
            }

            ident.References = refs.ToArray();
            root.Add((UANode)ident);
            return(ident.NodeId);
        }
        private static RelationshipElement setRealtionshipElement(UANode node)
        {
            //RelationshipElement
            //  -> First (Reference)
            //  -> Second (Reference)

            RelationshipElement elem = new RelationshipElement();

            foreach (Reference _ref in node.References)
            {
                if (_ref.ReferenceType != "HasTypeDefinition")
                {
                    UAVariable var = (UAVariable)findNode(_ref.Value);
                    if (var.BrowseName == "1:First")
                    {
                        elem.first = createReference(var.Value.InnerText);
                    }
                    if (var.BrowseName == "1:Second")
                    {
                        elem.second = createReference(var.Value.InnerText);
                    }
                }
            }

            return(elem);
        }
Ejemplo n.º 8
0
        public void RemoveInheritedValuesTest()
        {
            UAVariable _derivedNode = new UAVariable()
            {
                NodeId      = "ns=1;i=47", BrowseName = "EURange", ParentNodeId = "ns=1;i=43", DataType = "i=884",
                DisplayName = new XML.LocalizedText[] { new XML.LocalizedText()
                                                        {
                                                            Value = "EURange"
                                                        } }
            };
            UANode _baseNode = new UAVariable()
            {
                NodeId      = "i=17568", BrowseName = "EURange", ParentNodeId = "i=15318", DataType = "i=884",
                DisplayName = new XML.LocalizedText[] { new XML.LocalizedText()
                                                        {
                                                            Value = "EURange"
                                                        } }
            };
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();
            IUANodeContext _derivedNodeContext       = new UANodeContext(NodeId.Parse("ns=1;i=47"), _asMock.Object);

            _derivedNodeContext.Update(_derivedNode, x => Assert.Fail());
            UANodeContext _baseNodeContext = new UANodeContext(NodeId.Parse("i=17568"), _asMock.Object);

            _baseNodeContext.Update(_baseNode, x => Assert.Fail());
            _derivedNodeContext.RemoveInheritedValues(_baseNodeContext);
            Assert.AreEqual <string>("EURange", _derivedNode.BrowseName);
            Assert.IsNull(_derivedNode.DataType);
            Assert.IsNull(_derivedNode.Description);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Read OPC-UA NodesSet xml file and parse it into a UANodeSet object
            string nodesetxmlfilepath = "..\\..\\assets\\miab10-nodeset2.xml";

            Stream stream = new FileStream(nodesetxmlfilepath, FileMode.Open);

            Opc.Ua.Export.UANodeSet nodeSet = Opc.Ua.Export.UANodeSet.Read(stream);

            Dictionary <string, UANode> nodeDict = new Dictionary <string, UANode>();

            foreach (var item in nodeSet.Items)
            {
                nodeDict.Add(item.NodeId, item);
            }

            if (nodeDict.ContainsKey("ns=2;s=Beijer.nsuri=TagProvider;s=Tags"))
            {
                UAObject tagsObject = nodeDict["ns=2;s=Beijer.nsuri=TagProvider;s=Tags"] as UAObject;

                DTDLInterface di = new DTDLInterface();
                di.Extends = null;
                di.Id      = "dtmi:opcfoundation:org:UA:MiaB:Tags;1";

                var varRefs = Array.FindAll(tagsObject.References,
                                            varNodeRef => varNodeRef.ReferenceType == "HasComponent" && varNodeRef.IsForward);
                foreach (var item in varRefs)
                {
                    UAVariable       uaVar       = nodeDict[item.Value] as UAVariable;
                    DTDLPropertyItem dpi         = new DTDLPropertyItem();
                    string[]         nodeIdParts = uaVar.NodeId.Split(';');
                    dpi.Name   = nodeIdParts[2].Substring(2);
                    dpi.Schema = "integer";
                    di.Contents.Add(dpi);
                }

                Console.WriteLine("Hello World!");
                JsonSerializerOptions options = new JsonSerializerOptions
                {
                    WriteIndented        = true,
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                    IgnoreNullValues     = true,
                };
                // This is a workaround for the lack of polymorphic serialization in System.Text.Json
                // The suggested workaround in the docs (use object to declare the child item) did not work for me
                // But this custom serializer does
                options.Converters.Add(new HeterogenousListConverter <DTDLContentItem, List <DTDLContentItem> >());
                string ts = JsonSerializer.Serialize(di, options);
                System.IO.File.WriteAllText(".\\dtmi_opcfoundation_org_UA_MiaB-Tags-interface-1.json", ts);
            }
        }
Ejemplo n.º 10
0
 private static void Update(IVariableInstanceFactory nodeDesign, UAVariable nodeSet, IUANodeBase nodeContext, Action <TraceMessage> traceEvent)
 {
     nodeDesign.AccessLevel             = nodeSet.AccessLevel.GetAccessLevel(traceEvent);
     nodeDesign.ArrayDimensions         = nodeSet.ArrayDimensions.ExportString(string.Empty);
     nodeDesign.DataType                = nodeContext.ExportBrowseName(nodeSet.DataType, DataTypes.Number); //TODO add test case must be DataType, must not be abstract
     nodeDesign.DefaultValue            = nodeSet.Value;                                                    //TODO add test case must be of type defined by DataType
     nodeDesign.Historizing             = nodeSet.Historizing.Export(false);
     nodeDesign.MinimumSamplingInterval = nodeSet.MinimumSamplingInterval.Export(0D);
     nodeDesign.ValueRank               = nodeSet.ValueRank.GetValueRank(traceEvent);
     if (nodeSet.Translation != null)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NotSupportedFeature, "- the Translation element for the UAVariable"));
     }
 }
Ejemplo n.º 11
0
        NodeId get_dataType(UAVariable var)
        {
            // check first in the aliases
            foreach (NodeIdAlias alias in m_aliases)
            {
                logger.Debug("------ Substring ----- " + alias.Value + "  sub-> ");     //+alias.Value.Substring(2));

                if (alias.Alias == var.DataType)
                {
                    logger.Debug("------ Matched with " + var.DataType); //+alias.Value.Substring(2));

                    // case of non built it dataType alias
                    if (alias.Value.Split(';').Length > 1)
                    {
                        return(NodeId.Create(
                                   getIdentifier(alias.Value),
                                   getNodeNamespace(alias.Value),
                                   session_namespace
                                   ));
                    }
                    // case of built in DataType alias
                    else
                    {
                        return(new NodeId((uint)getIdentifier(alias.Value)));
                    }
                }
            }
            logger.Debug("Not in Aliases " + var.DataType);
            // Check if is a nodeID
            if (var.DataType.Substring(0, 2) == "i=" || var.DataType.Substring(0, 3) == "ns=")
            {
                logger.Debug("nodeID in dataType " + var.DataType);
                return(NodeId.Create(
                           getIdentifier(var.DataType),
                           getNodeNamespace(var.DataType),
                           session_namespace
                           ));
            }
            // then try with system types
            if (Type.GetType(var.DataType) != null)
            {
                return(TypeInfo.GetDataTypeId(Type.GetType(var.DataType)));
            }

            else
            {
                return(NodeId.Null);
            }
        }
        private static List <Key> addSemanticID(UANode sem)
        {
            //SemanticId
            //  -> Key (multiple)
            //      -> idType
            //      -> Local
            //      -> Type
            //      -> Value

            List <Key> keys = new List <Key>();

            foreach (Reference _ref in sem.References)
            {
                if (_ref.ReferenceType != "HasTypeDefinition" &&
                    getTypeDefinition(findNode(_ref.Value)) == "1:AASKeyType")
                {
                    UAVariable key  = (UAVariable)findNode(_ref.Value);
                    Key        _key = new Key();
                    foreach (Reference _InnerRef in key.References)
                    {
                        if (_InnerRef.ReferenceType != "HasTypeDefinition")
                        {
                            UAVariable value = (UAVariable)findNode(_InnerRef.Value);
                            switch (value.BrowseName)
                            {
                            case "1:IdType":
                                _key.idType = value.Value.InnerText;
                                break;

                            case "1:Local":
                                _key.local = bool.Parse(value.Value.InnerText);
                                break;

                            case "1:Type":
                                _key.type = value.Value.InnerText;
                                break;

                            case "1:Value":
                                _key.value = value.Value.InnerText;
                                break;
                            }
                        }
                    }
                    keys.Add(_key);
                }
            }
            return(keys);
        }
Ejemplo n.º 13
0
 private void Update(IPropertyInstanceFactory propertyInstance, UAVariable nodeSet, IUANodeBase nodeContext, UAReferenceContext parentReference)
 {
     try
     {
         Update(propertyInstance, nodeSet);
         propertyInstance.ReferenceType = parentReference == null ? null : parentReference.GetReferenceTypeName();
         if (!nodeContext.IsProperty)
         {
             Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, $"Creating Property {nodeContext.BrowseName}- wrong reference type {parentReference.ReferenceKind.ToString()}"));
         }
     }
     catch (Exception _ex)
     {
         Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, string.Format("Cannot resolve the reference for Property because of error {0} at: {1}.", _ex, _ex.StackTrace)));
     }
 }
Ejemplo n.º 14
0
 private static void Update(IVariableInstanceFactory variableInstance, UAVariable nodeSet, IUANodeBase nodeContext, UAReferenceContext parentReference, Action <TraceMessage> traceEvent)
 {
     try
     {
         Update(variableInstance, nodeSet, nodeContext, traceEvent);
         variableInstance.ReferenceType = parentReference == null ? null : parentReference.GetReferenceTypeName();
         if (nodeContext.IsProperty)
         {
             traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Variable, string.Format("Creating Variable - wrong reference type {0}", parentReference.ReferenceKind.ToString())));
         }
     }
     catch (Exception _ex)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, string.Format("Cannot resolve the reference for Variable because of error {0} at: {1}.", _ex, _ex.StackTrace)));
     }
 }
        private static Identification GetIdentification(UANode submodel)
        {
            //AASIdentifiable
            //  -> AASIdentifierType
            //      -> Id
            //      -> IdType

            //get AASIdentifiable node
            UANode iden = null;

            foreach (Reference _ref in submodel.References)
            {
                if (_ref.ReferenceType == "HasInterface")
                {
                    iden = findNode(_ref.Value);
                }
            }

            Identification identification = new Identification();

            foreach (Reference _ref in iden.References)
            {
                if (_ref.ReferenceType != "HasTypeDefinition")
                {
                    if (getTypeDefinition(findNode(_ref.Value)) == "1:AASIdentifierType")
                    {
                        var val = (UAVariable)findNode(_ref.Value);
                        foreach (Reference _refref in val.References)
                        {
                            if (_refref.ReferenceType == "HasProperty")
                            {
                                UAVariable node = (UAVariable)findNode(_refref.Value);
                                if (node.BrowseName == "1:Id")
                                {
                                    identification.id = node.Value.InnerText;
                                }
                                if (node.BrowseName == "1:IdType")
                                {
                                    identification.idType = node.Value.InnerText;
                                }
                            }
                        }
                    }
                }
            }
            return(identification);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Get the clone from the types derived from this one.
        /// </summary>
        /// <returns>An instance of <see cref="T:UAOOI.SemanticData.UANodeSetValidation.XML.UANode" />.</returns>
        protected override UANode ParentClone()
        {
            UAVariable _ret = new UAVariable()
            {
                Value                   = this.Value,
                Translation             = this.Translation,
                DataType                = this.DataType,
                ValueRank               = this.ValueRank,
                ArrayDimensions         = this.ArrayDimensions,
                AccessLevel             = this.AccessLevel,
                UserAccessLevel         = this.UserAccessLevel,
                MinimumSamplingInterval = this.MinimumSamplingInterval,
                Historizing             = this.Historizing,
            };

            return(_ret);
        }
Ejemplo n.º 17
0
        internal override void RemoveInheritedValues(UANode baseNode)
        {
            base.RemoveInheritedValues(baseNode);
            UAVariable _other = baseNode as UAVariable;

            if (baseNode is null)
            {
                throw new System.ArgumentNullException($"{nameof(baseNode)}", $"The parameter of the {nameof(RemoveInheritedValues)} must not be null");
            }
            if (this.DataType == _other.DataType)
            {
                this.DataType = null;
            }
            if (this.ArrayDimensions == _other.ArrayDimensions)
            {
                this.ArrayDimensions = string.Empty;
            }
        }
Ejemplo n.º 18
0
        private static string CreateLangStrSet(string lang, string str)
        {
            UAVariable ident = new UAVariable();

            ident.NodeId     = "ns=1;i=" + masterID.ToString();
            ident.BrowseName = "1:AASLangStrSet";
            masterID++;
            List <Reference> refs = new List <Reference>();

            refs.Add(CreateHasTypeDefinition("1:AASLangStrSetType"));

            refs.Add(CreateReference("HasProperty", CreateProperty(lang, "PropertyType", "Language", "String")));
            refs.Add(CreateReference("HasProperty", CreateProperty(str, "PropertyType", "String", "String")));

            ident.References = refs.ToArray();
            root.Add((UANode)ident);
            return(ident.NodeId);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Indicates whether the the inherited parent object is also equal to another object.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        ///   <c>true</c> if the current object is equal to the <paramref name="other">other</paramref>; otherwise,, <c>false</c> otherwise.</returns>
        protected override bool ParentEquals(UANode other)
        {
            UAVariable _other = other as UAVariable;

            if (_other == null)
            {
                return(false);
            }
            return
                (base.ParentEquals(_other) &&
                 //TODO compare Value, Translation
                 this.DataType == _other.DataType &&
                 this.ValueRank == _other.ValueRank &&
                 this.ArrayDimensions == _other.ArrayDimensions &&
                 this.AccessLevel == _other.AccessLevel &&
                 this.UserAccessLevel == _other.UserAccessLevel &&
                 this.MinimumSamplingInterval == _other.MinimumSamplingInterval &&
                 this.Historizing == _other.Historizing);
        }
        private static ReferenceElement setReferenceElement(UANode node)
        {
            //ReferenceElement
            //  -> Value

            ReferenceElement refEle = new ReferenceElement();

            foreach (Reference _ref in node.References)
            {
                if (_ref.ReferenceType != "HasTypeDefinition")
                {
                    UAVariable var = (UAVariable)findNode(_ref.Value);
                    string     val = var.Value.InnerText;
                    //convert String into Reference
                    refEle.value = createReference(val);
                }
            }

            return(refEle);
        }
Ejemplo n.º 21
0
        private static string CreateKey(string idtype, string local, string type, string value)
        {
            UAVariable ident = new UAVariable();

            ident.NodeId     = "ns=1;i=" + masterID.ToString();
            ident.BrowseName = "1:AASKey";
            masterID++;
            List <Reference> refs = new List <Reference>();

            refs.Add(CreateHasTypeDefinition("1:AASKeyType"));

            refs.Add(CreateReference("HasProperty", CreateProperty(idtype, "1:AASKeyType", "IdType", "String")));
            refs.Add(CreateReference("HasProperty", CreateProperty(local, "BaseDataVariableType", "Local", "String")));
            refs.Add(CreateReference("HasProperty", CreateProperty(type, "1:AASPropertyType", "Type", "String")));
            refs.Add(CreateReference("HasProperty", CreateProperty(value, "BaseDataVariableType", "Value", "String")));

            ident.References = refs.ToArray();
            root.Add((UANode)ident);
            return(ident.NodeId);
        }
Ejemplo n.º 22
0
        private static string CreateIdentifiableIdentification(string id, string idtype)
        {
            UAVariable ident = new UAVariable();

            ident.NodeId     = "ns=1;i=" + masterID.ToString();
            ident.BrowseName = "1:Identification";
            masterID++;
            List <Reference> refs = new List <Reference>();

            refs.Add(CreateHasTypeDefinition("1:AASIdentifierType"));

            refs.Add(CreateReference("HasProperty", CreateProperty(id, "PropertyType", "Id", "String")));
            refs.Add(
                CreateReference(
                    "HasProperty", CreateProperty(idtype, "1:AASIdentifierTypeDataType", "IdType", "String")));

            ident.References = refs.ToArray();
            root.Add((UANode)ident);
            return(ident.NodeId);
        }
        private static AdminShellV20.ModelingKind getKind(UANode node)
        {
            //Parent (node)
            // -> Kind (Property)

            ModelingKind kind = new ModelingKind();

            foreach (Reference _ref in node.References)
            {
                if (_ref.ReferenceType != "HasTypeDefinition")
                {
                    UANode val = findNode(_ref.Value);
                    if (getTypeDefinition(val) == "1:AASModelingKindDataType")
                    {
                        UAVariable var = (UAVariable)val;
                        kind.kind = var.Value.InnerText;
                    }
                }
            }
            return(kind);
        }
Ejemplo n.º 24
0
        private static string CreateReferable(string category, List <AdminShellV20.LangStr> langstr)
        {
            UAVariable ident = new UAVariable();

            ident.NodeId     = "ns=1;i=" + masterID.ToString();
            ident.BrowseName = "1:AASReferable";
            masterID++;
            List <Reference> refs = new List <Reference>();

            refs.Add(CreateHasTypeDefinition("1:IAASReferableType"));

            if (langstr != null)
            {
                refs.Add(CreateReference("HasProperty", CreateLangStrContainer(langstr, "Description")));
            }
            refs.Add(CreateReference("HasProperty", CreateProperty(category, "PropertyType", "Category", "String")));

            ident.References = refs.ToArray();
            root.Add((UANode)ident);
            return(ident.NodeId);
        }
        //Create Parameters

        private static string getCategory(UANode node)
        {
            //Parent (node)
            //  -> Category (Property, String)

            string cat = null;

            foreach (Reference _ref in node.References)
            {
                if (_ref.ReferenceType != "HasTypeDefinition")
                {
                    UANode val = findNode(_ref.Value);
                    if (val.BrowseName == "1:Category")
                    {
                        UAVariable var = (UAVariable)val;
                        cat = var.Value.InnerText;
                    }
                }
            }
            return(cat);
        }
Ejemplo n.º 26
0
        private static string CreateIdentifiableAdministration(string version, string revision)
        {
            UAVariable ident = new UAVariable();

            ident.NodeId     = "ns=1;i=" + masterID.ToString();
            ident.BrowseName = "1:Administration";
            masterID++;
            List <Reference> refs = new List <Reference>();

            refs.Add(CreateHasTypeDefinition("1:AASAdministrativeInformationType"));

            refs.Add(
                CreateReference(
                    "HasProperty", CreateProperty(version, "1:AASPropertyType", "Version", "String")));
            refs.Add(
                CreateReference(
                    "HasProperty", CreateProperty(revision, "1:AASPropertyType", "Revision", "String")));

            ident.References = refs.ToArray();
            root.Add((UANode)ident);
            return(ident.NodeId);
        }
Ejemplo n.º 27
0
        private static string createContainedElement(AdminShellV20.ContainedElementRef ele)
        {
            UAVariable var = new UAVariable();

            var.NodeId     = "ns=1;i=" + masterID.ToString();
            var.BrowseName = "1:ContainedElementRef";
            masterID++;
            List <Reference> refs = new List <Reference>();

            refs.Add(CreateHasTypeDefinition("1:AASReferenceType"));

            foreach (AdminShellV20.Key key in ele.Keys)
            {
                refs.Add(
                    CreateReference(
                        "HasComponent", CreateKey(key.idType, key.local.ToString(), key.type, key.value)));
            }

            var.References = refs.ToArray();
            root.Add((UANode)var);
            return(var.NodeId);
        }
Ejemplo n.º 28
0
        public void UpdateWithDifferentNodeIdTest()
        {
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();
            QualifiedName  qualifiedName             = QualifiedName.Parse("EURange");
            IUANodeContext _newNode = new UANodeContext(NodeId.Parse("ns=1;i=11"), _asMock.Object);

            Assert.AreEqual <string>("ns=1;i=11", _newNode.NodeIdContext.ToString());
            UANode _nodeFactory = new UAVariable()
            {
                NodeId       = "ns=1;i=47",
                BrowseName   = "EURange",
                ParentNodeId = "ns=1;i=43",
                DataType     = "i=884",
                DisplayName  = new XML.LocalizedText[] { new XML.LocalizedText()
                                                         {
                                                             Value = "EURange"
                                                         } }
            };

            _newNode.Update(_nodeFactory, x => Assert.Fail()); // Update has different NodeId - no change is expected.
            Assert.AreEqual <string>("ns=1;i=11", _newNode.NodeIdContext.ToString());
            Assert.AreEqual <string>("ns=1;i=47", _newNode.UANode.NodeId);
        }
        private static void addSemanticID(Submodel sub, UAVariable sem)
        {
            foreach (Reference _ref in sem.References)
            {
                if (_ref.ReferenceType != "HasTypeDefinition")
                {
                    UAVariable key  = (UAVariable)findNode(_ref.Value);
                    Key        _key = new Key();
                    foreach (Reference _InnerRef in key.References)
                    {
                        if (_InnerRef.ReferenceType != "HasTypeDefinition")
                        {
                            UAVariable value = (UAVariable)findNode(_InnerRef.Value);
                            switch (value.BrowseName)
                            {
                            case "1:IdType":
                                _key.idType = value.Value.InnerText;
                                break;

                            case "1:Local":
                                _key.local = bool.Parse(value.Value.InnerText);
                                break;

                            case "1:Type":
                                _key.type = value.Value.InnerText;
                                break;

                            case "1:Value":
                                _key.value = value.Value.InnerText;
                                break;
                            }
                        }
                    }
                    sub.semanticId.Keys.Add(_key);
                }
            }
        }
        private static Qualifier getQualifier(UANode node)
        {
            //Qualifier
            // -> QualifierType (Property)
            // -> QualifierValue (Property)
            // -> Key (multiple)

            Qualifier  qual = new Qualifier();
            List <Key> keys = new List <Key>();

            //create Keys
            keys = addSemanticID(node);
            foreach (Reference _ref in node.References)
            {
                if (_ref.ReferenceType != "HasTypeDefinition")
                {
                    if (_ref.ReferenceType == "HasComponent")
                    {
                    }
                    else
                    {
                        UAVariable var = (UAVariable)findNode(_ref.Value);
                        if (var.BrowseName == "1:QualifierType")
                        {
                            qual.type = var.Value.InnerText;
                        }
                        if (var.BrowseName == "1:QualifierValue")
                        {
                            qual.value = var.Value.InnerText;
                        }
                    }
                }
            }
            qual.semanticId = SemanticId.CreateFromKeys(keys);
            return(qual);
        }