Ejemplo n.º 1
0
        /// <summary>
        /// Gets the server host elements.
        /// </summary>
        /// <param name="section">The config section group and section name.</param>
        /// <returns>The server host element; else null.</returns>
        public ServerHostElement[] ServerHostElements(string section = "NequeoServerGroup/NequeoServerHosts")
        {
            ServerHostElement[] serverHostElements = null;

            try
            {
                // Refreshes the named section so the next time that it is retrieved it will be re-read from disk.
                System.Configuration.ConfigurationManager.RefreshSection(section);

                // Create a new default host type
                // an load the values from the configuration
                // file into the default host type.
                ServerHosts defaultHost =
                    (ServerHosts)System.Configuration.ConfigurationManager.GetSection(section);

                // Make sure the section is defined.
                if (defaultHost == null)
                {
                    throw new Exception("Configuration section has not been defined.");
                }

                // Return the collection.
                ServerHostElement[] items = new ServerHostElement[defaultHost.HostSection.Count];
                defaultHost.HostSection.CopyTo(items, 0);
                serverHostElements = items.Where(q => (q.Name != "localhost")).ToArray();
            }
            catch (Exception)
            {
                throw;
            }

            // Return the host elements.
            return(serverHostElements);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the server host element.
        /// </summary>
        /// <param name="name">The name of the host.</param>
        /// <param name="section">The config section group and section name.</param>
        /// <returns>The server host element; else null.</returns>
        public ServerHostElement GetServerHost(string name, string section = "NequeoServerGroup/NequeoServerHosts")
        {
            ServerHostElement serverHostElement = null;

            try
            {
                // Refreshes the named section so the next time that it is retrieved it will be re-read from disk.
                System.Configuration.ConfigurationManager.RefreshSection(section);

                // Create a new default host type
                // an load the values from the configuration
                // file into the default host type.
                ServerHosts defaultHost =
                    (ServerHosts)System.Configuration.ConfigurationManager.GetSection(section);

                // Make sure the section is defined.
                if (defaultHost == null)
                {
                    throw new Exception("Configuration section has not been defined.");
                }

                // Get the host element.
                serverHostElement = defaultHost.HostSection[name];
            }
            catch (Exception)
            {
                throw;
            }

            // Return the host element.
            return(serverHostElement);
        }