Exemplo n.º 1
0
        private static void LoadFromSnapshotForwardAndAppend()
        {
            var latestSnapshot = Store.GetSnapshot(StreamId, int.MaxValue);

            using (var stream = Store.OpenStream(latestSnapshot, int.MaxValue))
            {
                var @event = new SomeDomainEvent { Value = "Third event (first one after a snapshot)." };

                stream.Add(new EventMessage { Body = @event });
                stream.CommitChanges(Guid.NewGuid());
            }
        }
Exemplo n.º 2
0
        public override AggregateRoot GetById(Type aggregateRootType, Guid eventSourceId, long?lastKnownRevision)
        {
            int          maxRevision = lastKnownRevision != null ? (int)lastKnownRevision : int.MaxValue;
            var          snapshot    = _eventStore.GetSnapshot(eventSourceId, maxRevision);
            IEventStream stream;

            Sourcing.Snapshotting.Snapshot ncqrsSnapshot = null;
            if (snapshot != null)
            {
                ncqrsSnapshot = new Sourcing.Snapshotting.Snapshot(eventSourceId, snapshot.StreamRevision, snapshot.Payload);
                stream        = _eventStore.OpenStream(snapshot, maxRevision);
            }
            else
            {
                stream = _eventStore.OpenStream(eventSourceId, 0, maxRevision);
            }
            _trackedStreams[eventSourceId] = stream;
            var committedEventStream = GetCommittedEventStream(eventSourceId, stream);
            var result = _domainRepository.Load(aggregateRootType, ncqrsSnapshot, committedEventStream);

            return(result);
        }