示例#1
0
    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)
                   ));
    }
示例#2
0
        public async Task <Boolean> ApplyMetaValuesForStream <T>(Guid id, EventStoreStreamMetaValues values)
        {
            String streamName = GetStreamId <T>(id);

            await _client.SetStreamMetadataAsync(streamName, StreamState.Any,
                                                 new StreamMetadata(
                                                     maxCount : values.AmountOfItemsPerStream <= 0 ? new Int32?() : values.AmountOfItemsPerStream,
                                                     maxAge : values.MaxAgeOfEvents.Ticks < 0 ? new TimeSpan?() : values.MaxAgeOfEvents
                                                     ));

            return(true);
        }
示例#3
0
    public async ValueTask Store(string subscriptionId, ulong position, CancellationToken ct)
    {
        var @event        = new CheckpointStored(subscriptionId, position, DateTime.UtcNow);
        var eventToAppend = new[] { @event.ToJsonEventData() };
        var streamName    = GetCheckpointStreamName(subscriptionId);

        try
        {
            // store new checkpoint expecting stream to exist
            await eventStoreClient.AppendToStreamAsync(
                streamName,
                StreamState.StreamExists,
                eventToAppend,
                cancellationToken : ct
                );
        }
        catch (WrongExpectedVersionException)
        {
            // WrongExpectedVersionException means that stream did not exist
            // Set the checkpoint stream to have at most 1 event
            // using stream metadata $maxCount property
            await eventStoreClient.SetStreamMetadataAsync(
                streamName,
                StreamState.NoStream,
                new StreamMetadata(1),
                cancellationToken : ct
                );

            // append event again expecting stream to not exist
            await eventStoreClient.AppendToStreamAsync(
                streamName,
                StreamState.NoStream,
                eventToAppend,
                cancellationToken : ct
                );
        }
    }
示例#4
0
 private async Task SetStreamMetadata(CancellationToken cancellationToken)
 {
     await _eventStore.SetStreamMetadataAsync(_checkpointStreamName, StreamState.NoStream,
                                              new StreamMetadata(maxCount : 5), options => options.ThrowOnAppendFailure = false,
                                              cancellationToken : cancellationToken);
 }
 public Task <WriteResult> SetStreamMetadataAsync(string streamName, AnyStreamRevision expectedRevision, StreamMetadata metadata,
                                                  Action <EventStoreClientOperationOptions> configureOperationOptions = null, UserCredentials userCredentials = null,
                                                  CancellationToken cancellationToken = new CancellationToken())
 {
     return(Client.SetStreamMetadataAsync(streamName, expectedRevision, metadata, configureOperationOptions, userCredentials, cancellationToken));
 }