Наследование: UAInstance
Пример #1
0
        /// <summary>
        /// Selects the provided node against the selection rules in the node config. In case no rules are specified
        /// the default is to take all nodes.
        /// </summary>
        /// <param name="node"></param>
        /// <returns>true if the node match any of the selection rules, false otherwise.</returns>
        public Boolean selectNode(Opc.Ua.Export.UAVariable node)
        {
            if (skipSelection)
            {
                return(true);
            }

            string target = "";

            switch (_config.targetIdentifier.ToLower())
            {
            case "displayname":
                if (node.DisplayName != null && node.DisplayName[0] != null)
                {
                    target = node.DisplayName[0].Value;
                }
                break;

            case "browsename":
                target = node.BrowseName;
                break;

            case "nodeid":
                target = node.NodeId;
                break;

            default:
                logger.Debug("This should not happen, targetID = {0}", _config.targetIdentifier.ToLower());
                target = "TheseAreNotTheDroidsYouAreLookingFor";
                break;
            }
            return(selectNode(target));
        }
Пример #2
0
 public object convert(object value, Opc.Ua.Export.UANode node)
 {
     if (node.GetType().ToString() == "Opc.Ua.Export.UAVariable")
     {
         Opc.Ua.Export.UAVariable m_node = node as Opc.Ua.Export.UAVariable;
         Type t = TypeInfo.GetSystemType(map[m_node.DataType], ValueRanks.Scalar);
         return(Convert.ChangeType(value, t));
     }
     else
     {
         return(null);
     }
 }
Пример #3
0
        public List <Node> convertToLocalNodeset()
        {
            // FIXME - possibly this function can be deleted

            foreach (Opc.Ua.Export.UANode node in m_UANodeset.Items)
            {
                if (node.BrowseName != "ciao" && (node.DisplayName[0].Value != "ciao"))
                {
                    continue;
                }

                if (node.GetType().ToString() == "Opc.Ua.Export.UAVariable")
                {
                    Opc.Ua.Export.UAVariable xml_node = node as UAVariable;

                    // creating the variableNode
                    VariableNode v_node = new VariableNode();
                    v_node.NodeClass = NodeClass.Variable;

                    // Assign NodeID
                    v_node.NodeId = NodeId.Create(
                        getIdentifier(xml_node.NodeId),
                        getNodeNamespace(xml_node.NodeId),
                        session_namespace
                        );
                    // Assign data type
                    v_node.DataType = get_dataType(xml_node);

                    // Assign Rank and other
                    v_node.ValueRank  = xml_node.ValueRank;
                    v_node.BrowseName = node.BrowseName;
                    if (xml_node.DisplayName != null && xml_node.DisplayName[0] != null)
                    {
                        v_node.DisplayName = xml_node.DisplayName[0].Value;
                    }
                    if (xml_node.Description != null)
                    {
                        v_node.Description = xml_node.Description.ToString();
                    }

                    out_nodeset.Add(v_node);
                }
            }
            return(out_nodeset);
        }
