private Task <IWriteResult> SetStreamMetadataInternal(StreamMetadata metadata,
                                                       AppendReq appendReq,
                                                       EventStoreClientOperationOptions operationOptions,
                                                       UserCredentials?userCredentials,
                                                       CancellationToken cancellationToken) =>
 AppendToStreamInternal(appendReq, new[] {
     new EventData(Uuid.NewUuid(), SystemEventTypes.StreamMetadata,
                   JsonSerializer.SerializeToUtf8Bytes(metadata, StreamMetadataJsonSerializerOptions)),
 }, operationOptions, userCredentials, cancellationToken);
示例#2
0
 public async Task DeleteAsync(string streamName, string groupName, UserCredentials?userCredentials = null,
                               CancellationToken cancellationToken = default)
 {
     await _client.DeleteAsync(new DeleteReq {
         Options = new DeleteReq.Types.Options {
             StreamIdentifier = streamName,
             GroupName        = groupName
         }
     }, EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));
 }
示例#3
0
 public async Task EnableAsync(string name, UserCredentials?userCredentials = null,
                               CancellationToken cancellationToken          = default)
 {
     using var call = _client.EnableAsync(new EnableReq {
         Options = new EnableReq.Types.Options {
             Name = name
         }
     }, RequestMetadata.Create(userCredentials ?? Settings.DefaultCredentials), cancellationToken: cancellationToken);
     await call.ResponseAsync.ConfigureAwait(false);
 }
 public async Task EnableAsync(string name, UserCredentials?userCredentials = null,
                               CancellationToken cancellationToken          = default)
 {
     using var call = _client.EnableAsync(new EnableReq {
         Options = new EnableReq.Types.Options {
             Name = name
         }
     }, EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));
     await call.ResponseAsync.ConfigureAwait(false);
 }
示例#5
0
        private async Task <DeleteResult> DeleteInternal(DeleteReq request, EventStoreClientOperationOptions operationOptions,
                                                         UserCredentials?userCredentials,
                                                         CancellationToken cancellationToken)
        {
            _log.LogDebug("Deleting stream {streamName}.", request.Options.StreamName);
            var result = await _client.DeleteAsync(request, RequestMetadata.Create(userCredentials ?? Settings.DefaultCredentials),
                                                   deadline : DeadLine.After(operationOptions.TimeoutAfter), cancellationToken);

            return(new DeleteResult(new Position(result.Position.CommitPosition, result.Position.PreparePosition)));
        }
示例#6
0
 public async Task DeleteAsync(string streamName, string groupName, UserCredentials?userCredentials = null,
                               CancellationToken cancellationToken = default)
 {
     await _client.DeleteAsync(new DeleteReq {
         Options = new DeleteReq.Types.Options {
             StreamIdentifier = streamName,
             GroupName        = groupName
         }
     }, RequestMetadata.Create(userCredentials ?? Settings.DefaultCredentials), cancellationToken : cancellationToken);
 }
示例#7
0
 private async Task DisableInternalAsync(string name, bool writeCheckpoint, UserCredentials?userCredentials,
                                         CancellationToken cancellationToken)
 {
     using var call = _client.DisableAsync(new DisableReq {
         Options = new DisableReq.Types.Options {
             Name            = name,
             WriteCheckpoint = writeCheckpoint
         }
     }, RequestMetadata.Create(userCredentials ?? Settings.DefaultCredentials), cancellationToken: cancellationToken);
     await call.ResponseAsync.ConfigureAwait(false);
 }
 public async Task CreateOneTimeAsync(string query, UserCredentials?userCredentials = null,
                                      CancellationToken cancellationToken           = default)
 {
     using var call = _client.CreateAsync(new CreateReq {
         Options = new CreateReq.Types.Options {
             OneTime = new Empty(),
             Query   = query
         }
     }, RequestMetadata.Create(userCredentials ?? Settings.DefaultCredentials), cancellationToken: cancellationToken);
     await call.ResponseAsync.ConfigureAwait(false);
 }
 public async Task CreateOneTimeAsync(string query, UserCredentials?userCredentials = null,
                                      CancellationToken cancellationToken           = default)
 {
     using var call = _client.CreateAsync(new CreateReq {
         Options = new CreateReq.Types.Options {
             OneTime = new Empty(),
             Query   = query
         }
     }, EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));
     await call.ResponseAsync.ConfigureAwait(false);
 }
 private Task <DeleteResult> TombstoneAsync(
     string streamName,
     StreamState expectedState,
     EventStoreClientOperationOptions operationOptions,
     UserCredentials?userCredentials     = null,
     CancellationToken cancellationToken = default) =>
 TombstoneInternal(new TombstoneReq {
     Options = new TombstoneReq.Types.Options {
         StreamIdentifier = streamName
     }
 }.WithAnyStreamRevision(expectedState), operationOptions, userCredentials, cancellationToken);
