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; }
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); }
public virtual IEventStream OpenStream(Snapshot snapshot, int maxRevision) { maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision; return new OptimisticEventStream(snapshot, this, maxRevision); }
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)); } }
public virtual IEventStream OpenStream(Snapshot snapshot, int maxRevision) { maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision; return(new OptimisticEventStream(snapshot, this, maxRevision)); }
public virtual bool AddSnapshot(Snapshot snapshot) { return(this.persistence.AddSnapshot(snapshot)); // TODO: update the cache here }
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); }