/// <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(); //local unit work success callback WorkFactory.InvokeCommitSuccessEvent(); //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 { if (commandList.Count <= 0) { return(new CommitResult() { CommitCommandCount = 0, ExecutedDataCount = 0 }); } var exectCommandList = commandList.Where(c => !c.IsObsolete).ToList(); bool beforeExecuteResult = await ExecuteCommandBeforeExecuteAsync(exectCommandList).ConfigureAwait(false); if (!beforeExecuteResult) { throw new Exception("Any Command BeforeExecute Event Return Fail"); } var result = await CommandExecuteManager.ExecuteAsync(exectCommandList).ConfigureAwait(false); await ExecuteCommandCallbackAsync(exectCommandList, result > 0).ConfigureAwait(false); var commitResult = new CommitResult() { CommitCommandCount = exectCommandList.Count, ExecutedDataCount = result, AllowNoneResultCommandCount = exectCommandList.Count(c => c.VerifyResult?.Invoke(0) ?? false) }; if (commitResult.NoneCommandOrSuccess) { CommitSuccessCallbackEvent?.Invoke(); UnitOfWork.InvokeCommitSuccessEvent(); } return(commitResult); } catch (Exception ex) { throw ex; } finally { Dispose(); } }
/// <summary> /// Commit Command /// </summary> /// <returns></returns> public CommitResult Commit() { try { if (commandList.Count <= 0) { return(new CommitResult() { CommitCommandCount = 0, ExecutedDataCount = 0 }); } var exectCommandList = commandList.Select(c => c).ToList(); bool beforeExecuteResult = ExecuteCommandBeforeExecute(exectCommandList); if (!beforeExecuteResult) { throw new Exception("Any Command BeforeExecute Event Return Fail"); } var result = CommandExecuteManager.Execute(exectCommandList); ExecuteCommandCallback(exectCommandList, result > 0); var commitResult = new CommitResult() { CommitCommandCount = exectCommandList.Count, ExecutedDataCount = result, AllowNoneResultCommandCount = exectCommandList.Count(c => c.VerifyResult?.Invoke(0) ?? false) }; if (commitResult.NoneCommandOrSuccess) { CommitSuccessCallbackEvent?.Invoke(); UnitOfWork.InvokeCommitSuccessEvent(); } return(commitResult); } catch (Exception ex) { throw ex; } finally { Dispose(); } }
/// <summary> /// invoke commit success event /// </summary> internal static void InvokeCommitSuccessEvent() { CommitSuccessCallbackEvent?.Invoke(); }