コード例 #1
0
        /// <summary>
        /// Creates a batch of the given size and adds the result to the output queue.
        /// </summary>
        void MakeBatch(int size)
        {
            T[] batch = new T[size];

            // lock is necessary here to make sure items are in the correct order
            bool taken = false;

            try {
                batchLock.Enter(ref taken);

                for (int i = 0; i < size; ++i)
                {
                    messageQueue.TryTake(out batch [i]);
                }
            } finally {
                if (taken)
                {
                    batchLock.Exit();
                }
            }

            outgoing.AddData(batch);

            VerifyMaxNumberOfGroups();
        }
コード例 #2
0
        /// <summary>
        /// Transforms one item from the queue if the transform delegate is synchronous.
        /// </summary>
        /// <returns>Returns whether an item was processed. Returns <c>false</c> if the queue is empty.</returns>
        bool TransformProcess()
        {
            TInput input;

            var dequeued = messageQueue.TryTake(out input);

            if (dequeued)
            {
                outgoing.AddData(transform(input));
            }

            return(dequeued);
        }
コード例 #3
0
        /// <summary>
        /// Creates a batch of the given size and adds the resulting batch to the output queue.
        /// </summary>
        void MakeBatch(int batchSize)
        {
            if (batchSize == 0)
            {
                return;
            }

            var list1 = new List <T1> ();
            var list2 = new List <T2> ();
            var list3 = new List <T3> ();

            // lock is necessary here to make sure items are in the correct order
            bool taken = false;

            try {
                batchLock.Enter(ref taken);

                int i = 0;

                T1 item1;
                while (i < batchSize && target1.Buffer.TryTake(out item1))
                {
                    list1.Add(item1);
                    i++;
                }

                T2 item2;
                while (i < batchSize && target2.Buffer.TryTake(out item2))
                {
                    list2.Add(item2);
                    i++;
                }

                T3 item3;
                while (i < batchSize && target3.Buffer.TryTake(out item3))
                {
                    list3.Add(item3);
                    i++;
                }

                if (i < batchSize)
                {
                    throw new InvalidOperationException("Unexpected count of items.");
                }
            } finally {
                if (taken)
                {
                    batchLock.Exit();
                }
            }

            var batch = Tuple.Create <IList <T1>, IList <T2>, IList <T3> > (list1, list2,
                                                                            list3);

            outgoing.AddData(batch);

            VerifyMaxNumberOfGroups();
        }
コード例 #4
0
        /// <summary>
        /// Moves items from the input queue to the output queue.
        /// </summary>
        void ProcessQueue()
        {
            T item;

            while (messageQueue.TryTake(out item))
            {
                outgoing.AddData(item);
            }
        }
コード例 #5
0
        /// <summary>
        /// Creates a tuple from the given values and adds the result to the output queue.
        /// </summary>
        void TriggerMessage(T1 val1, T2 val2, T3 val3)
        {
            outgoing.AddData(Tuple.Create(val1, val2, val3));

            if (dataflowBlockOptions.MaxNumberOfGroups != -1 &&
                Interlocked.Increment(ref numberOfGroups)
                >= dataflowBlockOptions.MaxNumberOfGroups)
            {
                Complete();
            }
        }
コード例 #6
0
        /// <summary>
        /// Adds the transformed collection to the output queue.
        /// </summary>
        void EnqueueTransformed(IEnumerable <TOutput> transformed)
        {
            bool first = true;

            if (transformed != null)
            {
                foreach (var item in transformed)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        messageBox.IncreaseCount();
                    }
                    outgoing.AddData(item);
                }
            }
            if (first)
            {
                messageBox.DecreaseCount();
            }
        }