/// <summary> /// Browses for computers on the network. /// </summary> private void BrowseNetwork(TreeNode node) { try { // clear current contents. node.Nodes.Clear(); IOpcDiscovery discovery = new OpcClientSdk.Com.ServerEnumerator(); string[] hosts = discovery.EnumerateHosts(); // add children. if (hosts != null) { foreach (string host in hosts) { TreeNode child = new TreeNode(host); child.ImageIndex = child.SelectedImageIndex = Resources.IMAGE_LOCAL_COMPUTER; child.Tag = null; child.Nodes.Add(new TreeNode()); node.Nodes.Add(child); } node.Expand(); } } catch (Exception e) { MessageBox.Show(e.Message); } }
/// <summary> /// Browses for servers a computer. /// </summary> private void BrowseServers(TreeNode node) { try { // clear current contents. node.Nodes.Clear(); // get the host name. string host = null; if (node != m_localServers) { host = node.Text; } // get default login information. OpcConnectData connectData = FindConnectData(node); // find the servers. List <OpcServer> servers; OpcUserIdentity userIdentity; if (connectData == null || connectData.UserIdentity == null) { userIdentity = null; } else { userIdentity = connectData.UserIdentity; } // find the servers. IOpcDiscovery discovery = new OpcClientSdk.Com.ServerEnumerator(); servers = discovery.GetAvailableServers(m_specification, host, connectData).ToList(); // add children. if (servers != null) { foreach (OpcServer server in servers) { TreeNode child = new TreeNode(server.ServerName); child.ImageIndex = child.SelectedImageIndex = Resources.IMAGE_LOCAL_SERVER; child.Tag = server; node.Nodes.Add(child); } node.Expand(); } } catch (Exception e) { MessageBox.Show(e.Message); } }