示例#11
0
 public async Task DeleteAsync(string streamName, string groupName, UserCredentials?userCredentials = null,
                               CancellationToken cancellationToken = default)
 {
     await new PersistentSubscriptions.PersistentSubscriptions.PersistentSubscriptionsClient(
         await SelectCallInvoker(cancellationToken).ConfigureAwait(false)).DeleteAsync(new DeleteReq {
         Options = new DeleteReq.Types.Options {
             StreamIdentifier = streamName,
             GroupName        = groupName
         }
     }, EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));
 }
示例#12
0
        private async Task <DeleteResult> DeleteInternal(DeleteReq request,
                                                         EventStoreClientOperationOptions operationOptions,
                                                         UserCredentials?userCredentials,
                                                         CancellationToken cancellationToken)
        {
            _log.LogDebug("Deleting stream {streamName}.", request.Options.StreamIdentifier);
            var result = await _client.DeleteAsync(request,
                                                   EventStoreCallOptions.Create(Settings, operationOptions, userCredentials, cancellationToken));

            return(new DeleteResult(new Position(result.Position.CommitPosition, result.Position.PreparePosition)));
        }
 private async Task DisableInternalAsync(string name, bool writeCheckpoint, UserCredentials?userCredentials,
                                         CancellationToken cancellationToken)
 {
     using var call = _client.DisableAsync(new DisableReq {
         Options = new DisableReq.Types.Options {
             Name            = name,
             WriteCheckpoint = writeCheckpoint
         }
     }, EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));
     await call.ResponseAsync.ConfigureAwait(false);
 }
        public Task <IWriteResult> SetStreamMetadataAsync(string streamName, StreamState expectedState,
                                                          StreamMetadata metadata, Action <EventStoreClientOperationOptions>?configureOperationOptions = null,
                                                          UserCredentials?userCredentials     = null,
                                                          CancellationToken cancellationToken = default)
        {
            var options = Settings.OperationOptions.Clone();

            configureOperationOptions?.Invoke(options);
            return(SetStreamMetadataAsync(streamName, expectedState, metadata, options,
                                          userCredentials, cancellationToken));
        }
 public async Task SetNodePriorityAsync(int nodePriority,
                                        UserCredentials?userCredentials     = null,
                                        CancellationToken cancellationToken = default)
 {
     await new Operations.Operations.OperationsClient(
         await SelectCallInvoker(cancellationToken).ConfigureAwait(false)).SetNodePriorityAsync(
         new SetNodePriorityReq {
         Priority = nodePriority
     },
         EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));
 }
 public static Metadata Create(UserCredentials?userCredentials) =>
 userCredentials == null
                         ? new Metadata()
                         : new Metadata
 {
     new Metadata.Entry(Constants.Headers.Authorization, new AuthenticationHeaderValue(
                            Constants.Headers.BasicScheme,
                            Convert.ToBase64String(
                                Encoding.ASCII.GetBytes($"{userCredentials.Username}:{userCredentials.Password}")))
                        .ToString())
 };
