/// <inheritdoc/>
        public async Task <CommittedEvents> Commit(UncommittedEvents uncommittedEvents, CancellationToken cancellationToken)
        {
            _logger.Debug("Committing events");
            var request = new Contracts.CommitEventsRequest
            {
                CallContext = GetCurrentCallContext(),
            };

            request.Events.AddRange(_eventConverter.ToProtobuf(uncommittedEvents));
            var response = await _eventStoreClient.CommitAsync(request, cancellationToken : cancellationToken);

            ThrowIfFailure(response.Failure);
            try
            {
                return(_eventConverter.ToSDK(response.Events));
            }
            catch (CouldNotDeserializeEvent ex)
            {
                throw new CouldNotDeserializeEventFromScope(ScopeId.Default, ex);
            }
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventSource"/> class.
 /// </summary>
 /// <param name="id"><see cref="EventSourceId"/> of the event source.</param>
 protected EventSource(EventSourceId id)
 {
     EventSourceId     = id;
     UncommittedEvents = new UncommittedEvents(this);
     Version           = EventSourceVersion.Initial;
 }
Exemple #3
0
 /// <inheritdoc/>
 public virtual void Rollback()
 {
     UncommittedEvents = new UncommittedEvents(this);
     Version           = Version.PreviousCommit();
 }
Exemple #4
0
 /// <inheritdoc/>
 public virtual void Commit()
 {
     UncommittedEvents = new UncommittedEvents(this);
     Version           = Version.NextCommit();
 }
Exemple #5
0
 /// <inheritdoc/>
 public IEnumerable <Contracts.UncommittedEvent> ToProtobuf(UncommittedEvents events)
 => events.Select(_ => ToProtobuf(_));