public Task WriteAsync(IReadOnlyCollection <IUnpersistedRawStreamEvent> events) { lock (_events) { var globalSequence = _events.Count + 1; var existingEvents = _events.Select(e => e.EventID); if (existingEvents.Intersect(events.Select(e => e.EventID)).Any()) { throw new DuplicatedEntryException(); } foreach (var e in events) { e.GlobalSequence = globalSequence++; var p = new PersistedRawEvent { GlobalSequence = e.GlobalSequence, EventID = e.EventID, Stream = e.Stream, EventType = e.EventType, UtcTimestamp = e.UtcTimestamp, Metadata = e.Metadata, Payload = e.Payload }; _events.Add(p); } } return(Unit.GetCompletedTask()); }
public Task WriteAsync(IReadOnlyCollection<IUnpersistedRawStreamEvent> events) { lock (_events) { var globalSequence = _events.Count + 1; var existingEvents = _events.Select(e => e.EventID); if (existingEvents.Intersect(events.Select(e => e.EventID)).Any()) throw new DuplicatedEntryException(); foreach (var e in events) { e.GlobalSequence = globalSequence++; var p = new PersistedRawEvent { GlobalSequence = e.GlobalSequence, EventID = e.EventID, Stream = e.Stream, EventType = e.EventType, UtcTimestamp = e.UtcTimestamp, Metadata = e.Metadata, Payload = e.Payload }; _events.Add(p); } } return Unit.GetCompletedTask(); }
public Task WriteStreamAsync(Stream stream, int expectedSequence, IReadOnlyCollection <IUnpersistedRawEvent> events) { lock (_events) { var streamCount = _events .Where(e => e.Stream.Equals(stream)) .Count(); if (expectedSequence != ExpectedSequence.Any) { if (expectedSequence == ExpectedSequence.None && streamCount > 0) { throw new UnexpectedStreamSequenceException(); } if (expectedSequence >= 0 && expectedSequence != streamCount) { throw new UnexpectedStreamSequenceException(); } } var globalSequence = _events.Count + 1; foreach (var e in events) { e.GlobalSequence = globalSequence++; var p = new PersistedRawEvent { GlobalSequence = e.GlobalSequence, EventID = e.EventID, Stream = stream, EventType = e.EventType, UtcTimestamp = e.UtcTimestamp, Metadata = e.Metadata, Payload = e.Payload }; _events.Add(p); } } return(Unit.GetCompletedTask()); }
public Task WriteStreamAsync(Stream stream, int expectedSequence, IReadOnlyCollection<IUnpersistedRawEvent> events) { lock (_events) { var streamCount = _events .Where(e => e.Stream.Equals(stream)) .Count(); if (expectedSequence != ExpectedSequence.Any) { if (expectedSequence == ExpectedSequence.None && streamCount > 0) throw new UnexpectedStreamSequenceException(); if (expectedSequence >= 0 && expectedSequence != streamCount) throw new UnexpectedStreamSequenceException(); } var globalSequence = _events.Count + 1; foreach (var e in events) { e.GlobalSequence = globalSequence++; var p = new PersistedRawEvent { GlobalSequence = e.GlobalSequence, EventID = e.EventID, Stream = stream, EventType = e.EventType, UtcTimestamp = e.UtcTimestamp, Metadata = e.Metadata, Payload = e.Payload }; _events.Add(p); } } return Unit.GetCompletedTask(); }