Ejemplo n.º 1
0
        private IncrementResult CallContinueWithNPlusOneTimes(int iterationCount)
        {
            var continuationCommandChain = _commandComposition.StartWith <InitializeCommand, IncrementResult>(new InitializeCommand(0, 1));

            for (int i = 0; i < iterationCount; i++)
            {
                continuationCommandChain = continuationCommandChain
                                           .ContinueWith <IncrementCommand, IncrementResult>();
            }

            return(continuationCommandChain.Run());
        }
Ejemplo n.º 2
0
        public void Execute(Envelope <TCommand> command)
        {
            _processingCommandId = command.MessageId;
            var restoreAggregateCommand = new RestoreEventSourcedAggregateCommand <TIdentity, TSnapshot>(command.Body.Identity, command.Body.Version, command.MessageId);
            var restoreAggregateResult  = CommandComposition
                                          .StartWith <RestoreEventSourcedAggregateCommand <TIdentity, TSnapshot>, RestoreAggregateCommandResult <TAggregate> >(restoreAggregateCommand)
                                          .Run();

            _previouslyDispatchedMessages = restoreAggregateResult.PreviouslyDispatchedMessages;

            if (restoreAggregateResult.AlreadyDispatched)
            {
                var publishEvents = new PublishEventsCommand(restoreAggregateResult.NeedRedispatchEvents);
                CommandComposition
                .StartWith(publishEvents)
                .Run();
            }
            else
            {
                var aggregate = restoreAggregateResult.Aggregate;
                IdempotentExecute(aggregate, command.Body);
                Persist(aggregate);
            }
        }
Ejemplo n.º 3
0
        public void Execute(Envelope <C> command)
        {
            var messsageId   = Guid.NewGuid();
            var newAggregate = new Aggregate(command.Body.Identity);

            newAggregate.SetName(command.Body.Name);

            var persistEvents   = new PersistEventsCommand <AggregateIdentity>(newAggregate.Id, newAggregate.GetUncommitedEvents(), command.MessageId);
            var persistSnapshot = new PersistSnapshotCommand <AggregateSnapshot>(newAggregate.GetSnapshot(), Enumerable.Empty <Guid>().ToList(), 1);
            var publishEvents   = new PublishEventsCommand(newAggregate.GetUncommitedEvents());

            _commandComposition
            .StartWith(persistEvents)
            .ContinueWith(persistSnapshot)
            .ContinueWith(publishEvents)
            .Run();
        }