Пример #1
0
        /// <summary>
        /// Add first stage to this pipeline
        /// </summary>
        /// <typeparam name="TSource">Input type</typeparam>
        /// <typeparam name="TResult">Result type</typeparam>
        /// <param name="source">Source collection</param>
        /// <param name="workers">Number of Workers</param>
        /// <param name="queueSize">Size of result buffer</param>
        /// <param name="filter"></param>
        /// <param name="onFinish"></param>
        /// <param name="onInterval"></param>
        /// <param name="onBegin"></param>
        /// <returns></returns>
        public PipeLineSelectStage <TSource, TResult> Init <TSource, TResult>(
            IEnumerable <TSource> source,
            int workers,
            int queueSize,
            Func <TSource, TResult> filter,
            OnBeginEventHandler onBegin       = null,
            OnFinishEventHandler onFinish     = null,
            OnIntervalEventHandler onInterval = null
            )
        {
            if (workers <= 0)
            {
                throw new PipeLineException("Workers must be more than 1");
            }
            if (queueSize <= 0)
            {
                throw new PipeLineException("QueueSize must be more than 1");
            }
            var s = new BlockingCollection <TSource>();

            foreach (var item in source)
            {
                s.Add(item, token);
            }
            s.CompleteAdding();

            var rt = new PipeLineSelectStage <TSource, TResult>(s, workers, queueSize, filter, onBegin, onFinish,
                                                                onInterval);

            // first stage
            stages.Add(rt);

            return(rt);
        }
Пример #2
0
        /// <summary>
        /// Add first split stage to this pipeline
        /// </summary>
        /// <typeparam name="TSource">Input type</typeparam>
        /// <typeparam name="TResult">Result type</typeparam>
        /// <param name="source">Source collection</param>
        /// <param name="workers">Number of Workers</param>
        /// <param name="queueSize">Size of result buffer</param>
        /// <param name="filter"></param>
        /// <param name="onBegin"></param>
        /// <param name="onFinish"></param>
        /// <param name="onInterval"></param>
        /// <param name="onInnerInterval"></param>
        /// <returns></returns>
        public PipeLineManyStage <TSource, TResult> InitSelectMany <TSource, TResult>(
            IEnumerable <TSource> source,
            int workers,
            int queueSize,
            Func <TSource, IEnumerable <TResult> > filter,
            OnBeginEventHandler onBegin                 = null,
            OnFinishEventHandler onFinish               = null,
            OnIntervalEventHandler onInterval           = null,
            OnInnerIntervalEventHandler onInnerInterval = null)
        {
            var s = new BlockingCollection <TSource>();

            foreach (var item in source)
            {
                s.Add(item, token);
            }
            s.CompleteAdding();
            var rt = new PipeLineManyStage <TSource, TResult>(s, workers, queueSize, filter, onBegin, onFinish,
                                                              onInterval, onInnerInterval);

            // first stage
            stages.Add(rt);

            return(rt);
        }
Пример #3
0
        public PipeLineStageBase <TResult, TResult[]> Buffer(
            int size,
            int queueSize,
            OnBeginEventHandler onBegin       = null,
            OnFinishEventHandler onFinish     = null,
            OnIntervalEventHandler onInterval = null
            )
        {
            var rt = new PipeLineBuffer <TResult>(Results, size, 1, queueSize, onBegin, onFinish, onInterval);

            Next = rt;
            return(rt);
        }
Пример #4
0
        public PipeLineStageBase <TResult, TNextResult> Then <TNextResult>(
            int workers,
            int queueSize,
            Func <TResult, TNextResult> filter,
            OnBeginEventHandler onBegin       = null,
            OnFinishEventHandler onFinish     = null,
            OnIntervalEventHandler onInterval = null
            )
        {
            var rt = new PipeLineSelectStage <TResult, TNextResult>(Results, workers, queueSize, filter, onBegin, onFinish, onInterval);

            Next = rt;
            return(rt);
        }
Пример #5
0
 public PipeLineSelectStage(
     BlockingCollection <TSource> sources,
     int workers,
     int queueSize,
     Func <TSource, TResult> filter,
     OnBeginEventHandler onBegin       = null,
     OnFinishEventHandler onFinish     = null,
     OnIntervalEventHandler onInterval = null
     ) : base(sources, workers, queueSize)
 {
     this.filter = filter;
     OnBegin    += onBegin;
     OnFinish   += onFinish;
     OnInterval += onInterval;
 }
Пример #6
0
 internal PipeLineBuffer(
     BlockingCollection <TItem> sources,
     int size,
     int workers,
     int queueSize,
     OnBeginEventHandler onBegin       = null,
     OnFinishEventHandler onFinish     = null,
     OnIntervalEventHandler onInterval = null
     ) : base(sources,
              workers, queueSize)
 {
     if (size <= 0)
     {
         throw new PipeLineException("size must be more than one");
     }
     Size        = size;
     OnBegin    += onBegin;
     OnFinish   += onFinish;
     OnInterval += onInterval;
 }