/// <summary> /// Resolve table-value by <paramref name="template"/> and <paramref name="tableName"/><br/> /// i.e: With <paramref name="template"/> equal to "tables:{<paramref name="tableName"/>}:globalId" and <paramref name="tableName"/> equal to "Person" (and ie. <paramref name="migrationConfig"/>.GetSchemaPrefixId() (<see cref="IDbConfigSchemaTargets.GetSchemaPrefixId()"/>) returns "EX" <br/> /// => Will search configuration:<br/> /// - "database:migration:tables:Person:globalId"<br/> /// - "database:migration:tables:EXPerson:globalId"<br/> /// - "database:tables:Person:globalId"<br/> /// - "database:tables:EXPerson:globalId"<br/> /// </summary> /// <param name="migrationConfig"></param> /// <param name="template">string template containing {tableName}</param> /// <param name="tableName"></param> /// <param name="fallbackTemplates"></param> /// <returns></returns> public static string GetTableConfigValue(this IDbMigrationConfig migrationConfig, string template, string tableName, params string[] fallbackTemplates) { if (migrationConfig == null) { return(null); } var defaultKey = template.ReplaceIgnoreCase("{tableName}", tableName); var alternativeKey = template.ReplaceIgnoreCase("{tableName}", tableName.TrimPrefixName(migrationConfig.GetSchemaPrefixId())); var alternativeKey2 = template.ReplaceIgnoreCase("{tableName}", tableName.GetPrefixedName(migrationConfig.GetSchemaPrefixId())); var list = new List <string>(new[] { defaultKey, alternativeKey, alternativeKey2 }.Distinct()); if (fallbackTemplates.Any()) { list.AddRange(fallbackTemplates.SelectMany(x => new[] { x.ReplaceIgnoreCase("{tableName}", tableName), x.ReplaceIgnoreCase("{tableName}", tableName.TrimPrefixName(migrationConfig.GetSchemaPrefixId())), x.ReplaceIgnoreCase("{tableName}", tableName.GetPrefixedName(migrationConfig.GetSchemaPrefixId())), }.Distinct())); } var keys = list.Distinct().ToArray(); return(migrationConfig.GetAllMigrationConfigValues()?.GetValue(keys) ?? migrationConfig.GetDbConfig().GetAllDatabaseConfigValues()?.GetValue(keys)); }
/// <summary> /// Fetch config value for <paramref name="key"/> /// </summary> /// <param name="migrationConfig"></param> /// <param name="key"></param> /// <returns></returns> protected string GetConfigValue(IDbMigrationConfig migrationConfig, string key) { if (migrationConfig == null) { return(null); } return(migrationConfig.GetAllMigrationConfigValues()?.GetValue(key) ?? migrationConfig.GetDbConfig().GetAllDatabaseConfigValues()?.GetValue(key)); }