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));
 }
예제 #2
0
        public static async Task <ConditionalWriteResult> ConditionalAppendToStreamAsync(
            this EventStoreClient client,
            string streamName,
            StreamRevision expectedRevision,
            IEnumerable <EventData> eventData,
            UserCredentials?userCredentials     = null,
            CancellationToken cancellationToken = default)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            try {
                var result = await client.AppendToStreamAsync(streamName, expectedRevision, eventData,
                                                              options => options.ThrowOnAppendFailure = false, userCredentials, cancellationToken)
                             .ConfigureAwait(false);

                return(ConditionalWriteResult.FromWriteResult(result));
            } catch (StreamDeletedException) {
                return(ConditionalWriteResult.StreamDeleted);
            }
        }
예제 #3
0
        public static async Task WarmUpAsync(this EventStoreClient self)
        {
            // if we can read from $users then we know that 1. the users exist
            // and 2. we are connected to leader if we require it
            await Policy.Handle <Exception>()
            .WaitAndRetryAsync(10, retryCount => TimeSpan.FromSeconds(2))
            .ExecuteAsync(async() => {
                var users = await self
                            .ReadStreamAsync(
                    Direction.Forwards,
                    "$users",
                    StreamPosition.Start,
                    userCredentials: TestCredentials.Root)
                            .ToArrayAsync();

                if (users.Length == 0)
                {
                    throw new Exception("no users yet");
                }

                // the read from leader above is not enough to garantee the next write goes to leader
                await self.AppendToStreamAsync($"warmup", StreamState.Any, Enumerable.Empty <EventData>());
            });
        }