private void UpdateServers()
        {
            ServersLV.Items.Clear();

            // 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.ServerName);
                item.SubItems.Add(server.ServerUrl);
                item.Tag = server;

                ServersLV.Items.Add(item);
            }

            for (int ii = 0; ii < ServersLV.Columns.Count; ii++)
            {
                ServersLV.Columns[ii].Width = -2;
            }
        }
        private void RemoveBTN_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.
                int index = FindServer(wrapperConfig, (ComClientConfiguration)ServersLV.SelectedItems[0].Tag);

                if (index < 0)
                {
                    return;
                }

                // update the configuration.
                wrapperConfig.WrappedServers.RemoveAt(index);
                m_configuration.UpdateExtension<ComWrapperServerConfiguration>(null, wrapperConfig);
                m_configuration.SaveToFile(m_configuration.SourceFilePath);
                ServersLV.SelectedItems[0].Remove();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the node managers for the server.
        /// </summary>
        /// <remarks>
        /// This method allows the sub-class create any additional node managers which it uses. The SDK
        /// always creates a CoreNodeManager which handles the built-in nodes defined by the specification.
        /// Any additional NodeManagers are expected to handle application specific nodes.
        /// </remarks>
        protected override MasterNodeManager CreateMasterNodeManager(IServerInternal server, ApplicationConfiguration configuration)
        {
            List <INodeManager> nodeManagers = new List <INodeManager>();

            m_availableLocales = new List <string>();

            // get the configuration for the wrapper.
            ComWrapperServerConfiguration wrapperConfiguration = configuration.ParseExtension <ComWrapperServerConfiguration>();

            if (wrapperConfiguration != null && wrapperConfiguration.WrappedServers != null)
            {
                // create a new node manager for each wrapped COM server.
                bool loadTypeModel = true;
                Dictionary <string, ComClientConfiguration> namespaceUris = new Dictionary <string, ComClientConfiguration>();

                foreach (ComClientConfiguration clientConfiguration in wrapperConfiguration.WrappedServers)
                {
                    // add the available locales.
                    if (clientConfiguration.AvailableLocales != null && clientConfiguration.AvailableLocales.Count > 0)
                    {
                        foreach (string locale in clientConfiguration.AvailableLocales)
                        {
                            try
                            {
                                CultureInfo culture = CultureInfo.GetCultureInfo(locale);

                                if (!m_availableLocales.Contains(culture.Name))
                                {
                                    m_availableLocales.Add(culture.Name);
                                }
                            }
                            catch (Exception e)
                            {
                                Utils.Trace(e, "Can't process an invalid locale: {0}.", locale);
                            }
                        }
                    }

                    string namespaceUri = clientConfiguration.ServerUrl;

                    if (clientConfiguration is ComDaClientConfiguration)
                    {
                        namespaceUri += "/DA";

                        if (namespaceUris.ContainsKey(namespaceUri))
                        {
                            Utils.Trace("COM server has already been wrapped {0}.", namespaceUri);
                            continue;
                        }

                        namespaceUris.Add(namespaceUri, clientConfiguration);

                        ComDaClientNodeManager manager = new ComDaClientNodeManager(
                            server,
                            namespaceUri,
                            (ComDaClientConfiguration)clientConfiguration,
                            loadTypeModel);

                        nodeManagers.Add(manager);
                        loadTypeModel = false;
                        continue;
                    }

                    if (clientConfiguration is ComAeClientConfiguration)
                    {
                        namespaceUri += "/AE";

                        if (namespaceUris.ContainsKey(namespaceUri))
                        {
                            Utils.Trace("COM server has already been wrapped {0}.", namespaceUri);
                            continue;
                        }

                        namespaceUris.Add(namespaceUri, clientConfiguration);

                        ComAeClientNodeManager manager = new ComAeClientNodeManager(
                            server,
                            namespaceUri,
                            (ComAeClientConfiguration)clientConfiguration,
                            loadTypeModel);

                        nodeManagers.Add(manager);
                        loadTypeModel = false;
                        continue;
                    }

                    if (clientConfiguration is ComHdaClientConfiguration)
                    {
                        namespaceUri += "/HDA";

                        if (namespaceUris.ContainsKey(namespaceUri))
                        {
                            Utils.Trace("COM server has already been wrapped {0}.", namespaceUri);
                            continue;
                        }

                        namespaceUris.Add(namespaceUri, clientConfiguration);

                        ComHdaClientNodeManager manager = new ComHdaClientNodeManager(
                            server,
                            namespaceUri,
                            (ComHdaClientConfiguration)clientConfiguration,
                            loadTypeModel);

                        nodeManagers.Add(manager);
                        loadTypeModel = false;
                        continue;
                    }
                }
            }

            // create master node manager.
            return(new MasterNodeManager(server, configuration, null, nodeManagers.ToArray()));
        }
        private int FindServer(ComWrapperServerConfiguration configuration, ComClientConfiguration server)
        {
            for (int ii = 0; ii < configuration.WrappedServers.Count; ii++)
            {
                if (server.GetType().Name != configuration.WrappedServers[ii].GetType().Name)
                {
                    continue;
                }

                if (configuration.WrappedServers[ii].ServerUrl == server.ServerUrl)
                {
                    return ii;
                }
            }

            return -1;
        }
Exemplo n.º 5
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();
                }

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