public IEnumerable <ICommit> GetFromTo(Int64 from, Int64 to) { InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CheckpointToken.CompareTo(from) == 0); return(_commits.Skip(_commits.IndexOf(startingCommit) + 1 /* GetFrom => after the checkpoint*/) .TakeWhile(c => c.CheckpointToken <= to)); }
public ICommit Commit(CommitAttempt attempt, Int64 checkpoint) { lock (_commits) { DetectDuplicate(attempt); var commit = new InMemoryCommit(attempt.BucketId, attempt.StreamId, attempt.StreamRevision, attempt.CommitId, attempt.CommitSequence, attempt.CommitStamp, checkpoint, attempt.Headers, attempt.Events); if (_potentialConflicts.Contains(new IdentityForConcurrencyConflictDetection(commit))) { throw new ConcurrencyException(); } _stamps[commit.CommitId] = commit.CommitStamp; _commits.Add(commit); _potentialDuplicates.Add(new IdentityForDuplicationDetection(commit)); _potentialConflicts.Add(new IdentityForConcurrencyConflictDetection(commit)); IStreamHead head = _heads.FirstOrDefault(x => x.StreamId == commit.StreamId); _heads.Remove(head); Logger.LogDebug(Resources.UpdatingStreamHead, commit.StreamId); int snapshotRevision = head?.SnapshotRevision ?? 0; _heads.Add(new StreamHead(commit.BucketId, commit.StreamId, commit.StreamRevision, snapshotRevision)); return(commit); } }
public ICommit Commit(CommitAttempt attempt, ICheckpoint checkpoint) { lock (_commits) { DetectDuplicate(attempt); var commit = new InMemoryCommit(attempt.BucketId, attempt.StreamId, attempt.StreamRevision, attempt.CommitId, attempt.CommitSequence, attempt.CommitStamp, checkpoint.Value, attempt.Headers, attempt.Events, checkpoint); if (_commits.Any(c => c.StreamId == commit.StreamId && c.CommitSequence == commit.CommitSequence)) { throw new ConcurrencyException(); } _stamps[commit.CommitId] = commit.CommitStamp; _commits.Add(commit); _undispatched.Add(commit); IStreamHead head = _heads.FirstOrDefault(x => x.StreamId == commit.StreamId); _heads.Remove(head); Logger.Debug(Resources.UpdatingStreamHead, commit.StreamId); int snapshotRevision = head == null ? 0 : head.SnapshotRevision; _heads.Add(new StreamHead(commit.BucketId, commit.StreamId, commit.StreamRevision, snapshotRevision)); return(commit); } }
public IEnumerable <ICommit> GetFrom(DateTime start) { Guid commitId = _stamps.Where(x => x.Value >= start).Select(x => x.Key).FirstOrDefault(); if (commitId == Guid.Empty) { return(Enumerable.Empty <ICommit>()); } InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CommitId == commitId); return(_commits.Skip(_commits.IndexOf(startingCommit))); }
public IEnumerable <ICommit> GetFromTo(DateTime start, DateTime end) { IEnumerable <Guid> selectedCommitIds = _stamps.Where(x => x.Value >= start && x.Value < end).Select(x => x.Key).ToArray(); Guid firstCommitId = selectedCommitIds.FirstOrDefault(); Guid lastCommitId = selectedCommitIds.LastOrDefault(); if (lastCommitId == Guid.Empty && lastCommitId == Guid.Empty) { return(Enumerable.Empty <ICommit>()); } InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CommitId == firstCommitId); InMemoryCommit endingCommit = _commits.FirstOrDefault(x => x.CommitId == lastCommitId); int startingCommitIndex = (startingCommit == null) ? 0 : _commits.IndexOf(startingCommit); int endingCommitIndex = (endingCommit == null) ? _commits.Count - 1 : _commits.IndexOf(endingCommit); int numberToTake = endingCommitIndex - startingCommitIndex + 1; return(_commits.Skip(_commits.IndexOf(startingCommit)).Take(numberToTake)); }
public IEnumerable <ICommit> GetFrom(Int64 checkpoint) { InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CheckpointToken.CompareTo(checkpoint) == 0); return(_commits.Skip(_commits.IndexOf(startingCommit) + 1 /* GetFrom => after the checkpoint*/)); }
public ICommit Commit(CommitAttempt attempt, ICheckpoint checkpoint) { lock (_commits) { DetectDuplicate(attempt); var commit = new InMemoryCommit(attempt.BucketId, attempt.StreamId, attempt.StreamRevision, attempt.CommitId, attempt.CommitSequence, attempt.CommitStamp, checkpoint.Value, attempt.Headers, attempt.Events, checkpoint); if (_potentialConflicts.Contains(new IdentityForConcurrencyConflictDetection(commit))) { throw new ConcurrencyException(); } _stamps[commit.CommitId] = commit.CommitStamp; _commits.Add(commit); _potentialDuplicates.Add(new IdentityForDuplicationDetection(commit)); _potentialConflicts.Add(new IdentityForConcurrencyConflictDetection(commit)); _undispatched.Add(commit); IStreamHead head = _heads.FirstOrDefault(x => x.StreamId == commit.StreamId); _heads.Remove(head); Logger.Debug(Resources.UpdatingStreamHead, commit.StreamId); int snapshotRevision = head == null ? 0 : head.SnapshotRevision; _heads.Add(new StreamHead(commit.BucketId, commit.StreamId, commit.StreamRevision, snapshotRevision)); return commit; } }