/// <summary> /// Commit Work /// </summary> /// <returns></returns> public async Task <CommitResult> CommitAsync() { try { //build commands BuildCommand(); //object command if (commandGroup.IsNullOrEmpty()) { return(new CommitResult() { CommitCommandCount = 0, ExecutedDataCount = 0 }); } bool beforeExecuteResult = await ExecuteCommandBeforeExecuteAsync().ConfigureAwait(false); if (!beforeExecuteResult) { throw new Exception("any command BeforeExecute event return fail"); } var executeOption = GetCommandExecuteOption(); var result = await CommandExecuteManager.ExecuteAsync(executeOption, commandGroup.Values).ConfigureAwait(false); var commitResult = new CommitResult() { CommitCommandCount = commandList.Count, ExecutedDataCount = result, AllowEmptyResultCommandCount = allowEmptyResultCommandCount }; await ExecuteCommandCallbackAsync(commitResult.EmptyResultOrSuccess).ConfigureAwait(false); if (commitResult.EmptyResultOrSuccess) { InvokeCommitSuccessEventHandler(commitResult); //local unit work success callback WorkFactory.InvokeWorkCommitSuccessEventHandler(this, commitResult, commandList); //unit work global success callback await ExecuteWorkCompletedDomainEventAsync().ConfigureAwait(false); //execute domain event } return(commitResult); } catch (Exception ex) { throw ex; } finally { CommitCompleted(); } }
/// <summary> /// Commit Work /// </summary> /// <returns></returns> public async Task <CommitResult> CommitAsync() { try { //build commands BuildCommand(); //object command if (commandGroup.IsNullOrEmpty()) { return(new CommitResult() { CommitCommandCount = 0, ExecutedDataCount = 0 }); } bool beforeExecuteResult = await ExecuteCommandBeforeExecuteAsync().ConfigureAwait(false); if (!beforeExecuteResult) { throw new Exception("any command BeforeExecute event return fail"); } var result = await CommandExecuteManager.ExecuteAsync(commandGroup.Values).ConfigureAwait(false); var commitResult = new CommitResult() { CommitCommandCount = commandList.Count, ExecutedDataCount = result, AllowEmptyResultCommandCount = allowEmptyResultCommandCount }; await ExecuteCommandCallbackAsync(commitResult.EmptyResultOrSuccess).ConfigureAwait(false); if (commitResult.EmptyResultOrSuccess) { CommitSuccessCallbackEvent?.Invoke(); WorkFactory.InvokeCommitSuccessEvent(); } return(commitResult); } catch (Exception ex) { throw ex; } finally { CommitCompleted(); } }
/// <summary> /// invoke commit success event /// </summary> internal static void InvokeWorkCommitSuccessEventHandler(IUnitOfWork unitOfWork, CommitResult commitResult, IEnumerable <ICommand> commands) { workCommitSuccessEventHandler?.Invoke(unitOfWork, commitResult, commands); }
/// <summary> /// invoke commit success event handler /// </summary> /// <param name="commitResult"></param> void InvokeCommitSuccessEventHandler(CommitResult commitResult) { commitSuccessEventHandler?.Invoke(this, commitResult, commandList); }