Opc.Ua.Configuration.SelectComServerDlg.OkBTN_Click C# (CSharp) Method

OkBTN_Click() private method

Handles the Click event of the OkBTN control.
private OkBTN_Click ( object sender, EventArgs e ) : void
sender object The source of the event.
e EventArgs The instance containing the event data.
return void
        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();
                }

                // get the selected server.
                Item item = (Item)ServersLV.SelectedItems[0].Tag;

                // create a new new COM client entry for the selected server.
                ComClientConfiguration clientConfig = null;

                if (item.Specification == Specification.Da20 || item.Specification == Specification.Da30)
                {
                    clientConfig = new ComDaClientConfiguration();
                }
                else if (item.Specification == Specification.Ae10)
                {
                    clientConfig = new ComAeClientConfiguration();
                }
                else if (item.Specification == Specification.Hda10)
                {
                    clientConfig = new ComHdaClientConfiguration();
                }

                clientConfig.ServerUrl = item.Server.Url;
                clientConfig.ServerName = item.Server.VersionIndependentProgId;
                clientConfig.MaxReconnectWait = 100000;

                wrapperConfig.WrappedServers.Add(clientConfig);

                // update the configuration.
                m_configuration.UpdateExtension<ComWrapperServerConfiguration>(null, wrapperConfig);

                // close the dialog.
                DialogResult = DialogResult.OK;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }