public static DocumentStreamHead ToDocumentStreamHead(this CommitAttempt commit) { return(new DocumentStreamHead { Id = DocumentStreamHead.GetStreamHeadId(commit.BucketId, commit.StreamId), BucketId = commit.BucketId, StreamId = commit.StreamId, HeadRevision = commit.StreamRevision, SnapshotRevision = 0 }); }
public static DocumentStreamHead ToDocumentStreamHead(this ISnapshot snapshot) { return(new DocumentStreamHead { Id = DocumentStreamHead.GetStreamHeadId(snapshot.BucketId, snapshot.StreamId), BucketId = snapshot.BucketId, StreamId = snapshot.StreamId, HeadRevision = snapshot.StreamRevision, SnapshotRevision = snapshot.StreamRevision }); }
private void SaveStreamHead(DocumentStreamHead updated) { TryExecute(() => { var collection = this.EnsureCollection(this.Options.StreamHeadCollectionName).Result; var documents = this.Client.ReadDocumentFeedAsync(collection.DocumentsLink).Result; var documentId = DocumentStreamHead.GetStreamHeadId(updated.BucketId, updated.StreamId); var streamHead = documents.Where(d => d.Id == documentId).FirstOrDefault() ?? updated; streamHead.HeadRevision = updated.HeadRevision; if (updated.SnapshotRevision > 0) { streamHead.SnapshotRevision = updated.SnapshotRevision; } return(this.Client.ReplaceDocumentAsync(streamHead).Result); }); }