Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <CommittedAggregateEvents> FetchForAggregate(Type aggregateRoot, EventSourceId eventSource, CancellationToken cancellationToken)
        {
            _logger.Debug("Fetching events for aggregate");
            var request = new Contracts.FetchForAggregateRequest
            {
                CallContext = GetCurrentCallContext(),
                Aggregate   = new Contracts.Aggregate
                {
                    AggregateRootId = _artifactMap.GetArtifactFor(aggregateRoot).Id.ToProtobuf(),
                    EventSourceId   = eventSource.ToProtobuf(),
                },
            };
            var response = await _eventStoreClient.FetchForAggregateAsync(request, cancellationToken : cancellationToken);

            ThrowIfFailure(response.Failure);
            try
            {
                return(_eventConverter.ToSDK(response.Events));
            }
            catch (CouldNotDeserializeEvent ex)
            {
                throw new CouldNotDeserializeEventFromScope(ScopeId.Default, ex);
            }
        }