Пример #1
0
        public async Task <StreamEvents> GetEventsForStream(Guid streamId, CancellationToken token = default)
        {
            var batch      = _session.CreateBatchQuery();
            var streamTask = batch.Events.FetchStream(streamId);
            var stateTask  = batch.Events.FetchStreamState(streamId);
            await batch.Execute(token);

            var stream = await streamTask;
            var state  = await stateTask;

            return(new StreamEvents
            {
                Events = stream?.Select(e => (IEventDescriptor) new MartenEvent(e.Id, e.Version, e.Timestamp.UtcDateTime, e.Data as IDomainEvent)).ToList(),
                CurrentVersion = state?.Version ?? 0,
                IsArchived = state?.IsArchived ?? false,
            });
        }