예제 #1
0
            public async Task UpdateEntityToProjectionAsync(ProjectionSourceDescriptor projectionSource,
                                                            IProjectionResult projectionResult,
                                                            bool addEntityToProjections,
                                                            CancellationToken cancellation)
            {
                if (addEntityToProjections)
                {
                    var projectionId = GetProjectionId(projectionResult);

                    var addedProjection = new ProjectionTargetDescriptor <TProjectionId>(typeof(TProjection), projectionId);
                    var(originalMetadata, metadata) = await GetMetadataAsync(addedProjection, cancellation);

                    Assert(!metadata.ProjectionSources.Any(p => p.Id == projectionSource.SourceId &&
                                                           p.Type == projectionSource.SourceType.GetUnqualifiedTypeName()));

                    var storedProjectionSource = new ProjectionSource
                    {
                        Id   = projectionSource.SourceId,
                        Type = projectionSource.SourceType.GetUnqualifiedTypeName()
                    };

                    metadata.ProjectionSources.Add(storedProjectionSource);

                    _targetMetadataCache[addedProjection] = new ProjectionTargetMetadataCacheEntry(originalMetadata,
                                                                                                   metadata,
                                                                                                   touched: true);
                }

                _targetsToUpdate.Add((TProjection)projectionResult.Result);
            }
예제 #2
0
        private async Task ProjectAsync(ProjectionSourceDescriptor entityDescriptor,
                                        ISet <ProjectionSourceDescriptor> processedEntities,
                                        CancellationToken cancellation)
        {
            if (processedEntities.Contains(entityDescriptor))
            {
                return;
            }

            var scopedEngine = new SourceScopedProjectionEngine(entityDescriptor, _projector, _transactionalDatabase, _database, _serviceProvider);
            var dependents   = await scopedEngine.ProjectAsync(cancellation);

            processedEntities.Add(entityDescriptor);

            foreach (var dependent in dependents)
            {
                await ProjectAsync(dependent, processedEntities, cancellation);
            }
        }
예제 #3
0
            public async Task RemoveEntityFromProjectionAsync(ProjectionSourceDescriptor projectionSource,
                                                              ProjectionTargetDescriptor removedProjection,
                                                              CancellationToken cancellation)
            {
                var(originalMetadata, metadata) = await GetMetadataAsync(removedProjection, cancellation);

                if (metadata == null)
                {
                    Assert(false);
                    return;
                }

                var removed = metadata.ProjectionSources
                              .RemoveFirstWhere(p => p.Id == projectionSource.SourceId &&
                                                p.Type == projectionSource.SourceType.GetUnqualifiedTypeName());

                Assert(removed != null);

                if (!metadata.ProjectionSources.Any())
                {
                    _targetMetadataCache[removedProjection] = new ProjectionTargetMetadataCacheEntry(originalMetadata,
                                                                                                     metadata: null,
                                                                                                     touched: true);

                    var predicate  = DataPropertyHelper.BuildPredicate <TProjectionId, TProjection>(metadata.TargetId);
                    var projection = await _database.GetAsync(predicate, cancellation).FirstOrDefault();

                    if (projection != null)
                    {
                        _targetsToDelete.Add(projection);
                        //await _database.RemoveAsync(projection, cancellation);
                    }
                }

                _targetMetadataCache[removedProjection] = new ProjectionTargetMetadataCacheEntry(originalMetadata,
                                                                                                 metadata,
                                                                                                 touched: true);
            }