private void ProcessIfNoEventsOfCommand(ProcessingCommand processingCommand, int retryTimes) { var command = processingCommand.Message; _ioHelper.TryAsyncActionRecursively("ProcessIfNoEventsOfCommand", () => _eventStore.FindAsync(command.AggregateRootId, command.Id), currentRetryTimes => ProcessIfNoEventsOfCommand(processingCommand, currentRetryTimes), result => { var existingEventStream = result.Data; if (existingEventStream != null) { _eventService.PublishDomainEventAsync(processingCommand, existingEventStream); } else { CompleteCommand(processingCommand, CommandStatus.NothingChanged, typeof(string).FullName, processingCommand.CommandExecuteContext.GetResult()); } }, () => string.Format("[commandId:{0}]", command.Id), errorMessage => { _logger.Fatal(string.Format("Find event by commandId has unknown exception, the code should not be run to here, errorMessage: {0}", errorMessage)); }, retryTimes, true); }
private Task ProcessIfNoEventsOfCommand(ProcessingCommand processingCommand, int retryTimes, TaskCompletionSource <bool> taskSource) { var command = processingCommand.Message; _ioHelper.TryAsyncActionRecursively("ProcessIfNoEventsOfCommand", () => _eventStore.FindAsync(command.AggregateRootId, command.Id), currentRetryTimes => ProcessIfNoEventsOfCommand(processingCommand, currentRetryTimes, taskSource), async result => { var existingEventStream = result; if (existingEventStream != null) { _eventCommittingService.PublishDomainEventAsync(processingCommand, existingEventStream); taskSource.SetResult(true); } else { await CompleteCommand(processingCommand, CommandStatus.NothingChanged, typeof(string).FullName, processingCommand.CommandExecuteContext.GetResult()).ConfigureAwait(false); taskSource.SetResult(true); } }, () => string.Format("[commandId:{0}]", command.Id), null, retryTimes, true); return(taskSource.Task); }