Пример #4
0
        /// <summary>
        /// Imports a node from the set.
        /// </summary>
        private NodeState Import(ISystemContext context, UANode node)
        {
            NodeState importedNode = null;

            NodeClass nodeClass = NodeClass.Unspecified;

            if (node is UAObject)
            {
                nodeClass = NodeClass.Object;
            }
            else if (node is UAVariable)
            {
                nodeClass = NodeClass.Variable;
            }
            else if (node is UAMethod)
            {
                nodeClass = NodeClass.Method;
            }
            else if (node is UAObjectType)
            {
                nodeClass = NodeClass.ObjectType;
            }
            else if (node is UAVariableType)
            {
                nodeClass = NodeClass.VariableType;
            }
            else if (node is UADataType)
            {
                nodeClass = NodeClass.DataType;
            }
            else if (node is UAReferenceType)
            {
                nodeClass = NodeClass.ReferenceType;
            }
            else if (node is UAView)
            {
                nodeClass = NodeClass.View;
            }

            switch (nodeClass)
            {
            case NodeClass.Object:
            {
                UAObject        o     = (UAObject)node;
                BaseObjectState value = new BaseObjectState(null);
                value.EventNotifier = o.EventNotifier;
                importedNode        = value;
                break;
            }

            case NodeClass.Variable:
            {
                UAVariable o = (UAVariable)node;

                NodeId typeDefinitionId = null;

                if (node.References != null)
                {
                    for (int ii = 0; ii < node.References.Length; ii++)
                    {
                        Opc.Ua.NodeId         referenceTypeId = ImportNodeId(node.References[ii].ReferenceType, context.NamespaceUris, true);
                        bool                  isInverse       = !node.References[ii].IsForward;
                        Opc.Ua.ExpandedNodeId targetId        = ImportExpandedNodeId(node.References[ii].Value, context.NamespaceUris, context.ServerUris);

                        if (referenceTypeId == ReferenceTypeIds.HasTypeDefinition && !isInverse)
                        {
                            typeDefinitionId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris);
                            break;
                        }
                    }
                }

                BaseVariableState value = null;

                if (typeDefinitionId == Opc.Ua.VariableTypeIds.PropertyType)
                {
                    value = new PropertyState(null);
                }
                else
                {
                    value = new BaseDataVariableState(null);
                }

                value.DataType                = ImportNodeId(o.DataType, context.NamespaceUris, true);
                value.ValueRank               = o.ValueRank;
                value.ArrayDimensions         = ImportArrayDimensions(o.ArrayDimensions);
                value.AccessLevelEx           = o.AccessLevel;
                value.UserAccessLevel         = (byte)(o.AccessLevel & 0xFF);
                value.MinimumSamplingInterval = o.MinimumSamplingInterval;
                value.Historizing             = o.Historizing;

                if (o.Value != null)
                {
                    XmlDecoder decoder  = CreateDecoder(context, o.Value);
                    TypeInfo   typeInfo = null;
                    value.Value = decoder.ReadVariantContents(out typeInfo);
                    decoder.Close();
                }

                importedNode = value;
                break;
            }

            case NodeClass.Method:
            {
                UAMethod    o     = (UAMethod)node;
                MethodState value = new MethodState(null);
                value.Executable       = o.Executable;
                value.UserExecutable   = o.Executable;
                value.TypeDefinitionId = ImportNodeId(o.MethodDeclarationId, context.NamespaceUris, true);
                importedNode           = value;
                break;
            }

            case NodeClass.View:
            {
                UAView    o     = (UAView)node;
                ViewState value = new ViewState();
                value.ContainsNoLoops = o.ContainsNoLoops;
                importedNode          = value;
                break;
            }

            case NodeClass.ObjectType:
            {
                UAObjectType        o     = (UAObjectType)node;
                BaseObjectTypeState value = new BaseObjectTypeState();
                value.IsAbstract = o.IsAbstract;
                importedNode     = value;
                break;
            }

            case NodeClass.VariableType:
            {
                UAVariableType        o     = (UAVariableType)node;
                BaseVariableTypeState value = new BaseDataVariableTypeState();
                value.IsAbstract      = o.IsAbstract;
                value.DataType        = ImportNodeId(o.DataType, context.NamespaceUris, true);
                value.ValueRank       = o.ValueRank;
                value.ArrayDimensions = ImportArrayDimensions(o.ArrayDimensions);

                if (o.Value != null)
                {
                    XmlDecoder decoder  = CreateDecoder(context, o.Value);
                    TypeInfo   typeInfo = null;
                    value.Value = decoder.ReadVariantContents(out typeInfo);
                    decoder.Close();
                }

                importedNode = value;
                break;
            }

            case NodeClass.DataType:
            {
                UADataType    o     = (UADataType)node;
                DataTypeState value = new DataTypeState();
                value.IsAbstract = o.IsAbstract;
                Opc.Ua.DataTypeDefinition dataTypeDefinition = Import(o, o.Definition, context.NamespaceUris);
                value.DataTypeDefinition = new ExtensionObject(dataTypeDefinition);
                value.Purpose            = o.Purpose;
                value.DataTypeModifier   = DataTypeModifier.None;

                if (o.Definition != null)
                {
                    if (o.Definition.IsOptionSet)
                    {
                        value.DataTypeModifier = DataTypeModifier.OptionSet;
                    }
                    else if (o.Definition.IsUnion)
                    {
                        value.DataTypeModifier = DataTypeModifier.Union;
                    }
                }

                importedNode = value;
                break;
            }

            case NodeClass.ReferenceType:
            {
                UAReferenceType    o     = (UAReferenceType)node;
                ReferenceTypeState value = new ReferenceTypeState();
                value.IsAbstract  = o.IsAbstract;
                value.InverseName = Import(o.InverseName);
                value.Symmetric   = o.Symmetric;
                importedNode      = value;
                break;
            }
            }

            importedNode.NodeId      = ImportNodeId(node.NodeId, context.NamespaceUris, false);
            importedNode.BrowseName  = ImportQualifiedName(node.BrowseName, context.NamespaceUris);
            importedNode.DisplayName = Import(node.DisplayName);

            if (importedNode.DisplayName == null)
            {
                importedNode.DisplayName = new Ua.LocalizedText(importedNode.BrowseName.Name);
            }

            importedNode.Description   = Import(node.Description);
            importedNode.Categories    = (node.Category != null && node.Category.Length > 0) ? node.Category : null;
            importedNode.ReleaseStatus = node.ReleaseStatus;
            importedNode.WriteMask     = (AttributeWriteMask)node.WriteMask;
            importedNode.UserWriteMask = (AttributeWriteMask)node.UserWriteMask;
            importedNode.Extensions    = node.Extensions;

            if (!String.IsNullOrEmpty(node.SymbolicName))
            {
                importedNode.SymbolicName = node.SymbolicName;
            }

            if (node.References != null)
            {
                BaseInstanceState instance = importedNode as BaseInstanceState;
                BaseTypeState     type     = importedNode as BaseTypeState;

                for (int ii = 0; ii < node.References.Length; ii++)
                {
                    Opc.Ua.NodeId         referenceTypeId = ImportNodeId(node.References[ii].ReferenceType, context.NamespaceUris, true);
                    bool                  isInverse       = !node.References[ii].IsForward;
                    Opc.Ua.ExpandedNodeId targetId        = ImportExpandedNodeId(node.References[ii].Value, context.NamespaceUris, context.ServerUris);

                    if (instance != null)
                    {
                        if (referenceTypeId == ReferenceTypeIds.HasModellingRule && !isInverse)
                        {
                            instance.ModellingRuleId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris);
                            continue;
                        }

                        if (referenceTypeId == ReferenceTypeIds.HasTypeDefinition && !isInverse)
                        {
                            instance.TypeDefinitionId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris);
                            continue;
                        }
                    }

                    if (type != null)
                    {
                        if (referenceTypeId == ReferenceTypeIds.HasSubtype && isInverse)
                        {
                            type.SuperTypeId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris);
                            continue;
                        }
                    }

                    importedNode.AddReference(referenceTypeId, isInverse, targetId);
                }
            }

            return(importedNode);
        }
