/// <summary> /// execute command /// </summary> /// <param name="cmds">commands</param> /// <returns>date numbers </returns> public async Task <int> ExecuteAsync(params ICommand[] cmds) { if (cmds.IsNullOrEmpty()) { return(0); } Dictionary <string, List <ICommand> > commandGroup = new Dictionary <string, List <ICommand> >(); Dictionary <string, ServerInfo> serverInfos = new Dictionary <string, ServerInfo>(); #region get database servers foreach (var cmd in cmds) { var servers = await GetServerAsync(cmd).ConfigureAwait(false); foreach (var server in servers) { string serverKey = server.Key; if (serverInfos.ContainsKey(serverKey)) { commandGroup[serverKey].Add(cmd); } else { commandGroup.Add(serverKey, new List <ICommand>() { cmd }); serverInfos.Add(serverKey, server); } } } #endregion #region verify database server engine IEnumerable <ServerType> serverTypeList = serverInfos.Values.Select(c => c.ServerType).Distinct(); VerifyServerEngine(serverTypeList.ToArray()); #endregion #region execute commands int totalVal = 0; foreach (var cmdGroup in commandGroup) { ServerInfo serverInfo = serverInfos[cmdGroup.Key]; IDbEngine engine = DataManager.DbEngines[serverInfo.ServerType]; totalVal += await engine.ExecuteAsync(serverInfo, cmdGroup.Value.ToArray()).ConfigureAwait(false); } return(totalVal); #endregion }