Ejemplo n.º 1
0
        /// <summary>
        /// Commit work
        /// </summary>
        /// <returns>Return work commit result</returns>
        public async Task <WorkCommitResult> CommitAsync()
        {
            try
            {
                //build commands
                BuildCommand();

                if (commandEngineGroups.IsNullOrEmpty())
                {
                    return(WorkCommitResult.Empty());
                }
                var executeOption = GetCommandExecuteOption();
                var result        = await CommandExecuteManager.ExecuteAsync(executeOption, commandEngineGroups.Values).ConfigureAwait(false);

                var commitResult = new WorkCommitResult()
                {
                    CommitCommandCount           = commandCollection.Count,
                    ExecutedDataCount            = result,
                    AllowEmptyResultCommandCount = allowEmptyResultCommandCount
                };

                // trigger command callback event
                TriggerCommandCallbackEvent(commitResult.EmptyResultOrSuccess);
                if (commitResult.EmptyResultOrSuccess)
                {
                    //Trigger commit success event
                    TriggerCommitSuccessEvent(commitResult);
                    //Trigger work global success event
                    WorkManager.TriggerWorkCommitSuccessEvent(this, commitResult, commandCollection);
                    //Execute domain event
                    TriggerWorkCompletedDomainEvent();
                    //Execute data access event
                    TriggerDataAccessEvent();
                }
                else
                {
                    //Trigger work global commit fail event
                    WorkManager.TriggerWorkCommitFailEvent(this, commitResult, commandCollection);
                }
                return(commitResult);
            }
            catch (Exception ex)
            {
                Reset();
                throw ex;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Commit work
        /// </summary>
        /// <returns>Return work commit result</returns>
        public async Task <WorkCommitResult> CommitAsync()
        {
            try
            {
                if (allowTraceLog)
                {
                    LogManager.LogInformation <DefaultWork>($"===== Work:{WorkId} commit begin =====");
                }

                //build commands
                BuildCommand();
                WorkCommitResult commitResult = null;
                if (commandEngineGroups.IsNullOrEmpty())
                {
                    commitResult = WorkCommitResult.Empty();
                }
                else
                {
                    var executeOptions = GetCommandExecuteOptions();

                    if (allowTraceLog)
                    {
                        LogManager.LogInformation <DefaultWork>($"Work:{WorkId},Command execute options:{JsonSerializeHelper.ObjectToJson(executeOptions)}");
                        LogManager.LogInformation <DefaultWork>($"Work:{WorkId},Command engine keys:{string.Join(",", commandEngineGroups.Keys)},Command count:{commandCollection.Count}");
                    }

                    int returnValue = await CommandExecuteManager.ExecuteAsync(executeOptions, commandEngineGroups.Values).ConfigureAwait(false);

                    commitResult = new WorkCommitResult()
                    {
                        CommitCommandCount           = commandCollection.Count,
                        ExecutedDataCount            = returnValue,
                        AllowEmptyResultCommandCount = allowEmptyResultCommandCount
                    };
                }

                // trigger command callback event
                TriggerCommandCallbackEvent(commitResult.EmptyResultOrSuccess);
                if (commitResult.EmptyResultOrSuccess)
                {
                    //Trigger commit success event
                    TriggerCommitSuccessEvent(commitResult);
                    //Trigger work global success event
                    WorkManager.TriggerWorkCommitSuccessEvent(this, commitResult, commandCollection);
                    //Execute domain event
                    TriggerWorkCompletedDomainEvent();
                    //Execute data access event
                    TriggerDataAccessEvent();
                }
                else
                {
                    //Trigger work global commit fail event
                    WorkManager.TriggerWorkCommitFailEvent(this, commitResult, commandCollection);
                }

                if (allowTraceLog)
                {
                    LogManager.LogInformation <DefaultWork>($"Work:{WorkId},Commit command count:{commitResult.CommitCommandCount},Execute data count:{commitResult.ExecutedDataCount},Allow empty result command result:{allowEmptyResultCommandCount}");
                }

                return(commitResult);
            }
            catch (Exception ex)
            {
                Reset();
                if (allowTraceLog)
                {
                    LogManager.LogInformation <DefaultWork>($"Work:{WorkId},Exception message : {ex.Message}");
                }
                throw ex;
            }
            finally
            {
                if (allowTraceLog)
                {
                    LogManager.LogInformation <DefaultWork>($"===== Work:{WorkId} commit end =====");
                }
            }
        }