/// <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); } }
/// <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; }
/// <inheritdoc/> public virtual void Rollback() { UncommittedEvents = new UncommittedEvents(this); Version = Version.PreviousCommit(); }
/// <inheritdoc/> public virtual void Commit() { UncommittedEvents = new UncommittedEvents(this); Version = Version.NextCommit(); }
/// <inheritdoc/> public IEnumerable <Contracts.UncommittedEvent> ToProtobuf(UncommittedEvents events) => events.Select(_ => ToProtobuf(_));