A channel used to read from and write to a given file in the underlying file-system.
Inheritance: IConfigurationSource, IDisposable
Example #1
0
 public static IConfigurationBuilder LoadFile(this IConfigurationBuilder builder, string fileName,
                                              IConfigurationFormatter formatter)
 {
     using (var source = new FileConfigurationSource(fileName)) {
         return(builder.Load(source, formatter));
     }
 }
        public static IConfigurationBuilder LoadFile(this IConfigurationBuilder builder, string fileName,
			IConfigurationFormatter formatter)
        {
            using (var source = new FileConfigurationSource(fileName)) {
                return builder.Load(source, formatter);
            }
        }
        public static ISystemBuilder UseFileConfiguration(this ISystemBuilder builder, string filePath, IConfigurationFormatter formatter)
        {
            var config = new Data.Configuration.Configuration();

            using (var source = new FileConfigurationSource(filePath)) {
                formatter.LoadInto(config, source.InputStream);
            }

            return(builder.UseConfiguration(config));
        }
Example #4
0
        public void LoadProperties()
        {
            var dbConfig = new Configuration();

            var path = Path.Combine(Environment.CurrentDirectory, FileName);
            using (var source = new FileConfigurationSource(path)) {
                dbConfig.Load(source, new PropertiesConfigurationFormatter());
            }

            Assert.AreEqual(2, dbConfig.GetKeys().Count());

            var firstSetting = dbConfig.GetValue("first-setting");
            Assert.IsNotNull(firstSetting);
            Assert.IsInstanceOf<string>(firstSetting);
            Assert.AreEqual("one", firstSetting);

            var secondSetting = dbConfig.GetValue("second");
            Assert.IsNotNull(secondSetting);
            Assert.IsInstanceOf<string>(secondSetting);
            Assert.AreEqual("345.33", secondSetting);
        }
Example #5
0
        public void LoadFromFile_Properties()
        {
            var filePath = Path.Combine(Environment.CurrentDirectory, "db.config");

            var config = new Configuration();

            using (var source = new FileConfigurationSource(filePath)) {
                config.Load(source, new PropertiesConfigurationFormatter());
            }

            Assert.AreEqual(2, config.Count());

            var keys = config.GetKeys().ToArray();

            Assert.IsNotEmpty(keys);
            Assert.AreEqual("system.configKey", keys.First());

            var configValue = config.GetValue("db.name");

            Assert.IsNotNull(configValue);
            Assert.IsInstanceOf <string>(configValue);
            Assert.AreEqual("testdb", (string)configValue);
        }
Example #6
0
        public void LoadProperties()
        {
            var dbConfig = new Configuration();

            var path = Path.Combine(Environment.CurrentDirectory, FileName);

            using (var source = new FileConfigurationSource(path)) {
                dbConfig.Load(source, new PropertiesConfigurationFormatter());
            }

            Assert.AreEqual(2, dbConfig.GetKeys().Count());

            var firstSetting = dbConfig.GetValue("first-setting");

            Assert.IsNotNull(firstSetting);
            Assert.IsInstanceOf <string>(firstSetting);
            Assert.AreEqual("one", firstSetting);

            var secondSetting = dbConfig.GetValue("second");

            Assert.IsNotNull(secondSetting);
            Assert.IsInstanceOf <string>(secondSetting);
            Assert.AreEqual("345.33", secondSetting);
        }
		public static void Save(this IConfiguration config, ConfigurationLevel level, string fileName, IConfigurationFormatter formatter) {
			using (var source = new FileConfigurationSource(fileName)) {
				config.Save(source, level, formatter);
			}
		}
Example #8
0
        public void LoadFromFile_Properties()
        {
            var filePath = Path.Combine(Environment.CurrentDirectory, "db.config");

            var config = new Configuration();
            using (var source = new FileConfigurationSource(filePath)) {
                config.Load(source, new PropertiesConfigurationFormatter());
            }

            Assert.AreEqual(2, config.Count());

            var keys = config.GetKeys().ToArray();
            Assert.IsNotEmpty(keys);
            Assert.AreEqual("system.configKey", keys.First());

            var configValue = config.GetValue("db.name");
            Assert.IsNotNull(configValue);
            Assert.IsInstanceOf<string>(configValue);
            Assert.AreEqual("testdb", (string)configValue);
        }