Ejemplo n.º 1
0
        /// <summary>
        /// Shows the dialog.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns>True if the configuration was updated.</returns>
        public bool ShowDialogForDelete(ApplicationConfiguration configuration)
        {
            this.Text         = "Select Wrapped COM Server to Delete";
            m_delete          = true;
            m_configuration   = configuration;
            AddressPN.Visible = false;

            // 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();
            }

            // populate the list of wrapped servers.
            for (int ii = 0; ii < wrapperConfig.WrappedServers.Count; ii++)
            {
                ComClientConfiguration server = wrapperConfig.WrappedServers[ii];

                ListViewItem item = new ListViewItem(server.ServerUrl);
                item.SubItems.Add(server.ServerName);
                item.Tag = server;

                ServersLV.Items.Add(item);
            }

            for (int ii = 0; ii < ServersLV.Columns.Count; ii++)
            {
                ServersLV.Columns[ii].Width = -2;
            }

            // show the dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }