Exemplo n.º 1
0
        /// <summary>
        /// Gets, the http host collection elements.
        /// </summary>
        /// <param name="section">The config section group and section name.</param>
        /// <returns>The http host collection; else null.</returns>
        public static HttpHostElement[] HttpHostElements(string section = "HttpServerGroup/HttpServerHosts")
        {
            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.
                HttpServerHosts baseHandler =
                    (HttpServerHosts)System.Configuration.ConfigurationManager.GetSection(section);

                // Return the element.
                // Return the collection.
                HttpHostElement[] items = new HttpHostElement[baseHandler.HostSection.Count];
                baseHandler.HostSection.CopyTo(items, 0);
                return(items.Where(q => (q.NameAttribute != "default")).ToArray());
            }
            catch (Exception ex)
            {
                // Log the error.
                LogHandler.WriteTypeMessage(
                    ex.Message,
                    MethodInfo.GetCurrentMethod(),
                    Nequeo.Net.Common.Helper.EventApplicationName);

                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the path prefix.
        /// </summary>
        /// <param name="hostName">The host name to search for.</param>
        /// <param name="section">The config section group and section name.</param>
        /// <returns>The prefix path.</returns>
        public string GetPathPrefix(string hostName, string section = "HttpServerGroup/HttpServerHosts")
        {
            try
            {
                // If no host name set then
                // use the defualt values.
                if (String.IsNullOrEmpty(hostName))
                {
                    // 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.
                    HttpServerHosts defaultHost =
                        (HttpServerHosts)System.Configuration.ConfigurationManager.GetSection(section);

                    // The http html provider path prefix.
                    return(defaultHost.HostSection[hostName].PathAttribute);
                }

                // Return null.
                return(null);
            }
            catch (Exception ex)
            {
                // Log the error.
                LogHandler.WriteTypeMessage(
                    ex.Message,
                    MethodInfo.GetCurrentMethod(),
                    Nequeo.Net.Common.Helper.EventApplicationName);

                return(null);
            }
        }