Beispiel #1
0
        private static IProducer <U> BufferSelectInternal <T, U>(this IProducer <T> source, int size, Func <IEnumerable <Message <T> >, ValueTuple <U, DateTime> > selector, DeliveryPolicy policy)
        {
            if (size < 0)
            {
                throw new ArgumentOutOfRangeException("size", size, "The size should be positive (and non-zero).");
            }

            var buffer = new BufferSelect <T, U>(source.Out.Pipeline, selector, size);

            return(PipeTo(source, buffer, policy));
        }
Beispiel #2
0
        /// <summary>
        /// Historical messages by time span.
        /// </summary>
        /// <typeparam name="T">Type of source messages.</typeparam>
        /// <typeparam name="U">Type of output messages.</typeparam>
        /// <param name="source">Source stream.</param>
        /// <param name="timeSpan">Time span over which to gather historical messages.</param>
        /// <param name="selector">Selector function.</param>
        /// <param name="policy">Delivery policy.</param>
        /// <returns>Output stream.</returns>
        public static IProducer <U> History <T, U>(this IProducer <T> source, TimeSpan timeSpan, Func <IEnumerable <Message <T> >, ValueTuple <U, DateTime> > selector, DeliveryPolicy policy = null)
        {
            if (timeSpan.Ticks < 0)
            {
                throw new ArgumentOutOfRangeException("timeSpan", timeSpan, "The timeSpan should be positive (and non-zero).");
            }

            Func <Message <T>, DateTime, bool> bufferRemoveCondition =
                (b, ct) => b.OriginatingTime < ct - timeSpan;

            var buffer = new BufferSelect <T, U>(source.Out.Pipeline, bufferRemoveCondition, selector);

            source.PipeTo(buffer.In, policy ?? DeliveryPolicy.Immediate);
            return(buffer.Out);
        }