Esempio n. 1
0
 private static void Indent(StringBuilder sb, Krb5ConfigurationSerializationConfig serializerConfig)
 {
     for (var i = 0; i < serializerConfig.CurrentIndent * serializerConfig.IndentWidth; i++)
     {
         sb.Append(" ");
     }
 }
Esempio n. 2
0
 private static void SerializeValue(StringBuilder sb, string key, object val, Krb5ConfigurationSerializationConfig serializerConfig)
 {
     if (val is ConfigurationSectionList multiVal)
     {
         SerializeValues(sb, key, multiVal, serializerConfig);
     }
     else
     {
         Indent(sb, serializerConfig);
         sb.AppendFormat(CultureInfo.InvariantCulture, "{0} = {1}", key, val);
         sb.AppendLine();
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Serialize a configuration list into a configuration file.
        /// </summary>
        /// <param name="configuration">The configuration to serialize.</param>
        /// <param name="serializerConfig">Optional configuration that describes the format requested.</param>
        /// <returns>Returns the configuration in string form.</returns>
        public static string Serialize(ConfigurationSectionList configuration, Krb5ConfigurationSerializationConfig serializerConfig = null)
        {
            if (configuration is null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (serializerConfig is null)
            {
                serializerConfig = new Krb5ConfigurationSerializationConfig();
            }

            var sb = new StringBuilder();

            foreach (var config in configuration)
            {
                var section = config.Value as ConfigurationSectionList;

                SerializeSection(sb, section, serializerConfig);
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Converts a <see cref="Krb5Config"/> instance into a <see cref="ConfigurationSectionList" /> for possible future serialization.
        /// </summary>
        /// <param name="config">The configuration instance to load</param>
        /// <param name="serializationConfig">Serializer configuration options</param>
        /// <returns>Returns a sectioned version of the configuration</returns>
        public static ConfigurationSectionList FromConfigObject(Krb5Config config, Krb5ConfigurationSerializationConfig serializationConfig)
        {
            if (config is null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (serializationConfig == null)
            {
                serializationConfig = new Krb5ConfigurationSerializationConfig();
            }

            var list = new ConfigurationSectionList();

            foreach (var property in config.GetType().GetProperties(PublicInstancePropertyFlags))
            {
                var section = property.GetValue(config);

                list.Add(AddSection(section, property, serializationConfig));
            }

            return(list);
        }
Esempio n. 5
0
 /// <summary>
 /// Serialize a configuration object instance into a configuration file.
 /// </summary>
 /// <param name="configuration">The configuration to serialize.</param>
 /// <param name="serializationConfig">Optional configuration that describes the format requested.</param>
 /// <returns>Returns the configuration in string form.</returns>
 public static string Serialize(Krb5Config configuration, Krb5ConfigurationSerializationConfig serializationConfig = null)
 {
     return(Serialize(ConfigurationSectionList.FromConfigObject(configuration), serializationConfig));
 }
Esempio n. 6
0
        private static void SerializeValues(StringBuilder sb, string key, ConfigurationSectionList multiVal, Krb5ConfigurationSerializationConfig serializerConfig)
        {
            Indent(sb, serializerConfig);
            sb.AppendFormat(CultureInfo.InvariantCulture, "{0} = {{", key);
            sb.AppendLine();

            serializerConfig.CurrentIndent++;

            foreach (var multi in multiVal)
            {
                var val = multi.Value;

                SerializeValue(sb, multi.Key, val, serializerConfig);
            }

            serializerConfig.CurrentIndent--;

            Indent(sb, serializerConfig);
            sb.AppendLine("}");
        }
Esempio n. 7
0
        private static void SerializeSection(StringBuilder sb, ConfigurationSectionList section, Krb5ConfigurationSerializationConfig serializerConfig)
        {
            sb.AppendFormat(CultureInfo.InvariantCulture, "[{0}]", section.Name);
            sb.AppendLine();

            foreach (var config in section)
            {
                var val = config.Value;

                SerializeValue(sb, config.Key, val, serializerConfig);
            }

            sb.AppendLine();
        }
Esempio n. 8
0
 public string Serialize(Krb5ConfigurationSerializationConfig serializationConfig)
 {
     return(Krb5ConfigurationSerializer.Serialize(this, serializationConfig));
 }