Example #1
0
        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="executeOptions">Execute options</param>
        /// <param name="commandExecutorGroup">Command executor group</param>
        /// <returns>Return the execute data effect numbers</returns>
        internal static async Task <int> ExecuteAsync(CommandExecuteOptions executeOptions, IEnumerable <Tuple <ICommandExecutor, List <ICommand> > > commandExecutorGroup)
        {
            if (commandExecutorGroup.IsNullOrEmpty())
            {
                return(0);
            }
            var groupCount = commandExecutorGroup.Count();

            //Single executor
            if (groupCount == 1)
            {
                var firstGroup = commandExecutorGroup.First();
                return(await firstGroup.Item1.ExecuteAsync(executeOptions, firstGroup.Item2).ConfigureAwait(false));
            }

            //Multiple executor
            Task <int>[] valueTasks = new Task <int> [groupCount];
            var          groupIndex = 0;

            foreach (var executorGroupItem in commandExecutorGroup)
            {
                valueTasks[groupIndex] = executorGroupItem.Item1.ExecuteAsync(executeOptions, executorGroupItem.Item2);
                groupIndex++;
            }
            return((await Task.WhenAll(valueTasks).ConfigureAwait(false)).Sum());
        }
Example #2
0
        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="executeOptions">Execute options</param>
        /// <param name="commands">Commands</param>
        /// <returns>Return the execute data effect numbers</returns>
        internal static async Task <int> ExecuteAsync(CommandExecuteOptions executeOptions, IEnumerable <ICommand> commands)
        {
            if (commands.IsNullOrEmpty())
            {
                return(0);
            }
            var cmdExecutorGroupDictionary = GroupCommandByExecutor(commands);

            return(await ExecuteAsync(executeOptions, cmdExecutorGroupDictionary.Values).ConfigureAwait(false));
        }