Beispiel #1
0
        public object Clone()
        {
            ConfigSource config = (ConfigSource)Activator.CreateInstance(GetType());

            foreach (KeyValuePair <string, string> pair in keyValues)
            {
                config.SetValue(pair.Key, pair.Value);
            }
            foreach (ConfigSource child in children)
            {
                config.children.Add((ConfigSource)child.Clone());
            }
            return(config);
        }
Beispiel #2
0
        private static string CreateMessage(ConfigSource config, string key)
        {
            string message;

            if (!String.IsNullOrEmpty(key))
            {
                message = "A configuration error occurred at source '" + config.FullName + "' on key '" + key + "'.";
            }
            else
            {
                message = "A configuration error occurred at source '" + config.FullName + "'";
            }

            return(message);
        }
        public void StructuredProperties()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("test.me = pass");
            sb.AppendLine("test.two = ed");
            sb.AppendLine("stress.it.to.the.max = 200");
            sb.AppendLine("stress.it.again = 23d");

            ConfigSource source = new ConfigSource();

            source.LoadProperties(GetStream(sb));

            Assert.AreEqual(2, source.GetChild("test").Keys.Length);
            Assert.AreEqual("ed", source.GetChild("test").GetString("two"));
        }
        public void SimpleProperties()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("test=passed");
            sb.AppendLine("me=spaced value");

            ConfigSource source = new ConfigSource();

            source.LoadProperties(GetStream(sb));

            Assert.AreEqual("test", source.Keys[0]);
            Assert.AreEqual("me", source.Keys[1]);
            Assert.AreEqual("passed", source.GetString("test"));
            Assert.AreEqual("spaced value", source.GetString("me"));
        }
Beispiel #5
0
        public bool HasValue(string key)
        {
            int index = key.IndexOf('.');

            if (index != -1)
            {
                string       childName = key.Substring(0, index);
                ConfigSource child     = GetChild(childName);
                if (child == null)
                {
                    throw new ArgumentException("The child '" + childName + "' was not found.");
                }

                key = key.Substring(index + 1);
                return(child.HasValue(key));
            }

            return(keyValues.ContainsKey(key));
        }
Beispiel #6
0
        public void LoadProperties()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("test=23");
            sb.AppendLine("test.foo=12");
            sb.AppendLine("test.bar=test");
            Stream input = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString()));

            ConfigSource config = new ConfigSource();

            config.LoadProperties(input);

            Assert.AreEqual(1, config.Keys.Length);
            Assert.AreEqual("test", config.Keys[0]);
            Assert.AreEqual(2, config.GetChild("test").Keys.Length);
            Assert.AreEqual("foo", config.GetChild("test").Keys[0]);
            Assert.AreEqual("bar", config.GetChild("test").Keys[1]);
            Assert.AreEqual(12, config.GetChild("test").GetInt32("foo"));
            Assert.AreEqual("test", config.GetChild("test").GetString("bar"));
        }
 public void Save(ConfigSource config, System.IO.Stream output)
 {
     throw new NotImplementedException();
 }
 public void Load(ConfigSource config, System.IO.Stream input)
 {
     throw new NotImplementedException();
 }
        private static void SetChildValues(Util.Properties properties, string prefix, ConfigSource config)
        {
            prefix += config.Name;

            foreach (string key in config.Keys)
            {
                string value = config.GetString(key, null);
                if (String.IsNullOrEmpty(value))
                {
                    continue;
                }

                properties.SetProperty(prefix + "." + key, value);
            }

            foreach (ConfigSource child in config.Children)
            {
                SetChildValues(properties, prefix, child);
            }
        }
Beispiel #10
0
 public ConfigurationException(ConfigSource config)
     : this(CreateMessage(config, null))
 {
 }
Beispiel #11
0
 public ConfigurationException(ConfigSource config, string key)
     : this(CreateMessage(config, key), config, key)
 {
 }
Beispiel #12
0
 public ConfigurationException(string message, ConfigSource config)
     : this(message, config, null)
 {
 }
Beispiel #13
0
 public ConfigurationException(string message, ConfigSource config, string key)
     : this(message) {
     this.config = config;
     this.key    = key;
 }
Beispiel #14
0
 private ConfigSource(ConfigSource parent, string name)
     : this(name) {
     this.parent = parent;
 }