Beispiel #1
0
        private Optional <Aggregate> GetAggregateFromChangeTrackerIfExits(string identifier)
        {
            Aggregate existingAggregate;

            _changeTracker.TryGet(identifier, out existingAggregate);

            return(new Optional <Aggregate>(existingAggregate));
        }
Beispiel #2
0
        public async Task <IExecutionResult> TakeSnapshotAsync(string stream)
        {
            Optional <TAggregateRoot> root = await _rootRepository.GetAsync(stream);

            root.ThrowsIf(r => !r.HasValue, new AggregateNotFoundException(stream));

            _changeTracker.TryGet(stream, out Aggregate aggregate);

            var serializedState = _eventSerializer.Serialize(root.Value.TakeSnapshot());

            var newSnapshot = new SnapshotDocument(aggregate.Identifier, serializedState, aggregate.ExpectedVersion.Value.ToString(), null, typeof(TSnapshot).TypeQualifiedName());

            await _cosmosDbClient.CreateItemAsync(newSnapshot,
                                                  _cosmosDBConfigurations.SnapshotContainerName).ConfigureAwait(false);

            return(ExecutionResult.Success);
        }