Beispiel #1
0
        /// <summary>
        /// Gets the <see cref="IStreamProcessorState" /> for the given <see cref="IStreamProcessorId" /> from the correct
        /// collection, either <see cref="SubscriptionState" /> or <see cref="StreamProcessorState" />.
        /// </summary>
        /// <param name="id">The unique <see cref="IStreamProcessorId" /> representing either the <see cref="AbstractScopedStreamProcessor"/>
        /// or <see cref="SubscriptionId" />.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken" />.</param>
        /// <returns>A <see cref="Task" /> that, when resolved, returns <see cref="Try{TResult}" />.</returns>
        public async Task <Try <IStreamProcessorState> > TryGetFor(IStreamProcessorId id, CancellationToken cancellationToken)
        {
            _logger.Trace("Trying to get Stream Processor State for {StreamProcessorId}", id);
            try
            {
                if (id is SubscriptionId subscriptionId)
                {
                    var states = await _subscriptionStates.Get(subscriptionId.ScopeId, cancellationToken).ConfigureAwait(false);

                    var persistedState = await states.Find(CreateFilter(subscriptionId))
                                         .FirstOrDefaultAsync(cancellationToken)
                                         .ConfigureAwait(false);

                    return((persistedState != null) ? (true, persistedState.ToRuntimeRepresentation()) : (false, null));
                }
                else if (id is StreamProcessorId streamProcessorId)
                {
                    var states = await _streamProcessorStates.Get(streamProcessorId.ScopeId, cancellationToken).ConfigureAwait(false);

                    var persistedState = await states.Find(CreateFilter(streamProcessorId))
                                         .FirstOrDefaultAsync(cancellationToken)
                                         .ConfigureAwait(false);

                    return((persistedState != null) ? (true, persistedState.ToRuntimeRepresentation()) : (false, null));
                }
                else
                {
                    throw new StreamProcessorIdOfUnsupportedType(id);
                }
            }
            catch (MongoWaitQueueFullException ex)
            {
                throw new EventStoreUnavailable("Mongo wait queue is full", ex);
            }
        }
    /// <summary>
    /// Gets the <see cref="IStreamProcessorState" /> for the given <see cref="IStreamProcessorId" /> from the correct
    /// collection, either <see cref="SubscriptionState" /> or <see cref="StreamProcessorState" />.
    /// </summary>
    /// <param name="id">The unique <see cref="IStreamProcessorId" /> representing either the <see cref="AbstractScopedStreamProcessor"/>
    /// or <see cref="SubscriptionId" />.</param>
    /// <param name="cancellationToken">The <see cref="CancellationToken" />.</param>
    /// <returns>A <see cref="Task" /> that, when resolved, returns <see cref="Try{TResult}" />.</returns>
    public async Task <Try <IStreamProcessorState> > TryGetFor(IStreamProcessorId id, CancellationToken cancellationToken)
    {
        _logger.GettingStreamProcessorState(id);
        try
        {
            if (id is SubscriptionId subscriptionId)
            {
                var states = await _subscriptionStates.Get(subscriptionId.ScopeId, cancellationToken).ConfigureAwait(false);

                var persistedState = await states.Find(CreateFilter(subscriptionId))
                                     .FirstOrDefaultAsync(cancellationToken)
                                     .ConfigureAwait(false);

                return(persistedState == default
                    ? new StreamProcessorStateDoesNotExist(subscriptionId)
                    : persistedState.ToRuntimeRepresentation());
            }
            else if (id is StreamProcessorId streamProcessorId)
            {
                var states = await _streamProcessorStates.Get(streamProcessorId.ScopeId, cancellationToken).ConfigureAwait(false);

                var persistedState = await states.Find(CreateFilter(streamProcessorId))
                                     .FirstOrDefaultAsync(cancellationToken)
                                     .ConfigureAwait(false);

                return(persistedState == default
                    ? new StreamProcessorStateDoesNotExist(streamProcessorId)
                    : Try <IStreamProcessorState> .Succeeded(persistedState.ToRuntimeRepresentation()));
            }
            else
            {
                throw new StreamProcessorIdOfUnsupportedType(id);
            }
        }
        catch (MongoWaitQueueFullException ex)
        {
            throw new EventStoreUnavailable("Mongo wait queue is full", ex);
        }
    }