Exemplo n.º 1
0
        private void TryMakeSnapshot(IAggregateRoot <TAuthenticationToken> aggregate)
        {
            if (!SnapshotStrategy.ShouldMakeSnapShot(aggregate))
            {
                return;
            }
            dynamic snapshot = aggregate.AsDynamic().GetSnapshot().RealObject;

            snapshot.Version = aggregate.Version + aggregate.GetUncommittedChanges().Count();
            SnapshotStore.Save(snapshot);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calls <see cref="ISnapshotStrategy{TAuthenticationToken}.ShouldMakeSnapShot"/> on <see cref="SnapshotStrategy"/>
        /// If the <see cref="IAggregateRoot{TAuthenticationToken}"/> is snapshot-able <see cref="SnapshotAggregateRoot{TAuthenticationToken,TSnapshot}.GetSnapshot"/> is called
        /// The <see cref="Snapshot.Version"/> is calculated, finally <see cref="ISnapshotStore.Save"/> is called on <see cref="SnapshotStore"/>.
        /// </summary>
        /// <param name="aggregate">The <see cref="IAggregateRoot{TAuthenticationToken}"/> to try and snapshot.</param>
        /// <param name="uncommittedChanges">A collection of uncommited changes to assess. If null the aggregate will be asked to provide them.</param>
        protected virtual void TryMakeSnapshot(IAggregateRoot <TAuthenticationToken> aggregate, IEnumerable <IEvent <TAuthenticationToken> > uncommittedChanges)
        {
            if (!SnapshotStrategy.ShouldMakeSnapShot(aggregate, uncommittedChanges))
            {
                return;
            }
            dynamic snapshot  = aggregate.AsDynamic().GetSnapshot().RealObject;
            var     rsnapshot = snapshot as Snapshot;

            if (rsnapshot != null)
            {
                rsnapshot.Version = aggregate.Version;
                SnapshotStore.Save(rsnapshot);
            }
            else
            {
                snapshot.Version = aggregate.Version;
                SnapshotStore.Save(snapshot);
            }
        }