/// <inheritdoc /> public async Task <DbCommandResult> ExecuteAsync(Action?dispatcherPostExecution = null, bool throwException = false) { this.EnsureDbConnection(); this.EnsureDbConnectionIsOpened(); Func <Task <DbCommandResult> > execution = async() => { bool commitException = false; DbCommandResultCollection results = new DbCommandResultCollection(); // wait all tasks in the queue while (this.ActionsToExecute.Any()) { Func <Task <DbCommandResult> > dbTask = this.ActionsToExecute.Dequeue(); results.Add(await dbTask()); } DbCommandResult mergeResult = results.MergeResults(); // We should not commit if there is any exception that occured var commit = this.CommitOrRollBackIfNecessary(mergeResult); commitException = !commit.Item1; dispatcherPostExecution?.Invoke(); // Get the eventuals commit exception mergeResult.Exception = commit.Item2; if (throwException && (!mergeResult.IsSuccess || commitException)) { // throw the inner exception (Exception of the merge result or the commit exception) throw commit.Item2 !; } return(mergeResult); }; return(await FluentDbCommandBase.SafeExecuteDbCommandAction(execution, this.RetryPolicy, throwException)); }
/// <inheritdoc /> public async Task <DbCommandResult> ExecuteAsync <T>(IEnumerable <DbObjectCommand <T> > commands, Action?dispatcherPostExecution = null, bool throwException = false) where T : class, new() { this.EnsureDbConnection(); this.EnsureDbConnectionIsOpened(); this.CheickDbObjectCommand(commands); Func <Task <DbCommandResult> > execution = async() => { bool commitException = false; DbCommandResultCollection results = new DbCommandResultCollection(); foreach (DbObjectCommand <T> command in commands) { results.Add(await this.ExecuteDbObjectCommand <T>(command)); } DbCommandResult mergeResult = results.MergeResults(); // We should not commit if there is any exception that occured var commit = this.CommitOrRollBackIfNecessary(mergeResult); commitException = !commit.Item1; dispatcherPostExecution?.Invoke(); // Get the eventuals commit exception mergeResult.Exception = commit.Item2; if (throwException && (!mergeResult.IsSuccess || commitException)) { // throw the inner exception (Exception of the merge result or the commit exception) throw commit.Item2 !; } return(mergeResult); }; return(await this.SafeExecute(execution, throwException)); }