AsEnumerable() публичный Метод

Retrieves an enumerable key value pair representation of the current configuration.
public AsEnumerable ( ) : HoconValue>>.IEnumerable
Результат HoconValue>>.IEnumerable
Пример #1
0
        /// <summary>
        /// Initializes nginx location configuration from self configuration
        /// </summary>
        /// <param name="host">The parent server configuration</param>
        /// <param name="serviceName">Location name</param>
        /// <param name="config">Section of self configuration, dedicated for the service configuration</param>
        private void InitServiceFromConfiguration(HostConfiguration host, string serviceName, Config config)
        {
            StringBuilder serviceConfig = new StringBuilder();
            foreach (var parameter in config.AsEnumerable())
            {
                if (parameter.Value.IsString())
                {
                    serviceConfig.AppendFormat("\t\t{0} {1};\n", parameter.Key, parameter.Value.GetString());
                }
                else if (parameter.Value.IsArray())
                {
                    var hoconValues = parameter.Value.GetArray();
                    foreach (var hoconValue in hoconValues)
                    {
                        serviceConfig.AppendFormat("\t\t{0} {1};\n", parameter.Key, hoconValue.GetString());
                    }
                }
            }

            // proxy_set_header Host $http_host;
            var headers = config.GetValue("proxy_set_header");
            if (headers == null
                || (headers.IsString()
                    && (headers.GetString() ?? string.Empty).ToLower()
                           .IndexOf("Host ", StringComparison.InvariantCulture) < 0)
                || (headers.IsArray()
                    && headers.GetArray()
                           .Select(v => v.GetString())
                           .All(
                               v =>
                               (v ?? string.Empty).ToLower().IndexOf("Host ", StringComparison.InvariantCulture) < 0)))
            {
                serviceConfig.Append("\t\tproxy_set_header Host $http_host;\n");
            }

            host[serviceName].Config = serviceConfig.ToString();
        }
Пример #2
0
        /// <summary>
        /// Initializes nginx server configuration from self configuration
        /// </summary>
        /// <param name="hostName">Local host identification</param>
        /// <param name="config">Section of self configuration, dedicated for the host configuration</param>
        private void InitHostFromConfiguration(string hostName, Config config)
        {
            StringBuilder hostConfig = new StringBuilder();
            foreach (var parameter in config.AsEnumerable())
            {
                if (parameter.Value.IsString())
                {
                    hostConfig.AppendFormat("\t{0} {1};\n", parameter.Key, parameter.Value.GetString());
                }

                if (parameter.Value.IsObject()
                    && parameter.Key.StartsWith("location ", StringComparison.InvariantCultureIgnoreCase))
                {
                    var serviceName = parameter.Key.Substring("location ".Length).Trim();
                    this.InitServiceFromConfiguration(
                        this.Configuration[hostName],
                        serviceName,
                        parameter.Value.AtKey("Key").GetConfig("Key"));
                }
            }

            this.Configuration[hostName].Config = hostConfig.ToString();
        }