public virtual ICommit Commit(CommitAttempt attempt) { Logger.Debug(Messages.AttemptingToCommit, attempt.Events.Count, attempt.StreamId, attempt.CommitSequence, attempt.BucketId); try { return(TryRaven(() => { var doc = attempt.ToRavenCommit(_serializer); using (TransactionScope scope = OpenCommandScope()) using (IDocumentSession session = _store.OpenSession()) { session.Advanced.UseOptimisticConcurrency = true; session.Store(doc); session.SaveChanges(); scope.Complete(); } Logger.Debug(Messages.CommitPersisted, attempt.CommitId, attempt.BucketId); SaveStreamHead(attempt.ToRavenStreamHead()); return doc.ToCommit(_serializer); })); } catch (Raven.Abstractions.Exceptions.ConcurrencyException) { RavenCommit savedCommit = LoadSavedCommit(attempt); if (savedCommit.CommitId == attempt.CommitId) { throw new DuplicateCommitException(); } Logger.Debug(Messages.ConcurrentWriteDetected); throw new ConcurrencyException(); } }
public static ICommit ToCommit(this RavenCommit commit, IDocumentSerializer serializer) { return(new Commit( commit.BucketId, commit.StreamId, commit.StreamRevision, commit.CommitId, commit.CommitSequence, commit.CommitStamp, null, commit.Headers, serializer.Deserialize <List <EventMessage> >(commit.Payload))); }
public static ICommit ToCommit(this RavenCommit commit, IDocumentSerializer serializer) { return(new Commit( commit.BucketId, commit.StreamId, commit.StreamRevision, commit.CommitId, commit.CommitSequence, commit.CommitStamp, commit.CheckpointNumber.ToString(CultureInfo.InvariantCulture), commit.Headers, serializer.Deserialize <IList <EventMessage> >(commit.Payload) )); }