Opc.Ua.ServerTest.ServerTestConfiguration.ReplaceNodeList C# (CSharp) Method

ReplaceNodeList() public method

Replaces the test nodes in the list.
public ReplaceNodeList ( IList nodes, IList newNodes, NamespaceTable namespaceUris ) : void
nodes IList
newNodes IList
namespaceUris NamespaceTable
return void
        public void ReplaceNodeList(IList<TestNode> nodes, IList<ILocalNode> newNodes, NamespaceTable namespaceUris)
        {
            nodes.Clear();

            if (newNodes == null)
            {
                return;
            }

            List<string> exportedUris = new List<string>();

            if (NamespaceUris != null)
            {
                exportedUris.AddRange(NamespaceUris);
            }
                
            for (int ii = 0; ii < newNodes.Count; ii++)
            {
                ILocalNode newNode = newNodes[ii];

                NodeId nodeId = newNode.NodeId;

                if (namespaceUris != null && nodeId.NamespaceIndex > 1)
                {
                    string uri = namespaceUris.GetString(nodeId.NamespaceIndex);
                    
                    if (uri != null)
                    {
                        bool found = false;

                        for (int jj = 0; jj < exportedUris.Count; ii++)
                        {
                            if (exportedUris[jj] == uri)
                            {
                                nodeId = new NodeId(nodeId.Identifier, (ushort)(jj+2));
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            exportedUris.Add(uri);
                            nodeId = new NodeId(nodeId.Identifier, (ushort)(exportedUris.Count+1));
                        }
                    }
                }

                TestNode testNode = new TestNode();

                testNode.Id = nodeId.ToString();
                testNode.Name = newNode.BrowseName.ToString();

                nodes.Add(testNode);
            }

            NamespaceUris = new ListOfString();
            NamespaceUris.AddRange(exportedUris);
        }

Usage Example

Exemplo n.º 1
0
        private void Test_BrowseRootsMI_Click(object sender, EventArgs e)
        {
            try
            {
                using (Session session = CreateSession())
                {
                    List <NodeId> nodeIds = m_testConfiguration.GetNodeList(m_testConfiguration.BrowseRoots, session.NamespaceUris);

                    IList <ILocalNode> nodes = new SelectNodesDlg().ShowDialog(session, null, nodeIds);

                    if (nodes != null)
                    {
                        if (m_testConfiguration.BrowseRoots == null)
                        {
                            m_testConfiguration.BrowseRoots = new ListOfTestNode();
                        }

                        m_testConfiguration.ReplaceNodeList(m_testConfiguration.BrowseRoots, nodes, session.NamespaceUris);
                    }
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }