Exemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <CommittedAggregateEvents> CommitForAggregate(UncommittedAggregateEvents uncommittedAggregateEvents, CancellationToken cancellationToken)
        {
            _logger.Debug("Committing events for aggregate");
            var request = new Contracts.CommitAggregateEventsRequest
            {
                CallContext = GetCurrentCallContext(),
                Events      = _eventConverter.ToProtobuf(uncommittedAggregateEvents),
            };
            var response = await _eventStoreClient.CommitForAggregateAsync(request, cancellationToken : cancellationToken);

            ThrowIfFailure(response.Failure);
            try
            {
                return(_eventConverter.ToSDK(response.Events));
            }
            catch (CouldNotDeserializeEvent ex)
            {
                throw new CouldNotDeserializeEventFromScope(ScopeId.Default, ex);
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public Contracts.UncommittedAggregateEvents ToProtobuf(UncommittedAggregateEvents uncommittedEvents)
        {
            var aggregateRoot = _artifactTypeMap.GetArtifactFor(uncommittedEvents.AggregateRoot);
            var events        = new Contracts.UncommittedAggregateEvents
            {
                AggregateRootId = aggregateRoot.Id.ToProtobuf(),
                EventSourceId   = uncommittedEvents.EventSource.ToProtobuf(),
                ExpectedAggregateRootVersion = uncommittedEvents.ExpectedAggregateRootVersion,
            };

            foreach (var @event in uncommittedEvents)
            {
                events.Events.Add(new Contracts.UncommittedAggregateEvents.Types.UncommittedAggregateEvent
                {
                    Artifact = ToProtobuf(@event.GetType()),
                    Public   = IsPublicEvent(@event),
                    Content  = _serializer.EventToJson(@event),
                });
            }

            return(events);
        }