Exemple #1
0
        /// <inheritdoc />
        protected override Task ListStreamsObservable(IObserver <IStream> observer, Func <string, bool> predicate, CancellationToken token)
        {
            if (Configuration.UseEmbeddedTcpStore)
            {
                observer.OnCompleted();
                return(Task.CompletedTask);
            }

            var streams = new HashSet <string>();
            var taskCompletionSource = new TaskCompletionSource <bool>();

            _connection.SubscribeToAllFrom(
                Position.Start,
                CatchUpSubscriptionSettings.Default,
                (sub, e) =>
            {
                var streamId = e.Event?.EventStreamId;
                if (!predicate(streamId) || !streams.Add(streamId))
                {
                    return;
                }

                var stream = _connection.GetStream(streamId, Serializer).Result;
                if (typeof(TEventSourced) == typeof(ISaga) && !stream.IsSaga)
                {
                    return;
                }
                if (typeof(TEventSourced) == typeof(IAggregate) && stream.IsSaga)
                {
                    return;
                }

                observer.OnNext(stream);
            },
                sub =>
            {
                sub.Stop();
                observer.OnCompleted();
                taskCompletionSource.SetResult(true);
            },
                (sub, reason, e) =>
            {
                Log.Error(e.Message);
                sub.Stop();
                observer.OnCompleted();
            }, new UserCredentials("admin", "changeit"));
            return(taskCompletionSource.Task);
        }