Exemple #1
0
        protected virtual void RegisterReceiver(ReceiverTask receiver)
        {
            lock (Store)
            {
                if (!Store.IsElementListEmpty)
                {
                    PortElement <T> portElement = Store.ElementListFirst;
                    int             num         = Store.ElementCount;
                    while (true)
                    {
                        PortElement <T> next  = portElement._next;
                        ITask           task  = null;
                        bool            flag2 = receiver.Evaluate(portElement, ref task);
                        if (task != null)
                        {
                            receiver.TaskQueue.Enqueue(task);
                        }
                        if (flag2)
                        {
                            Store.ElementListRemove(portElement);
                        }
                        if (receiver.State != ReceiverTaskState.Persistent)
                        {
                            if (flag2)
                            {
                                break;
                            }
                            if (task != null)
                            {
                                goto IL_88;
                            }
                        }
                        portElement = next;
                        num--;
                        if (num <= 0)
                        {
                            goto IL_88;
                        }
                    }
                    return;
                }
IL_88:
                if (_mode == PortMode.OptimizedSingleReissueReceiver && Store.ReceiverCount == 1)
                {
                    throw new InvalidOperationException("PortMode.OptimizedSingleReissueReceiver allows only a single receiver");
                }
                Store.AddReceiver(receiver);
            }
        }
Exemple #2
0
        internal void PostInternal(bool insertAtHead, PortElement <T> node)
        {
            bool            flag            = false;
            ITask           task            = null;
            DispatcherQueue dispatcherQueue = null;

            lock (Store)
            {
                if (insertAtHead)
                {
                    Store.ElementListAddFirst(node);
                }
                else
                {
                    Store.ElementListAddLast(node);
                }
                if (Store.ReceiverCount == 0)
                {
                    return;
                }
                int num = 1;
                if (Store.ActiveReceiver == null)
                {
                    num = Store.ReceiverCount;
                }
                ReceiverTask receiverTask = Store.ActiveReceiver;
                int          i            = 0;
                while (i < num)
                {
                    if (num != 1)
                    {
                        receiverTask = Store.GetReceiverAtIndex(i);
                    }
                    task            = null;
                    flag            = receiverTask.Evaluate(node, ref task);
                    dispatcherQueue = receiverTask.TaskQueue;
                    if (flag)
                    {
                        Store.ElementListRemove(node);
                        if (receiverTask.State != ReceiverTaskState.Persistent)
                        {
                            Store.RemoveReceiver(receiverTask);
                            if (i > 1)
                            {
                                i--;
                            }
                            else
                            {
                                receiverTask = Store.ActiveReceiver;
                            }
                            num = Store.ReceiverCount;
                            break;
                        }
                        break;
                    }
                    else
                    {
                        if (task != null)
                        {
                            dispatcherQueue.Enqueue(task);
                        }
                        i++;
                    }
                }
            }
            if (flag && task != null)
            {
                dispatcherQueue.Enqueue(task);
            }
        }