Пример #5
0
        /// <summary>
        /// Adds a node to the set.
        /// </summary>
        public void Export(ISystemContext context, NodeState node, bool outputRedundantNames = true)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (Opc.Ua.NodeId.IsNull(node.NodeId))
            {
                throw new ArgumentException("A non-null NodeId must be specified.");
            }

            UANode exportedNode = null;

            switch (node.NodeClass)
            {
            case NodeClass.Object:
            {
                BaseObjectState o     = (BaseObjectState)node;
                UAObject        value = new UAObject();
                value.EventNotifier = o.EventNotifier;

                if (o.Parent != null)
                {
                    value.ParentNodeId = ExportAlias(o.Parent.NodeId, context.NamespaceUris);
                }

                exportedNode = value;
                break;
            }

            case NodeClass.Variable:
            {
                BaseVariableState o     = (BaseVariableState)node;
                UAVariable        value = new UAVariable();
                value.DataType                = ExportAlias(o.DataType, context.NamespaceUris);
                value.ValueRank               = o.ValueRank;
                value.ArrayDimensions         = Export(o.ArrayDimensions);
                value.AccessLevel             = o.AccessLevelEx;
                value.MinimumSamplingInterval = o.MinimumSamplingInterval;
                value.Historizing             = o.Historizing;

                if (o.Parent != null)
                {
                    value.ParentNodeId = ExportAlias(o.Parent.NodeId, context.NamespaceUris);
                }

                if (o.Value != null)
                {
                    XmlEncoder encoder = CreateEncoder(context);

                    Variant variant = new Variant(o.Value);
                    encoder.WriteVariantContents(variant.Value, variant.TypeInfo);

                    XmlDocument document = new XmlDocument();
                    document.InnerXml = encoder.Close();
                    value.Value       = document.DocumentElement;
                }

                exportedNode = value;
                break;
            }

            case NodeClass.Method:
            {
                MethodState o     = (MethodState)node;
                UAMethod    value = new UAMethod();
                value.Executable = o.Executable;

                if (o.TypeDefinitionId != null && !o.TypeDefinitionId.IsNullNodeId && o.TypeDefinitionId != o.NodeId)
                {
                    value.MethodDeclarationId = Export(o.TypeDefinitionId, context.NamespaceUris);
                }

                if (o.Parent != null)
                {
                    value.ParentNodeId = ExportAlias(o.Parent.NodeId, context.NamespaceUris);
                }

                exportedNode = value;
                break;
            }

            case NodeClass.View:
            {
                ViewState o     = (ViewState)node;
                UAView    value = new UAView();
                value.ContainsNoLoops = o.ContainsNoLoops;
                exportedNode          = value;
                break;
            }

            case NodeClass.ObjectType:
            {
                BaseObjectTypeState o     = (BaseObjectTypeState)node;
                UAObjectType        value = new UAObjectType();
                value.IsAbstract = o.IsAbstract;
                exportedNode     = value;
                break;
            }

            case NodeClass.VariableType:
            {
                BaseVariableTypeState o     = (BaseVariableTypeState)node;
                UAVariableType        value = new UAVariableType();
                value.IsAbstract      = o.IsAbstract;
                value.DataType        = ExportAlias(o.DataType, context.NamespaceUris);
                value.ValueRank       = o.ValueRank;
                value.ArrayDimensions = Export(o.ArrayDimensions);

                if (o.Value != null)
                {
                    XmlEncoder encoder = CreateEncoder(context);

                    Variant variant = new Variant(o.Value);
                    encoder.WriteVariantContents(variant.Value, variant.TypeInfo);

                    XmlDocument document = new XmlDocument();
                    document.InnerXml = encoder.Close();
                    value.Value       = document.DocumentElement;
                }

                exportedNode = value;
                break;
            }

            case NodeClass.DataType:
            {
                DataTypeState o     = (DataTypeState)node;
                UADataType    value = new UADataType();
                value.IsAbstract = o.IsAbstract;
                value.Definition = Export(o, o.DataTypeDefinition, context.NamespaceUris, outputRedundantNames);
                value.Purpose    = o.Purpose;
                exportedNode     = value;
                break;
            }

            case NodeClass.ReferenceType:
            {
                ReferenceTypeState o     = (ReferenceTypeState)node;
                UAReferenceType    value = new UAReferenceType();
                value.IsAbstract = o.IsAbstract;

                if (!Opc.Ua.LocalizedText.IsNullOrEmpty(o.InverseName))
                {
                    value.InverseName = Export(new Opc.Ua.LocalizedText[] { o.InverseName });
                }

                value.Symmetric = o.Symmetric;
                exportedNode    = value;
                break;
            }
            }

            exportedNode.NodeId     = Export(node.NodeId, context.NamespaceUris);
            exportedNode.BrowseName = Export(node.BrowseName, context.NamespaceUris);

            if (outputRedundantNames || node.DisplayName.Text != node.BrowseName.Name)
            {
                exportedNode.DisplayName = Export(new Opc.Ua.LocalizedText[] { node.DisplayName });
            }
            else
            {
                exportedNode.DisplayName = null;
            }

            if (node.Description != null && !String.IsNullOrEmpty(node.Description.Text))
            {
                exportedNode.Description = Export(new Opc.Ua.LocalizedText[] { node.Description });
            }
            else
            {
                exportedNode.Description = new LocalizedText[0];
            }

            exportedNode.Category      = (node.Categories != null && node.Categories.Count > 0) ? new List <string>(node.Categories).ToArray() : null;
            exportedNode.ReleaseStatus = node.ReleaseStatus;
            exportedNode.WriteMask     = (uint)node.WriteMask;
            exportedNode.UserWriteMask = (uint)node.UserWriteMask;
            exportedNode.Extensions    = node.Extensions;

            if (!String.IsNullOrEmpty(node.SymbolicName) && node.SymbolicName != node.BrowseName.Name)
            {
                exportedNode.SymbolicName = node.SymbolicName;
            }

            // export references.
            INodeBrowser     browser            = node.CreateBrowser(context, null, null, true, BrowseDirection.Both, null, null, true);
            List <Reference> exportedReferences = new List <Reference>();
            IReference       reference          = browser.Next();

            while (reference != null)
            {
                if (node.NodeClass == NodeClass.Method)
                {
                    if (!reference.IsInverse && reference.ReferenceTypeId == ReferenceTypeIds.HasTypeDefinition)
                    {
                        reference = browser.Next();
                        continue;
                    }
                }

                Reference exportedReference = new Reference();

                exportedReference.ReferenceType = ExportAlias(reference.ReferenceTypeId, context.NamespaceUris);
                exportedReference.IsForward     = !reference.IsInverse;
                exportedReference.Value         = Export(reference.TargetId, context.NamespaceUris, context.ServerUris);
                exportedReferences.Add(exportedReference);

                reference = browser.Next();
            }

            exportedNode.References = exportedReferences.ToArray();

            // add node to list.
            UANode[] nodes = null;

            int count = 1;

            if (this.Items == null)
            {
                nodes = new UANode[count];
            }
            else
            {
                count += this.Items.Length;
                nodes  = new UANode[count];
                Array.Copy(this.Items, nodes, this.Items.Length);
            }

            nodes[count - 1] = exportedNode;

            this.Items = nodes;

            // recusively process children.
            List <BaseInstanceState> children = new List <BaseInstanceState>();

            node.GetChildren(context, children);

            for (int ii = 0; ii < children.Count; ii++)
            {
                Export(context, children[ii], outputRedundantNames);
            }
        }
