A channel used to read from and write to a given file in the underlying file-system.
Inheritance: IConfigurationSource, IDisposable
コード例 #1
0
 public static IConfigurationBuilder LoadFile(this IConfigurationBuilder builder, string fileName,
                                              IConfigurationFormatter formatter)
 {
     using (var source = new FileConfigurationSource(fileName)) {
         return(builder.Load(source, formatter));
     }
 }
コード例 #2
0
        public static IConfigurationBuilder LoadFile(this IConfigurationBuilder builder, string fileName,
			IConfigurationFormatter formatter)
        {
            using (var source = new FileConfigurationSource(fileName)) {
                return builder.Load(source, formatter);
            }
        }
コード例 #3
0
        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));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #7
0
		public static void Save(this IConfiguration config, ConfigurationLevel level, string fileName, IConfigurationFormatter formatter) {
			using (var source = new FileConfigurationSource(fileName)) {
				config.Save(source, level, formatter);
			}
		}
コード例 #8
0
ファイル: DbConfigTests.cs プロジェクト: deveel/deveeldb
        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);
        }