private void CommitChangesAsync(ProcessingCommand processingCommand, bool success, IApplicationMessage message, string errorMessage, int retryTimes)
        {
            var command        = processingCommand.Message;
            var handledCommand = new HandledCommand(command.Id, command.AggregateRootId, message);

            _ioHelper.TryAsyncActionRecursively("AddCommandAsync",
                                                () => _commandStore.AddAsync(handledCommand),
                                                currentRetryTimes => CommitChangesAsync(processingCommand, success, message, errorMessage, currentRetryTimes),
                                                result =>
            {
                var commandAddResult = result.Data;
                if (commandAddResult == CommandAddResult.Success)
                {
                    if (success)
                    {
                        if (message != null)
                        {
                            PublishMessageAsync(processingCommand, message, 0);
                        }
                        else
                        {
                            CompleteCommand(processingCommand, CommandStatus.Success, null, null);
                        }
                    }
                    else
                    {
                        CompleteCommand(processingCommand, CommandStatus.Failed, typeof(string).FullName, errorMessage);
                    }
                }
                else if (commandAddResult == CommandAddResult.DuplicateCommand)
                {
                    HandleDuplicatedCommandAsync(processingCommand, 0);
                }
            },
                                                () => string.Format("[handledCommand:{0}]", handledCommand),
                                                error =>
            {
                _logger.Fatal(string.Format("Add command has unknown exception, the code should not be run to here, errorMessage: {0}", error));
            },
                                                retryTimes, true);
        }
 private void CommitAggregateChangesAsync(ProcessingCommand processingCommand, IAggregateRoot dirtyAggregateRoot, DomainEventStream eventStream, HandledCommand handledCommand, int retryTimes)
 {
     _ioHelper.TryAsyncActionRecursively <AsyncTaskResult <CommandAddResult> >("AddCommandAsync",
                                                                               () => _commandStore.AddAsync(handledCommand),
                                                                               currentRetryTimes => CommitAggregateChangesAsync(processingCommand, dirtyAggregateRoot, eventStream, handledCommand, currentRetryTimes),
                                                                               result =>
     {
         var commandAddResult = result.Data;
         if (commandAddResult == CommandAddResult.Success)
         {
             _eventService.CommitDomainEventAsync(new EventCommittingContext(dirtyAggregateRoot, eventStream, processingCommand));
         }
         else if (commandAddResult == CommandAddResult.DuplicateCommand)
         {
             HandleAggregateDuplicatedCommandAsync(processingCommand, dirtyAggregateRoot, eventStream, 0);
         }
         else
         {
             NotifyCommandExecuted(processingCommand, CommandStatus.Failed, null, "Add command async failed.");
         }
     },
                                                                               () => string.Format("[handledCommand:{0}]", handledCommand),
                                                                               () => NotifyCommandExecuted(processingCommand, CommandStatus.Failed, null, "Add command async failed."),
                                                                               retryTimes);
 }
示例#3
0
        private void CommitChangesAsync(ProcessingCommand processingCommand, IApplicationMessage message, int retryTimes)
        {
            var command        = processingCommand.Message;
            var handledCommand = new HandledCommand(command.Id, command.AggregateRootId, message);

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult <CommandAddResult> >("AddCommandAsync",
                                                                                      () => _commandStore.AddAsync(handledCommand),
                                                                                      currentRetryTimes => CommitChangesAsync(processingCommand, message, currentRetryTimes),
                                                                                      result =>
            {
                var commandAddResult = result.Data;
                if (commandAddResult == CommandAddResult.Success)
                {
                    PublishMessageAsync(processingCommand, message, 0);
                }
                else if (commandAddResult == CommandAddResult.DuplicateCommand)
                {
                    HandleDuplicatedCommandAsync(processingCommand, 0);
                }
                else
                {
                    _logger.ErrorFormat("Add command async failed, commandType:{0}, commandId:{1}, aggregateRootId:{2}", command.GetType().Name, command.Id, command.AggregateRootId);
                    NotifyCommandExecuted(processingCommand, CommandStatus.Failed, typeof(string).FullName, "Add command async failed.");
                }
            },
                                                                                      () => string.Format("[handledCommand:{0}]", handledCommand),
                                                                                      errorMessage => NotifyCommandExecuted(processingCommand, CommandStatus.Failed, typeof(string).Name, errorMessage ?? "Add command async failed."),
                                                                                      retryTimes);
        }