Exemplo n.º 1
0
        public static async Task <DbConfig> BuildConfig(Task <DbConfig>[] vs, DbConfig[] others, IConnectionStringProvider provider)
        {
            var config = new DbConfig()
            {
                Sqls = new Dictionary <string, DbSql>()
            };
            var css = new Dictionary <string, string>();

            if (others != null)
            {
                foreach (var i in others)
                {
                    i?.ConnectionStrings?.ForEach(x => css.Add(x.Name, x.ConnectionString));
                    i?.SqlConfigs?.ForEach(x => config.Sqls.Add(x.CommandName, x));
                }
            }
            foreach (var i in vs)
            {
                var c = await i;
                c?.ConnectionStrings?.ForEach(x => css.Add(x.Name, x.ConnectionString));
                c?.SqlConfigs?.ForEach(x => config.Sqls.Add(x.CommandName, x));
            }
            if (provider != null)
            {
                provider.Update(css);
            }
            foreach (var item in config.Sqls.Values)
            {
                var connectionString = string.Empty;
                css.TryGetValue(item.ConnectionName, out connectionString);
                item.ConnectionString = connectionString;
            }
            return(config);
        }