Пример #1
0
 /// <summary>
 /// Handles the setting of the Hostname and FQDNLookup values.
 /// </summary>
 /// <param name="config">The Application Configuration.</param>
 /// <param name="configFile">The conf file content.</param>
 private void MungeHostName(ApplicationConfiguration config, ConfigurationFile configFile)
 {
     if (configFile.ContainsKey(HostnameKey))
     {
         config.Hostname = configFile[HostnameKey];
     }
     else if (configFile.ContainsKey(FQDNookupKey) &&
              configFile[FQDNookupKey].IsTrueString())
     {
         config.Hostname = GetFQDN();
     }
     else
     {
         config.Hostname = Environment.MachineName;
     }
 }
Пример #2
0
        private ApplicationConfiguration ProcessConfig(ConfigurationFile configFile)
        {
            var x = typeof(IConfigurationWhatsit);
            var interestedParties = AppDomain.CurrentDomain.GetAssemblies()
                                             .ToList()
                                             .SelectMany(a => a.GetTypes())
                                             .Where(t => x.IsAssignableFrom(t))
                                             .Where(t => t.IsClass)
                                             .Where(t => !t.IsAbstract);

            var config = new ApplicationConfiguration();
            foreach (var type in interestedParties)
            {
                var instance = (IConfigurationWhatsit)Activator.CreateInstance(type);
                instance.Munge(config, configFile);
            }
            return config;
        }
Пример #3
0
        private void ParseLine(ConfigurationFile config, string line, int lineNumber)
        {
            // TODO: Parse quoted string values
            var space = line.IndexOf(' ');
            var key = line.Substring(0, space);
            var value = line.Substring(space + 1);

            if (key == DirectiveLoadPlugin)
            {
                config.Plugins.Add(value);
                return;
            }

            if (config.ContainsKey(key))
            {
                _log.Debug("Overwriting value for '{0}' at line {1}", key, lineNumber);
            }

            config[key] = value;
        }
Пример #4
0
        public ConfigurationFile Parse(Stream stream)
        {
            var config = new ConfigurationFile();

            using (var reader = new StreamReader(stream))
            {
                int lineNumber = 0;
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    lineNumber++;
                    if (IsConfigLine(line))
                    {
                        ParseLine(config, line, lineNumber);
                    }
                }
            }

            return config;
        }
Пример #5
0
 public void Munge(ApplicationConfiguration config, ConfigurationFile configFile)
 {
     MungeHostName(config, configFile);
 }