public Task TruncateStream( StreamName stream, StreamTruncatePosition truncatePosition, ExpectedStreamVersion expectedVersion, CancellationToken cancellationToken ) { var meta = new StreamMetadata(truncateBefore: truncatePosition.AsStreamPosition()); return(TryExecute( () => AnyOrNot( expectedVersion, () => _client.SetStreamMetadataAsync( stream, StreamState.Any, meta, cancellationToken: cancellationToken ), () => _client.SetStreamMetadataAsync( stream, expectedVersion.AsStreamRevision(), meta, cancellationToken: cancellationToken ) ), stream, () => new ErrorInfo( "Unable to truncate stream {Stream} at {Position}", stream, truncatePosition ), (s, ex) => new TruncateStreamException(s, ex) )); }
public Task DeleteStream( StreamName stream, ExpectedStreamVersion expectedVersion, CancellationToken cancellationToken ) => TryExecute( () => AnyOrNot( expectedVersion, () => _client.DeleteAsync( stream, StreamState.Any, cancellationToken: cancellationToken ), () => _client.DeleteAsync( stream, expectedVersion.AsStreamRevision(), cancellationToken: cancellationToken ) ), stream, () => new ErrorInfo("Unable to delete stream {Stream}", stream), (s, ex) => new DeleteStreamException(s, ex) );
public Task <AppendEventsResult> AppendEvents( StreamName stream, ExpectedStreamVersion expectedVersion, IReadOnlyCollection <StreamEvent> events, CancellationToken cancellationToken ) { var proposedEvents = events.Select(ToEventData); var resultTask = expectedVersion == ExpectedStreamVersion.NoStream ? _client.AppendToStreamAsync( stream, StreamState.NoStream, proposedEvents, cancellationToken: cancellationToken ) : AnyOrNot( expectedVersion, () => _client.AppendToStreamAsync( stream, StreamState.Any, proposedEvents, cancellationToken: cancellationToken ), () => _client.AppendToStreamAsync( stream, expectedVersion.AsStreamRevision(), proposedEvents, cancellationToken: cancellationToken ) ); return(TryExecute( async() => { var result = await resultTask.NoContext(); return new AppendEventsResult( result.LogPosition.CommitPosition, result.NextExpectedStreamRevision.ToInt64() ); }, stream, () => new ErrorInfo("Unable to appends events to {Stream}", stream), (s, ex) => { EventuousEventSource.Log.UnableToAppendEvents(stream, ex); return new AppendToStreamException(s, ex); } )); EventData ToEventData(StreamEvent streamEvent) { var(eventType, contentType, payload) = _serializer.SerializeEvent(streamEvent.Payload !); return(new EventData( Uuid.FromGuid(streamEvent.Id), eventType, payload, _metaSerializer.Serialize(streamEvent.Metadata), contentType )); } }