Example #1
0
 private Task <WriteResult> SetStreamMetadataAsync(string streamName, AnyStreamRevision expectedRevision,
                                                   StreamMetadata metadata, EventStoreClientOperationOptions operationOptions,
                                                   UserCredentials userCredentials = default, CancellationToken cancellationToken = default)
 => SetStreamMetadataInternal(metadata, new AppendReq {
     Options = new AppendReq.Types.Options {
         StreamName = SystemStreams.MetastreamOf(streamName)
     }
 }.WithAnyStreamRevision(expectedRevision), operationOptions, userCredentials, cancellationToken);
 /// <summary>
 /// Appends events asynchronously to a stream.
 /// </summary>
 /// <param name="streamName">The name of the stream to append events to.</param>
 /// <param name="expectedRevision">The expected <see cref="AnyStreamRevision"/> of the stream to append to.</param>
 /// <param name="eventData">An <see cref="IEnumerable{EventData}"/> to append to the stream.</param>
 /// <param name="userCredentials">The <see cref="UserCredentials"/> for the operation.</param>
 /// <param name="cancellationToken">The optional <see cref="System.Threading.CancellationToken"/>.</param>
 /// <returns></returns>
 public Task <WriteResult> AppendToStreamAsync(
     string streamName,
     AnyStreamRevision expectedRevision,
     IEnumerable <EventData> eventData,
     UserCredentials userCredentials     = default,
     CancellationToken cancellationToken = default) =>
 AppendToStreamAsync(streamName, expectedRevision, eventData, _settings.OperationOptions,
                     userCredentials, cancellationToken);
Example #3
0
 public Task <DeleteResult> SoftDeleteAsync(
     string streamName,
     AnyStreamRevision expectedRevision,
     UserCredentials userCredentials     = default,
     CancellationToken cancellationToken = default) =>
 DeleteInternal(new DeleteReq {
     Options = new DeleteReq.Types.Options {
         StreamName = streamName
     }
 }.WithAnyStreamRevision(expectedRevision), userCredentials, cancellationToken);
 public Task <WriteResult> AppendToStreamAsync(
     string streamName,
     AnyStreamRevision expectedRevision,
     IEnumerable <EventData> eventData,
     UserCredentials userCredentials     = default,
     CancellationToken cancellationToken = default) =>
 AppendToStreamInternal(new AppendReq {
     Options = new AppendReq.Types.Options {
         StreamName = streamName
     }
 }.WithAnyStreamRevision(expectedRevision), eventData, userCredentials, cancellationToken);
 private Task <DeleteResult> TombstoneAsync(
     string streamName,
     AnyStreamRevision expectedRevision,
     EventStoreClientOperationOptions operationOptions,
     UserCredentials userCredentials     = default,
     CancellationToken cancellationToken = default) =>
 TombstoneInternal(new TombstoneReq {
     Options = new TombstoneReq.Types.Options {
         StreamName = streamName
     }
 }.WithAnyStreamRevision(expectedRevision), operationOptions, userCredentials, cancellationToken);
Example #6
0
        /// <summary>
        /// Asynchronously sets the metadata for a stream.
        /// </summary>
        /// <param name="streamName">The name of the stream to set metadata for.</param>
        /// <param name="expectedRevision">The <see cref="AnyStreamRevision"/> of the stream to append to.</param>
        /// <param name="metadata">A <see cref="StreamMetadata"/> representing the new metadata.</param>
        /// <param name="configureOperationOptions">An <see cref="Action{EventStoreClientOperationOptions}"/> to configure the operation's options.</param>
        /// <param name="userCredentials">The optional <see cref="UserCredentials"/> to perform operation with.</param>
        /// <param name="cancellationToken">The optional <see cref="System.Threading.CancellationToken"/>.</param>
        /// <returns></returns>
        public Task <WriteResult> SetStreamMetadataAsync(string streamName, AnyStreamRevision expectedRevision,
                                                         StreamMetadata metadata, Action <EventStoreClientOperationOptions> configureOperationOptions = default,
                                                         UserCredentials userCredentials     = default,
                                                         CancellationToken cancellationToken = default)
        {
            var options = _settings.OperationOptions.Clone();

            configureOperationOptions?.Invoke(options);
            return(SetStreamMetadataAsync(streamName, expectedRevision, metadata, options,
                                          userCredentials, cancellationToken));
        }
        /// <summary>
        /// Tombstones a stream asynchronously. Note: Tombstoned streams can never be recreated.
        /// </summary>
        /// <param name="streamName">The name of the stream to tombstone.</param>
        /// <param name="expectedRevision">The expected <see cref="AnyStreamRevision"/> of the stream being deleted.</param>
        /// <param name="configureOperationOptions">An <see cref="Action{EventStoreClientOperationOptions}"/> to configure the operation's options.</param>
        /// <param name="userCredentials">The optional <see cref="UserCredentials"/> to perform operation with.</param>
        /// <param name="cancellationToken">The optional <see cref="System.Threading.CancellationToken"/>.</param>
        /// <returns></returns>
        public Task <DeleteResult> TombstoneAsync(
            string streamName,
            AnyStreamRevision expectedRevision,
            Action <EventStoreClientOperationOptions> configureOperationOptions,
            UserCredentials userCredentials     = default,
            CancellationToken cancellationToken = default)
        {
            var operationOptions = _settings.OperationOptions.Clone();

            configureOperationOptions(operationOptions);

            return(TombstoneAsync(streamName, expectedRevision, operationOptions, userCredentials, cancellationToken));
        }
        /// <summary>
        /// Appends events asynchronously to a stream.
        /// </summary>
        /// <param name="streamName">The name of the stream to append events to.</param>
        /// <param name="expectedRevision">The expected <see cref="AnyStreamRevision"/> of the stream to append to.</param>
        /// <param name="eventData">An <see cref="IEnumerable{EventData}"/> to append to the stream.</param>
        /// <param name="configureOperationOptions">An <see cref="Action{EventStoreClientOperationOptions}"/> to configure the operation's options.</param>
        /// <param name="userCredentials">The <see cref="UserCredentials"/> for the operation.</param>
        /// <param name="cancellationToken">The optional <see cref="System.Threading.CancellationToken"/>.</param>
        /// <returns></returns>
        public Task <WriteResult> AppendToStreamAsync(
            string streamName,
            AnyStreamRevision expectedRevision,
            IEnumerable <EventData> eventData,
            Action <EventStoreClientOperationOptions> configureOperationOptions,
            UserCredentials userCredentials     = default,
            CancellationToken cancellationToken = default)
        {
            var operationOptions = _settings.OperationOptions.Clone();

            configureOperationOptions(operationOptions);

            return(AppendToStreamAsync(streamName, expectedRevision, eventData, operationOptions, userCredentials,
                                       cancellationToken));
        }
