/// <inheritdoc/>
        public void Commit(TransactionCorrelationId correlationId, UncommittedEventStream uncommittedEventStream)
        {
            var envelopes        = _eventEnvelopes.CreateFrom(uncommittedEventStream.EventSource, uncommittedEventStream.EventsAndVersion);
            var envelopesAsArray = envelopes.ToArray();
            var eventsAsArray    = uncommittedEventStream.ToArray();

            var eventsAndEnvelopes = new List <EventAndEnvelope>();

            for (var eventIndex = 0; eventIndex < eventsAsArray.Length; eventIndex++)
            {
                var envelope = envelopesAsArray[eventIndex];
                var @event   = eventsAsArray[eventIndex];
                eventsAndEnvelopes.Add(new EventAndEnvelope(
                                           envelope
                                           .WithTransactionCorrelationId(correlationId)
                                           .WithSequenceNumber(_eventSequenceNumbers.Next())
                                           .WithSequenceNumberForEventType(_eventSequenceNumbers.NextForType(envelope.Event)),
                                           @event
                                           ));
            }

            _eventStore.Commit(eventsAndEnvelopes);
            _eventSourceVersions.SetFor(envelopesAsArray[0].EventSource, envelopesAsArray[0].EventSourceId, envelopesAsArray[envelopesAsArray.Length - 1].Version);

            var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId, eventsAndEnvelopes);

            _committedEventStreamSender.Send(committedEventStream);
        }
Beispiel #2
0
 /// <inheritdoc/>
 public virtual void Rollback()
 {
     UncommittedEvents = new UncommittedEventStream(this);
     Version           = Version.PreviousCommit();
 }
Beispiel #3
0
 /// <inheritdoc/>
 public virtual void Commit()
 {
     UncommittedEvents = new UncommittedEventStream(this);
     Version           = Version.NextCommit();
 }
Beispiel #4
0
 /// <summary>
 /// Initializes an instance of <see cref="EventSource">EventSource</see>
 /// </summary>
 /// <param name="id"><see cref="Events.EventSourceId"/> of the event source</param>
 protected EventSource(EventSourceId id)
 {
     EventSourceId     = id;
     UncommittedEvents = new UncommittedEventStream(this);
 }