示例#1
0
        public static async Task <InMemoryProjectionWriter <TView> > BuildAsync(string subject, TView view, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var writer = new InMemoryProjectionWriter <TView>();
            await writer.LoadViewAsync(subject, view, cancellationToken);

            return(writer);
        }
示例#2
0
        public async Task <TView> ApplyAsync(TView view, IEvent @event, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{nameof(InMemoryProjector<TView>)}.{nameof(ApplyAsync)} was cancelled before execution");
                cancellationToken.ThrowIfCancellationRequested();
            }

            var subject = Guid.NewGuid().ToString();
            var writer  = await InMemoryProjectionWriter <TView> .BuildAsync(subject, view, cancellationToken);

            var manager = _projectionManagerFactory.Create(writer);
            await manager.HandleAsync(@event, cancellationToken);

            return(await writer.RetrieveAsync(subject, cancellationToken));
        }
示例#3
0
        public async Task <TView> ProjectAsync(string subject, DateTimeOffset timestamp, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{nameof(InMemoryProjector<TView>)}.{nameof(ProjectAsync)} was cancelled before execution");
                cancellationToken.ThrowIfCancellationRequested();
            }

            var events = await _eventStore.GetEventsAsync(StreamId.From(subject), timestamp, cancellationToken);

            var writer = await InMemoryProjectionWriter <TView> .BuildAsync(cancellationToken);

            var manager = _projectionManagerFactory.Create(writer);

            foreach (var @event in events)
            {
                await manager.HandleAsync(@event.Payload, cancellationToken);
            }

            return(await writer.RetrieveAsync(subject, cancellationToken));
        }