Ejemplo n.º 1
0
        public async Task ApplyAsync(IDocumentOperations operations, IReadOnlyList <StreamAction> streams,
                                     CancellationToken cancellation)
        {
            // Doing the filtering here to prevent unnecessary network round trips by allowing
            // an aggregate projection to "work" on a stream with no matching events
            var filteredStreams = streams
                                  .Where(x => Projection.AppliesTo(x.Events.Select(x => x.EventType)))
                                  .ToArray();

            var slices = await Slicer.SliceInlineActions(operations, filteredStreams, Tenancy).ConfigureAwait(false);

            var martenSession = (DocumentSessionBase)operations;

            foreach (var slice in slices)
            {
                IStorageOperation?operation;

                if (Projection.MatchesAnyDeleteType(slice))
                {
                    operation = Storage.DeleteForId(slice.Id, slice.Tenant);
                }
                else
                {
                    operation = await DetermineOperation(martenSession, slice, cancellation).ConfigureAwait(false);
                }

                if (operation != null)
                {
                    operations.QueueOperation(operation);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task ApplyAsync(IDocumentOperations operations, IReadOnlyList <StreamAction> streams,
                                     CancellationToken cancellation)
        {
            // Doing the filtering here to prevent unnecessary network round trips by allowing
            // an aggregate projection to "work" on a stream with no matching events
            var filteredStreams = streams
                                  .Where(x => Projection.AppliesTo(x.Events.Select(x => x.EventType)))
                                  .ToArray();

            var slices = await Slicer.SliceInlineActions(operations, filteredStreams).ConfigureAwait(false);

            var martenSession = (DocumentSessionBase)operations;

            await martenSession.Database.EnsureStorageExistsAsync(typeof(TDoc), cancellation).ConfigureAwait(false);

            foreach (var slice in slices)
            {
                await ApplyChangesAsync(martenSession, slice, cancellation).ConfigureAwait(false);
            }
        }