示例#17
0
 public async Task ResetAsync(string name, UserCredentials?userCredentials = null,
                              CancellationToken cancellationToken          = default)
 {
     using var call = new Projections.Projections.ProjectionsClient(
               await SelectCallInvoker(cancellationToken).ConfigureAwait(false)).ResetAsync(new ResetReq {
         Options = new ResetReq.Types.Options {
             Name            = name,
             WriteCheckpoint = true
         }
     }, EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));
     await call.ResponseAsync.ConfigureAwait(false);
 }
 private Task <DeleteResult> TombstoneAsync(
     string streamName,
     StreamRevision expectedRevision,
     EventStoreClientOperationOptions operationOptions,
     UserCredentials?userCredentials     = null,
     CancellationToken cancellationToken = default) =>
 TombstoneInternal(new TombstoneReq {
     Options = new TombstoneReq.Types.Options {
         StreamName = streamName,
         Revision   = expectedRevision
     }
 }, operationOptions, userCredentials, cancellationToken);
        public async Task <PersistentSubscription> SubscribeAsync(string streamName, string groupName,
                                                                  Func <PersistentSubscription, ResolvedEvent, int?, CancellationToken, Task> eventAppeared,
                                                                  Action <PersistentSubscription, SubscriptionDroppedReason, Exception?>?subscriptionDropped = null,
                                                                  UserCredentials?userCredentials     = null, int bufferSize = 10, bool autoAck = true,
                                                                  CancellationToken cancellationToken = default)
        {
            if (streamName == null)
            {
                throw new ArgumentNullException(nameof(streamName));
            }

            if (groupName == null)
            {
                throw new ArgumentNullException(nameof(groupName));
            }

            if (eventAppeared == null)
            {
                throw new ArgumentNullException(nameof(eventAppeared));
            }

            if (streamName == string.Empty)
            {
                throw new ArgumentException($"{nameof(streamName)} may not be empty.", nameof(streamName));
            }

            if (groupName == string.Empty)
            {
                throw new ArgumentException($"{nameof(groupName)} may not be empty.", nameof(groupName));
            }

            if (bufferSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(bufferSize));
            }

            var operationOptions = Settings.OperationOptions.Clone();

            operationOptions.TimeoutAfter = new TimeSpan?();

            var call = new PersistentSubscriptions.PersistentSubscriptions.PersistentSubscriptionsClient(
                await SelectCallInvoker(cancellationToken).ConfigureAwait(false)).Read(EventStoreCallOptions.Create(
                                                                                           Settings, operationOptions, userCredentials, cancellationToken));

            return(await PersistentSubscription.Confirm(call, new ReadReq.Types.Options {
                BufferSize = bufferSize,
                GroupName = groupName,
                StreamIdentifier = streamName,
                UuidOption = new ReadReq.Types.Options.Types.UUIDOption {
                    Structured = new Empty()
                }
            }, autoAck, eventAppeared, subscriptionDropped ?? delegate { }, cancellationToken).ConfigureAwait(false));
        }
		public Task<DeleteResult> SoftDeleteAsync(
			string streamName,
			StreamRevision expectedRevision,
			Action<EventStoreClientOperationOptions>? configureOperationOptions = null,
			UserCredentials? userCredentials = null,
			CancellationToken cancellationToken = default) {

			var operationOptions = Settings.OperationOptions.Clone();
			configureOperationOptions?.Invoke(operationOptions);

			return SoftDeleteAsync(streamName, expectedRevision, operationOptions, userCredentials, cancellationToken);
		}
 public async Task CreateContinuousAsync(string name, string query, bool trackEmittedStreams = false,
                                         UserCredentials?userCredentials = null, CancellationToken cancellationToken = default)
 {
     using var call = _client.CreateAsync(new CreateReq {
         Options = new CreateReq.Types.Options {
             Continuous = new CreateReq.Types.Options.Types.Continuous {
                 Name = name,
                 TrackEmittedStreams = trackEmittedStreams
             },
             Query = query
         }
     }, RequestMetadata.Create(userCredentials ?? Settings.DefaultCredentials), cancellationToken: cancellationToken);
     await call.ResponseAsync.ConfigureAwait(false);
 }
 public async Task CreateContinuousAsync(string name, string query, bool trackEmittedStreams = false,
                                         UserCredentials?userCredentials = null, CancellationToken cancellationToken = default)
 {
     using var call = _client.CreateAsync(new CreateReq {
         Options = new CreateReq.Types.Options {
             Continuous = new CreateReq.Types.Options.Types.Continuous {
                 Name = name,
                 TrackEmittedStreams = trackEmittedStreams
             },
             Query = query
         }
     }, EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));
     await call.ResponseAsync.ConfigureAwait(false);
 }
        public async Task DisableUserAsync(string loginName, UserCredentials?userCredentials = null,
                                           CancellationToken cancellationToken = default)
        {
            if (loginName == string.Empty)
            {
                throw new ArgumentOutOfRangeException(nameof(loginName));
            }

            await _client.DisableAsync(new DisableReq {
                Options = new DisableReq.Types.Options {
                    LoginName = loginName
                }
            }, RequestMetadata.Create(userCredentials ?? Settings.DefaultCredentials), cancellationToken : cancellationToken);
        }
        public async Task DisableUserAsync(string loginName, UserCredentials?userCredentials = null,
                                           CancellationToken cancellationToken = default)
        {
            if (loginName == string.Empty)
            {
                throw new ArgumentOutOfRangeException(nameof(loginName));
            }

            await _client.DisableAsync(new DisableReq {
                Options = new DisableReq.Types.Options {
                    LoginName = loginName
                }
            }, EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));
        }
 public async Task CreateTransientAsync(string name, string query, UserCredentials?userCredentials = null,
                                        CancellationToken cancellationToken = default)
 {
     using var call = new Projections.Projections.ProjectionsClient(
               await SelectCallInvoker(cancellationToken).ConfigureAwait(false)).CreateAsync(new CreateReq {
         Options = new CreateReq.Types.Options {
             Transient = new CreateReq.Types.Options.Types.Transient {
                 Name = name
             },
             Query = query
         }
     }, EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));
     await call.ResponseAsync.ConfigureAwait(false);
 }
 public static Task SetSystemSettingsAsync(
     this EventStoreClient client,
     SystemSettings settings,
     UserCredentials?userCredentials = null, CancellationToken cancellationToken = default)
 {
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     return(client.AppendToStreamAsync(SystemStreams.SettingsStream, StreamState.Any,
                                       new[] {
         new EventData(Uuid.NewUuid(), SystemEventTypes.Settings,
                       JsonSerializer.SerializeToUtf8Bytes(settings, SystemSettingsJsonSerializerOptions))
     }, userCredentials: userCredentials, cancellationToken: cancellationToken));
 }
        public Task <IWriteResult> AppendToStreamAsync(
            string streamName,
            StreamRevision expectedRevision,
            IEnumerable <EventData> eventData,
            Action <EventStoreClientOperationOptions>?configureOperationOptions = null,
            UserCredentials?userCredentials     = null,
            CancellationToken cancellationToken = default)
        {
            var options = Settings.OperationOptions.Clone();

            configureOperationOptions?.Invoke(options);

            return(AppendToStreamAsync(streamName, expectedRevision, eventData, options, userCredentials,
                                       cancellationToken));
        }
        public async Task <JsonDocument> GetStateAsync(string name, string?partition   = null,
                                                       UserCredentials?userCredentials = null, CancellationToken cancellationToken = default)
        {
            var value = await GetStateInternalAsync(name, partition, userCredentials, cancellationToken).ConfigureAwait(false);

            await using var stream = new MemoryStream();
            await using var writer = new Utf8JsonWriter(stream);
            var serializer = new ValueSerializer();

            serializer.Write(writer, value, new JsonSerializerOptions());
            stream.Position = 0;
            await writer.FlushAsync(cancellationToken).ConfigureAwait(false);

            return(JsonDocument.Parse(stream));
        }
        public async IAsyncEnumerable <UserDetails> ListAllAsync(UserCredentials?userCredentials = null,
                                                                 [EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            using var call = _client.Details(new DetailsReq(),
                                             EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken));

            await foreach (var userDetail in call.ResponseStream
                           .ReadAllAsync(cancellationToken)
                           .Select(x => ConvertUserDetails(x.UserDetails))
                           .WithCancellation(cancellationToken)
                           .ConfigureAwait(false))
            {
                yield return(userDetail);
            }
        }
        private async ValueTask <Value> GetStateInternalAsync(string name, string?partition,
                                                              UserCredentials?userCredentials,
                                                              CancellationToken cancellationToken)
        {
            using var call = _client.StateAsync(new StateReq {
                Options = new StateReq.Types.Options {
                    Name      = name,
                    Partition = partition ?? string.Empty
                }
            }, RequestMetadata.Create(userCredentials ?? Settings.DefaultCredentials), cancellationToken: cancellationToken);

            var response = await call.ResponseAsync.ConfigureAwait(false);

            return(response.State);
        }