Example #9
0
        private Task <WriteResult> AppendToStreamAsync(
            string streamName,
            AnyStreamRevision expectedRevision,
            IEnumerable <EventData> eventData,
            EventStoreClientOperationOptions operationOptions,
            UserCredentials userCredentials     = default,
            CancellationToken cancellationToken = default)
        {
            _log.LogDebug("Append to stream - {streamName}@{expectedRevision}.", streamName, expectedRevision);

            return(AppendToStreamInternal(new AppendReq {
                Options = new AppendReq.Types.Options {
                    StreamName = streamName
                }
            }.WithAnyStreamRevision(expectedRevision), eventData, operationOptions, userCredentials, cancellationToken));
        }
        public static async Task <ConditionalWriteResult> ConditionalAppendToStreamAsync(
            this EventStoreClient client,
            string streamName,
            AnyStreamRevision expectedRevision,
            IEnumerable <EventData> eventData,
            UserCredentials userCredentials     = default,
            CancellationToken cancellationToken = default)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            try {
                var result = await client.AppendToStreamAsync(streamName, expectedRevision, eventData, userCredentials,
                                                              cancellationToken).ConfigureAwait(false);

                return(ConditionalWriteResult.FromWriteResult(result));
            } catch (StreamDeletedException) {
                return(ConditionalWriteResult.StreamDeleted);
            } catch (WrongExpectedVersionException ex) {
                return(ConditionalWriteResult.FromWrongExpectedVersion(ex));
            }
        }
 /// <summary>
 /// Tombstones a stream asynchronously. Note: Tombstoned streams can never be recreated.
 /// </summary>
 /// <param name="streamName">The name of the stream to tombstone.</param>
 /// <param name="expectedRevision">The expected <see cref="AnyStreamRevision"/> of the stream being deleted.</param>
 /// <param name="userCredentials">The optional <see cref="UserCredentials"/> to perform operation with.</param>
 /// <param name="cancellationToken">The optional <see cref="System.Threading.CancellationToken"/>.</param>
 /// <returns></returns>
 public Task <DeleteResult> TombstoneAsync(
     string streamName,
     AnyStreamRevision expectedRevision,
     UserCredentials userCredentials     = default,
     CancellationToken cancellationToken = default) => TombstoneAsync(streamName, expectedRevision,
                                                                      _settings.OperationOptions, userCredentials, cancellationToken);
Example #12
0
 public void ToStringExpectedResult(AnyStreamRevision sut, string expected)
 {
     Assert.Equal(expected, sut.ToString());
 }
Example #13
0
 public void ToInt64ExpectedResult(long expected, AnyStreamRevision value)
 => Assert.Equal(expected, value.ToInt64());
Example #14
0
 public void FromInt64ExpectedResult(long value, AnyStreamRevision expected)
 => Assert.Equal(expected, AnyStreamRevision.FromInt64(value));
 /// <summary>
 /// Asynchronously sets the metadata for a stream.
 /// </summary>
 /// <param name="streamName">The name of the stream to set metadata for.</param>
 /// <param name="expectedRevision">The <see cref="AnyStreamRevision"/> of the stream to append to.</param>
 /// <param name="metadata">A <see cref="StreamMetadata"/> representing the new metadata.</param>
 /// <param name="userCredentials">The optional <see cref="UserCredentials"/> to perform operation with.</param>
 /// <param name="cancellationToken">The optional <see cref="System.Threading.CancellationToken"/>.</param>
 /// <returns></returns>
 public Task <WriteResult> SetStreamMetadataAsync(string streamName, AnyStreamRevision expectedRevision,
                                                  StreamMetadata metadata, UserCredentials userCredentials = default,
                                                  CancellationToken cancellationToken = default)
 => SetStreamMetadataAsync(streamName, expectedRevision, metadata, _settings.OperationOptions,
                           userCredentials, cancellationToken);