Пример #1
0
 public OptimisticEventStream(Snapshot snapshot, ICommitEvents persistence, int maxRevision)
     : this(snapshot.StreamId, persistence)
 {
     var commits = persistence.GetFrom(snapshot.StreamId, snapshot.StreamRevision, maxRevision);
     this.PopulateStream(snapshot.StreamRevision + 1, maxRevision, commits);
     this.StreamRevision = snapshot.StreamRevision + this.committed.Count;
 }
Пример #2
0
		public virtual IEventStream OpenStream(Snapshot snapshot, int maxRevision)
		{
			if (snapshot == null)
				throw new ArgumentNullException("snapshot");

			Logger.Debug(Resources.OpeningStreamWithSnapshot, snapshot.StreamId, snapshot.StreamRevision, maxRevision);
			maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision;
			return new OptimisticEventStream(snapshot, this, maxRevision);
		}
Пример #3
0
 public virtual IEventStream OpenStream(Snapshot snapshot, int maxRevision)
 {
     maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision;
     return new OptimisticEventStream(snapshot, this, maxRevision);
 }
Пример #4
0
 public virtual bool AddSnapshot(Snapshot snapshot)
 {
     return this.persistence.AddSnapshot(snapshot); // TODO: update the cache here
 }
        private void CreateSnapshots(IEnumerable<StreamHead> streams)
        {
            foreach (StreamHead head in streams)
            {
            //NOTE: This uses a patched version of EventStore that loads commit headers in OptimisticEventStream.PopulateStream()
            // <code>
            // this.identifiers.Add(commit.CommitId);
            // this.headers = this.headers.Union(commit.Headers).ToDictionary(k => k.Key, k => k.Value);
            // </code>
            var stream = eventStore.OpenStream(head.StreamId, int.MinValue, int.MaxValue);

            //NOTE: Nasty hack but it works.
            var aggregateType = stream.UncommittedHeaders.Where(p=>p.Key=="AggregateType").First();
            var type = aggregateTypeResolver(aggregateType.Value.ToString());

            MethodInfo methodInfo = typeof(IRepository).GetMethod("GetById");
            MethodInfo method = methodInfo.MakeGenericMethod(type);

            object o = method.Invoke(repository, new object[]{head.StreamId, head.HeadRevision});
            var aggregate = (IAggregate) o;

            IMemento memento = aggregate.GetSnapshot();

            var snapshot = new Snapshot(head.StreamId, head.HeadRevision, memento);

            eventStore.AddSnapshot(snapshot);

            observer.Notify(new SnapshotTaken(head.StreamId, head.HeadRevision));
            }
        }
Пример #6
0
 public virtual IEventStream OpenStream(Snapshot snapshot, int maxRevision)
 {
     maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision;
     return(new OptimisticEventStream(snapshot, this, maxRevision));
 }
Пример #7
0
 public virtual bool AddSnapshot(Snapshot snapshot)
 {
     return(this.persistence.AddSnapshot(snapshot));            // TODO: update the cache here
 }
Пример #8
0
 public virtual IEventStream OpenStream(Snapshot snapshot, int maxRevision)
 {
     Logger.Debug(Resources.OpeningStreamWithSnapshot, snapshot.StreamId, snapshot.StreamRevision, maxRevision);
     maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision;
     return new OptimisticEventStream(snapshot, this, maxRevision);
 }