TranslateBrowsePaths() public static method

Returns the node ids for a set of relative paths.
public static TranslateBrowsePaths ( Session session, NodeId startNodeId, NamespaceTable namespacesUris ) : List
session Session An open session with the server to use.
startNodeId NodeId The starting node for the relative paths.
namespacesUris NamespaceTable The namespace URIs referenced by the relative paths.
return List
Beispiel #1
0
        /// <summary>
        /// Reads the application description from the GDS.
        /// </summary>
        private ApplicationDescription Read(NodeId nodeId)
        {
            NamespaceTable wellKnownNamespaceUris = new NamespaceTable();

            wellKnownNamespaceUris.Append(Namespaces.OpcUaGds);

            string[] browsePaths = new string[] {
                "1:ApplicationName", "1:ApplicationType", "1:ApplicationUri", "1:ProductUri", "1:GatewayServerUri",
                "1:DiscoveryUrls"
            };

            List <NodeId> propertyIds = ClientUtils.TranslateBrowsePaths(
                ServerCTRL.Session,
                nodeId,
                wellKnownNamespaceUris,
                browsePaths);

            ReadValueIdCollection nodesToRead = new ReadValueIdCollection();

            foreach (NodeId propertyId in propertyIds)
            {
                ReadValueId nodeToRead = new ReadValueId();
                nodeToRead.NodeId      = propertyId;
                nodeToRead.AttributeId = Attributes.Value;
                nodesToRead.Add(nodeToRead);
            }

            DataValueCollection      results         = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            ServerCTRL.Session.Read(
                null,
                0,
                TimestampsToReturn.Neither,
                nodesToRead,
                out results,
                out diagnosticInfos);

            ClientBase.ValidateResponse(results, nodesToRead);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);

            ApplicationDescription application = new ApplicationDescription();

            application.ApplicationName  = results[0].GetValue <LocalizedText>(null);
            application.ApplicationType  = (ApplicationType)results[1].GetValue <int>((int)ApplicationType.Server);
            application.ApplicationUri   = results[2].GetValue <string>(null);
            application.ProductUri       = results[3].GetValue <string>(null);
            application.GatewayServerUri = results[4].GetValue <string>(null);

            string[] discoveryUrls = results[5].GetValue <string[]>(null);

            if (discoveryUrls != null)
            {
                application.DiscoveryUrls = new StringCollection(discoveryUrls);
            }

            return(application);
        }
        /// <summary>
        /// Handles the BeforeExpand event of the BrowseTV control.
        /// </summary>
        private void BrowseTV_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            try
            {
                ReferenceDescription reference = (ReferenceDescription)e.Node.Tag;
                e.Node.Nodes.Clear();

                // build list of references to browse.
                BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection();

                for (int ii = 0; ii < m_referenceTypeIds.Length; ii++)
                {
                    BrowseDescription nodeToBrowse = new BrowseDescription();

                    nodeToBrowse.NodeId          = m_rootId;
                    nodeToBrowse.BrowseDirection = BrowseDirection.Forward;
                    nodeToBrowse.ReferenceTypeId = m_referenceTypeIds[ii];
                    nodeToBrowse.IncludeSubtypes = true;
                    nodeToBrowse.NodeClassMask   = 0;
                    nodeToBrowse.ResultMask      = (uint)BrowseResultMask.All;

                    if (reference != null)
                    {
                        nodeToBrowse.NodeId = (NodeId)reference.NodeId;
                    }

                    nodesToBrowse.Add(nodeToBrowse);
                }

                // add the childen to the control.
                SortedDictionary <ExpandedNodeId, TreeNode> dictionary = new SortedDictionary <ExpandedNodeId, TreeNode>();

                ReferenceDescriptionCollection references = ClientUtils.Browse(m_session, View, nodesToBrowse, false);

                for (int ii = 0; references != null && ii < references.Count; ii++)
                {
                    reference = references[ii];

                    // ignore out of server references.
                    if (reference.NodeId.IsAbsolute)
                    {
                        continue;
                    }

                    if (dictionary.ContainsKey(reference.NodeId))
                    {
                        continue;
                    }

                    TreeNode child = new TreeNode(reference.ToString());

                    child.Nodes.Add(new TreeNode());
                    child.Tag = reference;

                    if (!reference.TypeDefinition.IsAbsolute)
                    {
                        try
                        {
                            if (!m_typeImageMapping.ContainsKey((NodeId)reference.TypeDefinition))
                            {
                                List <NodeId> nodeIds = ClientUtils.TranslateBrowsePaths(m_session, (NodeId)reference.TypeDefinition, m_session.NamespaceUris, Opc.Ua.BrowseNames.Icon);

                                if (nodeIds.Count > 0 && nodeIds[0] != null)
                                {
                                    DataValue value = m_session.ReadValue(nodeIds[0]);
                                    byte[]    bytes = value.Value as byte[];

                                    if (bytes != null)
                                    {
                                        System.IO.MemoryStream istrm = new System.IO.MemoryStream(bytes);
                                        Image icon = Image.FromStream(istrm);
                                        BrowseTV.ImageList.Images.Add(icon);
                                        m_typeImageMapping[(NodeId)reference.TypeDefinition] = BrowseTV.ImageList.Images.Count - 1;
                                    }
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            Utils.Trace(exception, "Error loading image.");
                        }
                    }

                    int index = 0;

                    if (!m_typeImageMapping.TryGetValue((NodeId)reference.TypeDefinition, out index))
                    {
                        child.ImageIndex         = ClientUtils.GetImageIndex(m_session, reference.NodeClass, reference.TypeDefinition, false);
                        child.SelectedImageIndex = ClientUtils.GetImageIndex(m_session, reference.NodeClass, reference.TypeDefinition, true);
                    }
                    else
                    {
                        child.ImageIndex         = index;
                        child.SelectedImageIndex = index;
                    }

                    dictionary[reference.NodeId] = child;
                }

                // add nodes to tree.
                foreach (TreeNode node in dictionary.Values.OrderBy(i => i.Text))
                {
                    e.Node.Nodes.Add(node);
                }
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }