예제 #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);
        }
예제 #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);
        }
예제 #3
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public ServerHostCollection()
        {
            // Get the current host element.
            ServerHostElement host =
                (ServerHostElement)CreateNewElement();

            // Add the element to the collection.
            Add(host);
        }
예제 #4
0
 /// <summary>
 /// Add a new host element type to the collection.
 /// </summary>
 /// <param name="element">The current host element.</param>
 public void Add(ServerHostElement element)
 {
     // Add the element to the base
     // ConfigurationElementCollection type.
     BaseAdd(element);
 }