private void Persist(TAggregate aggregate)
        {
            var uncommitedEvents = aggregate.GetUncommitedEvents();
            var snapshot         = aggregate.GetSnapshot();
            var originalVersion  = aggregate.Version - uncommitedEvents.Count;
            var persistEvents    = new PersistEventsCommand <TIdentity>(aggregate.Id, uncommitedEvents, _processingCommandId, originalVersion);
            var persistSnapshot  = new PersistSnapshotCommand <TSnapshot>(snapshot, _previouslyDispatchedMessages, uncommitedEvents.Count);
            var publishEvents    = new PublishEventsCommand(uncommitedEvents);

            CommandComposition
            .StartWith(persistEvents)
            .ContinueWith(persistSnapshot)
            .ContinueWith(publishEvents)
            .Run();
        }
        public void Execute(PersistEventsCommand<TIdentity> command)
        {
            var expectedVersion = command.ExpectedVersion;
            var events = command.Events
                .Select(x => new EventEnvelope(x, new EventMetadata(command.MessageId, x.GetType().AssemblyQualifiedName)))
                .ToList();

            if (expectedVersion.HasValue)
            {
                _eventStoreContext.Persist(command.Identity, events, expectedVersion.Value - 1);
            }
            else
            {
                _eventStoreContext.Persist(command.Identity, events);
            }
        }
Beispiel #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();
        }