Пример #6
0
        /// <summary>
        /// Adds a node to the set.
        /// </summary>
        public void Export(ISystemContext context, NodeState node)
        {
            if (node == null) throw new ArgumentNullException("node");

            if (Opc.Ua.NodeId.IsNull(node.NodeId))
            {
                throw new ArgumentException("A non-null NodeId must be specified.");
            }

            UANode exportedNode = null;

            switch (node.NodeClass)
            {
                case NodeClass.Object:
                {
                    BaseObjectState o = (BaseObjectState)node;
                    UAObject value = new UAObject();
                    value.EventNotifier = o.EventNotifier;

                    if (o.Parent != null)
                    {
                        value.ParentNodeId = ExportAlias(o.Parent.NodeId, context.NamespaceUris);
                    }

                    exportedNode = value;
                    break;
                }

                case NodeClass.Variable:
                {
                    BaseVariableState o = (BaseVariableState)node;
                    UAVariable value = new UAVariable();
                    value.DataType = ExportAlias(o.DataType, context.NamespaceUris);
                    value.ValueRank = o.ValueRank;
                    value.ArrayDimensions = Export(o.ArrayDimensions);
                    value.AccessLevel = o.AccessLevel;
                    value.UserAccessLevel = o.UserAccessLevel;
                    value.MinimumSamplingInterval = o.MinimumSamplingInterval;
                    value.Historizing = o.Historizing;

                    if (o.Parent != null)
                    {
                        value.ParentNodeId = ExportAlias(o.Parent.NodeId, context.NamespaceUris);
                    }

                    if (o.Value != null)
                    {
                        XmlEncoder encoder = CreateEncoder(context);

                        Variant variant = new Variant(o.Value);
                        encoder.WriteVariantContents(variant.Value, variant.TypeInfo);

                        XmlDocument document = new XmlDocument();
                        document.InnerXml = encoder.Close();
                        value.Value = document.DocumentElement;
                    }

                    exportedNode = value;                 
                    break;
                }

                case NodeClass.Method:
                {
                    MethodState o = (MethodState)node;
                    UAMethod value = new UAMethod();
                    value.Executable = o.Executable;
                    value.UserExecutable = o.UserExecutable;

                    if (o.Parent != null)
                    {
                        value.ParentNodeId = ExportAlias(o.Parent.NodeId, context.NamespaceUris);
                    }

                    exportedNode = value;
                    break;
                }

                case NodeClass.View:
                {
                    ViewState o = (ViewState)node;
                    UAView value = new UAView();
                    value.ContainsNoLoops = o.ContainsNoLoops;
                    exportedNode = value;
                    break;
                }

                case NodeClass.ObjectType:
                {
                    BaseObjectTypeState o = (BaseObjectTypeState)node;
                    UAObjectType value = new UAObjectType();
                    value.IsAbstract = o.IsAbstract;
                    exportedNode = value;
                    break;
                }

                case NodeClass.VariableType:
                {
                    BaseVariableTypeState o = (BaseVariableTypeState)node;
                    UAVariableType value = new UAVariableType();
                    value.IsAbstract = o.IsAbstract;
                    value.DataType = ExportAlias(o.DataType, context.NamespaceUris);
                    value.ValueRank = o.ValueRank;
                    value.ArrayDimensions = Export(o.ArrayDimensions);

                    if (o.Value != null)
                    {
                        XmlEncoder encoder = CreateEncoder(context);

                        Variant variant = new Variant(o.Value);
                        encoder.WriteVariantContents(variant.Value, variant.TypeInfo);

                        XmlDocument document = new XmlDocument();
                        document.InnerXml = encoder.Close();
                        value.Value = document.DocumentElement;
                    }

                    exportedNode = value;
                    break;
                }

                case NodeClass.DataType:
                {
                    DataTypeState o = (DataTypeState)node;
                    UADataType value = new UADataType();
                    value.IsAbstract = o.IsAbstract;
                    value.Definition = Export(o.Definition, context.NamespaceUris);
                    exportedNode = value;
                    break;
                }

                case NodeClass.ReferenceType:
                {
                    ReferenceTypeState o = (ReferenceTypeState)node;
                    UAReferenceType value = new UAReferenceType();
                    value.IsAbstract = o.IsAbstract;
                    value.InverseName = Export(new Opc.Ua.LocalizedText[] { o.InverseName });
                    value.Symmetric = o.Symmetric;
                    exportedNode = value;
                    break;
                }
            }

            exportedNode.NodeId = Export(node.NodeId, context.NamespaceUris);
            exportedNode.BrowseName = Export(node.BrowseName, context.NamespaceUris);
            exportedNode.DisplayName = Export(new Opc.Ua.LocalizedText[] { node.DisplayName });
            exportedNode.Description = Export(new Opc.Ua.LocalizedText[] { node.Description });
            exportedNode.WriteMask = (uint)node.WriteMask;
            exportedNode.UserWriteMask = (uint)node.UserWriteMask;

            if (!String.IsNullOrEmpty(node.SymbolicName) && node.SymbolicName != node.BrowseName.Name)
            {
                exportedNode.SymbolicName = node.SymbolicName;
            }

            // export references.
            INodeBrowser browser = node.CreateBrowser(context, null, null, true, BrowseDirection.Both, null, null, true);
            List<Reference> exportedReferences = new List<Reference>();            
            IReference reference = browser.Next();

            while (reference != null)
            {
                Reference exportedReference = new Reference();

                exportedReference.ReferenceType = ExportAlias(reference.ReferenceTypeId, context.NamespaceUris);
                exportedReference.IsForward = !reference.IsInverse;
                exportedReference.Value = Export(reference.TargetId, context.NamespaceUris, context.ServerUris);
                exportedReferences.Add(exportedReference);

                reference = browser.Next();
            }

            exportedNode.References = exportedReferences.ToArray();

            // add node to list.
            UANode[] nodes = null;

            int count = 1;

            if (this.Items == null)
            {
                nodes = new UANode[count];
            }
            else
            {
                count += this.Items.Length;
                nodes = new UANode[count];
                Array.Copy(this.Items, nodes, this.Items.Length);
            }

            nodes[count-1] = exportedNode;

            this.Items = nodes;

            // recusively process children.
            List<BaseInstanceState> children = new List<BaseInstanceState>();
            node.GetChildren(context, children);

            for (int ii = 0; ii < children.Count; ii++)
            {
                Export(context, children[ii]);
            }
        }
