public IDisposable WatchForChanges(int version, OnSettingsChanged onSettingsChanged, CancellationToken ct) { IStreamSubscription subscription = null; async Task StreamMessageReceived(IStreamSubscription _, StreamMessage streamMessage, CancellationToken cancellationToken) { var settings = await StreamStoreConfigRepository.BuildConfigurationSettingsFromMessage(streamMessage, _messageHooks, ct); await onSettingsChanged(settings, ct); }; void SubscriptionDropped(IStreamSubscription _, SubscriptionDroppedReason reason, Exception exception = null) { if (reason != SubscriptionDroppedReason.Disposed) { SetupSubscription(); } }; void SetupSubscription() { subscription = _streamStore.SubscribeToStream( streamId: _streamId, continueAfterVersion: version, streamMessageReceived: StreamMessageReceived, subscriptionDropped: SubscriptionDropped); } SetupSubscription(); return(subscription); }
private StreamStoreConfigRepository BuildRepository(IStreamStore streamStore) { var repo = new StreamStoreConfigRepository( streamStore: streamStore, streamId: StreamId, messageHooks: MessageHooks, changeWatcher: ChangeWatcher); return(repo); }