/// <summary> /// Gets the available servers. /// </summary> /// <param name="factory">The factory.</param> /// <param name="specification">The specification.</param> private void GetAvailableServers(Opc.Ua.Com.ServerFactory factory, Specification specification) { Uri[] serverUrls = factory.GetAvailableServers(specification); for (int ii = 0; ii < serverUrls.Length; ii++) { ComServerDescription server = factory.ParseUrl(serverUrls[ii]); // don't wrap proxies. if (ConfigUtils.CLSID_UaComDaProxyServer == server.Clsid) { continue; } if (ConfigUtils.CLSID_UaComAeProxyServer == server.Clsid) { continue; } if (ConfigUtils.CLSID_UaComHdaProxyServer == server.Clsid) { continue; } // don't wrap UA psuedo-servers. List <Guid> catids = ConfigUtils.GetImplementedCategories(server.Clsid); bool suppress = false; for (int jj = 0; jj < catids.Count; jj++) { if (catids[jj] == ConfigUtils.CATID_PseudoComServers) { suppress = true; break; } } if (suppress) { continue; } // assume regular COM server. ListViewItem item = new ListViewItem(server.ProgId); item.SubItems.Add(server.Description); item.SubItems.Add(specification.ToString()); item.Tag = new Item(specification, server); ServersLV.Items.Add(item); } }
/// <summary> /// Updates the list of servers. /// </summary> private void UpdateServers() { // populate the list of servers. Opc.Ua.Com.ServerFactory factory = new ServerFactory(); try { ServersLV.Items.Clear(); string hostName = HostCB.Text; if (HostCB.SelectedIndex != -1) { hostName = (string)HostCB.SelectedItem; } factory.Connect(hostName, null); Uri[] serverUrls = factory.GetAvailableServers(Specification.Da20, Specification.Da30); for (int ii = 0; ii < serverUrls.Length; ii++) { ComServerDescription server = factory.ParseUrl(serverUrls[ii]); ListViewItem item = new ListViewItem(server.ProgId); item.SubItems.Add(server.Description); item.Tag = server; ServersLV.Items.Add(item); } for (int ii = 0; ii < ServersLV.Columns.Count; ii++) { ServersLV.Columns[ii].Width = -2; } } finally { factory.Disconnect(); } }
public Item(Specification specification, ComServerDescription server) { Specification = specification; Server = server; }
/// <summary> /// Handles the Click event of the OkBTN control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void OkBTN_Click(object sender, EventArgs e) { try { if (ServersLV.SelectedItems.Count != 1) { return; } // extract the wrapper configuration from the application configuration. ComWrapperServerConfiguration wrapperConfig = m_configuration.ParseExtension <ComWrapperServerConfiguration>(); if (wrapperConfig == null) { wrapperConfig = new ComWrapperServerConfiguration(); } if (wrapperConfig.WrappedServers == null) { wrapperConfig.WrappedServers = new ComClientConfigurationCollection(); } if (!m_delete) { // get the selected server. ComServerDescription server = (ComServerDescription)ServersLV.SelectedItems[0].Tag; // create a new new COM client entry for the selected server. ComDaClientConfiguration clientConfig = new ComDaClientConfiguration(); clientConfig.ServerUrl = server.Url; clientConfig.ServerName = server.VersionIndependentProgId; clientConfig.MaxReconnectWait = 100000; wrapperConfig.WrappedServers.Add(clientConfig); // update the configuration. m_configuration.UpdateExtension <ComWrapperServerConfiguration>(null, wrapperConfig); } else { // get the selected server. ComDaClientConfiguration server = (ComDaClientConfiguration)ServersLV.SelectedItems[0].Tag; for (int ii = 0; ii < wrapperConfig.WrappedServers.Count; ii++) { if (wrapperConfig.WrappedServers[ii].ServerUrl == server.ServerUrl) { wrapperConfig.WrappedServers.RemoveAt(ii); break; } } // update the configuration. m_configuration.UpdateExtension <ComWrapperServerConfiguration>(null, wrapperConfig); } // close the dialog. DialogResult = DialogResult.OK; } catch (Exception exception) { MessageBox.Show(exception.Message); } }