Пример #7
0
        public void fillCacheDB(cacheDB db)
        {
            if (m_UANodeset == null || m_UANodeset.Items.Length == 0)
            {
                throw new Exception("No UA nodes loaded");
            }

            // fill the namespace in DB
            logger.Debug("filling cache DB ");
            for (int k = 0; k < m_namespaceURIs.Length; k++)
            {
                dbNamespace ns = new dbNamespace {
                    internalIndex      = k,
                    URI                = m_namespaceURIs[k],
                    currentServerIndex = -1
                };
                logger.Debug("filling cache --- inserting : " + k);

                db.namespaces.Insert(ns);
            }
            logger.Debug("filling cache DB End ");

            // connect the server index to the corresponding xml_index
            db.updateNamespace(session_namespace);

            foreach (Opc.Ua.Export.UANode node in m_UANodeset.Items)
            {
                if (node.GetType().ToString() != "Opc.Ua.Export.UAVariable")
                {
                    continue;
                }

                Opc.Ua.Export.UAVariable xml_node = node as UAVariable;

                // Apply userdefined matching criteria
                if (!selector.selectNode(xml_node))
                {
                    continue;
                }

                // creating the variableNode
                dbNode db_node = new dbNode();
                db_node.classType = node.GetType().ToString();

                // Assign NodeID
                db_node.identifier = getIdentifierToString(xml_node.NodeId);
                // Assign data type
                db_node.systemType = get_systemDataType(xml_node);
                // Assign internal index
                db_node.internalIndex = ((int)getNodeNamespaceIndex(xml_node.NodeId));

                // Assign Rank and other
                // FIXME
                //db_node.ValueRank   = xml_node.ValueRank;
                if (xml_node.ValueRank > 1)
                {
                    logger.Error("Arrays are not supported yet. Skip Node: " + node.BrowseName);
                    continue;
                }
                // skipping not built in types... FIXME
                if (!db_node.systemType.StartsWith("System") || db_node.systemType.ToLower() == "null")
                {
                    logger.Error("Only System types are supported for now. Skip Node: " + node.BrowseName + "  type: " + db_node.systemType);
                    continue;
                }

                // assign user defined target name
                switch (_config.targetIdentifier.ToLower())
                {
                case "displayname":
                    if (xml_node.DisplayName != null && xml_node.DisplayName[0] != null)
                    {
                        db_node.name = node.DisplayName[0].Value;
                    }
                    else
                    {
                        logger.Error("Node: " + node.BrowseName + "  does not have DisplayName, using browseName instead");
                        db_node.name = node.BrowseName;
                    }
                    break;

                case "browsename":
                    db_node.name = node.BrowseName;
                    break;

                case "nodeid":
                    db_node.name = node.NodeId;
                    break;

                default:
                    logger.Fatal("This should not happen, targetID = {0}", _config.targetIdentifier.ToLower());
                    throw new Exception("targetID not allowed");
                }

                // Adding node to cache DB
                db.insertNodeIfNotExist(db_node);
            }
        }
