/// <summary> /// Load config from single file or multiple files. /// </summary> /// <param name="envName">"prod"</param> /// <param name="path">"prod.config" or multiple paths delimited by command. /// e.g. "prod.config, qa.config, dev.config"</param> /// <returns></returns> public static IConfigSource LoadFiles(string configDirectory, string configs) { bool hasConfigDir = !string.IsNullOrEmpty(configDirectory); // CASE 1 : File(s) do not exist. if (string.IsNullOrEmpty(configs)) { return(new IniDocument()); } // CASE 2 : single environment, represented with single configuration file. // e.g. "prod", "prod.config". if (!configs.Contains(",")) { // Check file. if (hasConfigDir) { configs = configDirectory + @"\" + configs; } if (!File.Exists(configs)) { return(new IniDocument()); } return(new IniDocument(configs, configs, true, true)); } // CASE 3 : single environment, represented with multiple configuration file. // e.g. "prod", "prod.config, qa.config, dev.config". string[] configPaths = configs.Split(','); var configSources = new List <IConfigSource>(); configPaths.ForEach(configPath => { if (hasConfigDir) { configPath = configDirectory + @"\" + configPath; } if (!File.Exists(configPath)) { throw new FileNotFoundException("Config file : " + configPath + " not found."); } FileInfo configFile = new FileInfo(configPath); configSources.Add(new IniDocument(configFile.Name, configPath, true, true)); }); IConfigSource inheritedConfig = new ConfigSourceMulti(configSources); return(inheritedConfig); }
/// <summary> /// Load config from single file or multiple files. /// </summary> /// <param name="envName">"prod"</param> /// <param name="path">"prod.config" or multiple paths delimited by command. /// e.g. "prod.config, qa.config, dev.config"</param> /// <returns></returns> public static IConfigSource LoadFiles(string path) { // CASE 1 : single environment, represented with single configuration file. // e.g. "prod", "prod.config". if (!path.Contains(",")) { return(new IniDocument(path, path, true, true)); } // CASE 2 : single environment, represented with multiple configuration file. // e.g. "prod", "prod.config, qa.config, dev.config". string[] configPaths = path.Split(','); var configSources = new List <IConfigSource>(); configPaths.ForEach(configPath => { configSources.Add(new IniDocument(configPath, configPath, true, true)); }); IConfigSource inheritedConfig = new ConfigSourceMulti(configSources); return(inheritedConfig); }