/// <summary>
 ///     Initializes a new instance of the <see cref="ConsumerPipelineContext" /> class.
 /// </summary>
 /// <param name="envelope">
 ///     The envelope containing the message being processed.
 /// </param>
 /// <param name="consumer">
 ///     The <see cref="IConsumer" /> that triggered this pipeline.
 /// </param>
 /// <param name="sequenceStore">
 ///     The <see cref="ISequenceStore" /> used to temporary store the pending sequences being consumed.
 /// </param>
 /// <param name="serviceProvider">
 ///     The <see cref="IServiceProvider" /> to be used to resolve the required services.
 /// </param>
 public ConsumerPipelineContext(
     IRawInboundEnvelope envelope,
     IConsumer consumer,
     ISequenceStore sequenceStore,
     IServiceProvider serviceProvider)
 {
     Envelope        = Check.NotNull(envelope, nameof(envelope));
     Consumer        = Check.NotNull(consumer, nameof(consumer));
     SequenceStore   = Check.NotNull(sequenceStore, nameof(sequenceStore));
     ServiceProvider = Check.NotNull(serviceProvider, nameof(serviceProvider));
 }
            public FakeSequence(string sequenceId, bool isComplete, bool isAborted, ISequenceStore store)
                : base(sequenceId, ConsumerPipelineContextHelper.CreateSubstitute(sequenceStore: store))
            {
                if (isComplete)
                {
                    CompleteAsync().Wait();
                }

                if (isAborted)
                {
                    AbortAsync(SequenceAbortReason.EnumerationAborted).Wait();
                }
            }
Esempio n. 3
0
        private static Task AbortPreviousSequencesAsync(ISequenceStore sequenceStore, ISequence currentSequence) =>
        sequenceStore
        .GetPendingSequences()
        .ForEachAsync(
            previousSequence =>
        {
            // Prevent Sequence and RawSequence to mess with each other
            if (currentSequence is RawSequence && previousSequence is Sequence ||
                currentSequence is Sequence && previousSequence is RawSequence)
            {
                return(Task.CompletedTask);
            }

            return(previousSequence.AbortAsync(SequenceAbortReason.IncompleteSequence));
        });
        private async Task AwaitOrAbortPreviousSequencesAsync(
            ISequenceStore sequenceStore)
        {
            var sequences = sequenceStore.ToList();

            await sequences
            .ForEachAsync(
                async previousSequence =>
            {
                // Prevent Sequence and RawSequence to mess with each other
                if (HandlesRawMessages && previousSequence is Sequence ||
                    !HandlesRawMessages && previousSequence is RawSequence)
                {
                    return;
                }

                if (!previousSequence.IsComplete)
                {
                    await previousSequence.AbortAsync(SequenceAbortReason.IncompleteSequence)
                    .ConfigureAwait(false);
                }

                var parentSequence = previousSequence.ParentSequence;

                if (parentSequence == null && previousSequence.IsComplete)
                {
                    await previousSequence.AwaitProcessingAsync(false).ConfigureAwait(false);
                }

                if (parentSequence != null && parentSequence.IsComplete)
                {
                    await parentSequence.AwaitProcessingAsync(false).ConfigureAwait(false);
                }
            })
            .ConfigureAwait(false);

            await sequences
            .Where(sequence => !sequence.IsPending)
            .ForEachAsync(sequence => sequenceStore.RemoveAsync(sequence.SequenceId))
            .ConfigureAwait(false);
        }