Пример #8
0
        public void fillCacheDB(cacheDB db)
        {
            if (m_UANodeset == null || m_UANodeset.Items.Length == 0)
            {
                throw new Exception("No UA nodes loaded");
            }

            // fill the namespace in DB
            logger.Debug("filling cache DB ");
            for (int k = 0; k < m_namespaceURIs.Length; k++)
            {
                dbNamespace ns = new dbNamespace {
                    internalIndex      = k,
                    URI                = m_namespaceURIs[k],
                    currentServerIndex = -1
                };
                logger.Debug("filling cache --- inserting : " + k);

                db.namespaces.Insert(ns);
            }
            logger.Debug("filling cache DB End ");

            // connect the server index to the corresponding xml_index
            db.updateNamespace(session_namespace);

            foreach (Opc.Ua.Export.UANode node in m_UANodeset.Items)
            {
                if (node.GetType().ToString() == "Opc.Ua.Export.UAVariable")
                {
                    bool skip = false;

                    Opc.Ua.Export.UAVariable xml_node = node as UAVariable;

                    // creating the variableNode
                    dbNode db_node = new dbNode();
                    db_node.classType = node.GetType().ToString();

                    // Assign NodeID
                    db_node.identifier = getIdentifierToString(xml_node.NodeId);
                    // Assign data type
                    db_node.systemType = get_systemDataType(xml_node);
                    // Assign internal index
                    db_node.internalIndex = ((int)getNodeNamespaceIndex(xml_node.NodeId));

                    // Assign Rank and other
                    // FIXME
                    //db_node.ValueRank   = xml_node.ValueRank;
                    if (xml_node.ValueRank > 1)
                    {
                        skip = true;
                        logger.Error("Arrays are not supported yet. Skip Node: " + node.BrowseName);
                    }
                    // skipping not built in types... FIXME
                    if (!db_node.systemType.StartsWith("System"))
                    {
                        skip = true;
                        logger.Error("Only System types are supported for now. Skip Node: " + node.BrowseName + "  type: " + db_node.systemType);
                    }
                    if (xml_node.DisplayName != null && xml_node.DisplayName[0] != null)
                    {
                        db_node.name = node.DisplayName[0].Value;
                    }
                    else
                    {
                        db_node.name = node.BrowseName;
                        logger.Warn("Node: " + node.BrowseName + "  does not have DisplayName, using browseName instead");
                    }

                    if (db_node.systemType.ToLower() != "null" && !skip)
                    {
                        db.nodes.Insert(db_node);
                    }
                }
            }
        }