public ICommit Commit(CommitAttempt attempt) { Logger.Debug(Messages.AttemptingToCommit, attempt.Events.Count, attempt.StreamId, attempt.CommitSequence, attempt.BucketId); try { return(TryExecute(() => { var doc = attempt.ToDocumentCommit(this.Serializer); var collection = this.EnsureCollection(this.Options.CommitCollectionName).Result; var document = this.Client.CreateDocumentAsync(collection.SelfLink, doc).Result; Logger.Debug(Messages.CommitPersisted, attempt.CommitId, attempt.BucketId); SaveStreamHead(attempt.ToDocumentStreamHead()); return doc.ToCommit(this.Serializer); })); } catch (Microsoft.Azure.Documents.DocumentClientException) // TODO: verify actual exception { DocumentCommit savedCommit = LoadSavedCommit(attempt); if (savedCommit.CommitId == attempt.CommitId) { throw new DuplicateCommitException(); } Logger.Debug(Messages.ConcurrentWriteDetected); throw new ConcurrencyException(); } }
public static ICommit ToCommit(this DocumentCommit 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) )); }