Пример #1
0
        //Performs BFS to find node with value
        //returns node with given value
        //returns null if value was not found in graph
        public static GraphNode <T> Search <T>(GraphNode <T> begining, T value)
        {
            System.Collections.Generic.Queue <GraphNode <T> > q = new System.Collections.Generic.Queue <GraphNode <T> >();
            HashSet <GraphNode <T> > visited = new HashSet <GraphNode <T> >();

            q.Enqueue(begining);

            while (q.Count != 0)
            {
                GraphNode <T> node = q.Dequeue();

                if (node.Value.Equals(value))
                {
                    return(node);
                }


                if (!visited.Contains(node))
                {
                    visited.Add(node);
                    foreach (GraphNode <T> n in node.Neighbours)
                    {
                        q.Enqueue(n);
                    }
                }
            }
            return(null);
        }
Пример #2
0
    public static void bfs(Graph G, int startVert)
    {
        bool[] visited = new bool[G.Size];
        // NOTE: the namespace reference isn't required if you have this file on it's own, but if you download
        // all the files with this in the same folder, it will mistakenly reference
        // the local Queue implementation, and not the built in!
        System.Collections.Generic.Queue <int> q = new System.Collections.Generic.Queue <int>();

        visited[startVert] = true;

        q.Enqueue(startVert);

        while (q.Count > 0)
        {
            int v = q.Dequeue();
            foreach (int adjV in G.adj[v])
            {
                if (!visited[adjV])
                {
                    visited[adjV] = true;
                    q.Enqueue(adjV);
                }
            }
        }
    }
Пример #3
0
 public static void RecordProductViews(string bvin, MerchantTribeApplication app)
 {
     if (WebAppSettings.LastProductsViewedCookieName != string.Empty)
     {
         string SavedProductIDs = SessionManager.GetCookieString(WebAppSettings.LastProductsViewedCookieName, app.CurrentStore);
         if (SavedProductIDs != string.Empty)
         {
             string[] AllIDs = SavedProductIDs.Split(',');
             System.Collections.Generic.Queue <string> q = new System.Collections.Generic.Queue <string>();
             q.Enqueue(bvin);
             foreach (string id in AllIDs)
             {
                 if (q.Count < 10)
                 {
                     if (!q.Contains(id))
                     {
                         q.Enqueue(id);
                     }
                 }
             }
             SessionManager.SetCookieString(WebAppSettings.LastProductsViewedCookieName, string.Join(",", q.ToArray()), app.CurrentStore);
         }
         else
         {
             SessionManager.SetCookieString(WebAppSettings.LastProductsViewedCookieName, bvin, app.CurrentStore);
         }
     }
 }
 /// <summary></summary>
 public void Enqueue(T item)
 {
     lock (_Locker)
     {
         _Queue.Enqueue(item);
     }
 }
        public void ClearQueue()
        {
            lock (this)
            {
                // List of tasks that should be re-add after the queue is cleared.
                // This are tasks that are not allowed to be cancelled.
                List <FFmpegTask> addAgainAfterClear = new List <FFmpegTask>();

                // Clear all task references and empty queue.
                while (_queue.Count > 0)
                {
                    FFmpegTask task = _queue.Dequeue();

                    if (task.ForceCompletion)
                    {
                        addAgainAfterClear.Add(task);
                    }
                }
                _queue.Clear();

                // Add the "forced to complete" items again to the queue.
                foreach (FFmpegTask task in addAgainAfterClear)
                {
                    _queue.Enqueue(task);
                }
            }
        }
Пример #6
0
        public void createScript(string Authorname, string NameOfScript)
        {
            // Der Benutzer muss bereits existieren
            if (Users.ExistsBo(Authorname))
            {
                if (!Scripts.ExistsBo(CanvasScriptKey.Create(Authorname, NameOfScript)))
                {
                    var user = Users.GetBo(Authorname);

                    var entity = new CanvasScript();
                    entity._Name         = NameOfScript;
                    entity._Created      = DateTime.Now;
                    entity._Author       = user.Name;
                    entity._ScriptAsJson = CanvasScriptServer.Bo.PredefinedScripts.DefaultScript;
                    _cudActions.Enqueue(() => _ScriptsTab.Add(entity));
                }
                else
                {
                    throw new System.Data.ConstraintException("Das Skript " + NameOfScript + " für den Autor " + Authorname + " existiert bereits");
                }
            }
            else
            {
                throw new System.Data.ConstraintException("Scriptautor " + Authorname + " existiert nicht. Das Skript " + NameOfScript + " konnte nicht angelegt werden");
            }
        }
Пример #7
0
        public static IEnumerable <(GraphNode node, int distance)> FindPaths(GraphNode startGraphNode)
        {
            var queue   = new System.Collections.Generic.Queue <GraphNode>();
            var visited = new HashSet <GraphNode>();
            var result  = new List <(GraphNode, int)>();

            queue.Enqueue(startGraphNode);
            var distance = 1;

            while (queue.Count != 0)
            {
                var nodes = queue.ToList();
                queue.Clear();
                foreach (var node in nodes)
                {
                    visited.Add(node);
                    foreach (var incidentNode in node.Edges.Where(x => !visited.Contains(x)))
                    {
                        queue.Enqueue(incidentNode);
                        result.Add((incidentNode, distance));
                    }
                }

                distance++;
            }

            return(result);
        }
Пример #8
0
        // level order
        public string BreadthFirstSearch(int startValue)
        {
            bool[] visited = new bool[vertices];
            System.Collections.Generic.Queue <GraphNode> queue = new System.Collections.Generic.Queue <GraphNode>();
            StringBuilder sb = new StringBuilder();

            int index = startValue;

            queue.Enqueue(adjLists[index]);
            visited[index] = true;

            while (queue.Count > 0)
            {
                var graphNode = queue.Dequeue();
                sb.Append(graphNode.value + " ");

                // print value graphNode.value
                for (int i = 0; i < graphNode.Edges.Count; i++)
                {
                    int adjIndex = graphNode.Edges[i];
                    if (!visited[adjIndex])
                    {
                        visited[adjIndex] = true;
                        queue.Enqueue(adjLists[adjIndex]);
                    }
                }
            }

            return(sb.ToString());
        }
        public void LineByLineLevelOrderTraversal(Bnode <int> head)
        {
            var q = new System.Collections.Generic.Queue <Bnode <int> >();

            q.Enqueue(head);
            int curlevel  = 1;
            int nextlevel = 0;

            while (q.Count > 0)
            {
                var node = q.Dequeue();
                curlevel--;

                if (node.left != null)
                {
                    q.Enqueue(node.left);
                    nextlevel++;
                }
                if (node.right != null)
                {
                    q.Enqueue(node.right);
                    nextlevel++;
                }

                if (curlevel == 0)
                {
                    curlevel = nextlevel;
                    curlevel = 0;
                    Console.Write("\n");
                }
            }
        }
Пример #10
0
        /// <summary>
        /// 文件夹遍历方法(广度优先算法)
        /// </summary>
        /// <param name="sPathName">起始文件夹</param>
        public static FileInfo[] TraversingAllFiles(string sPathName)
        {
            System.Collections.ArrayList al = new System.Collections.ArrayList();
            //创建一个队列用于保存子目录
            System.Collections.Generic.Queue <string> pathQueue = new System.Collections.Generic.Queue <string>();
            //首先把根目录排入队中
            pathQueue.Enqueue(sPathName);
            //开始循环查找文件,直到队列中无任何子目录
            string path = string.Empty;

            while (pathQueue.Count > 0)
            {
                //从队列中取出一个目录,把该目录下的所有子目录排入队中
                path = pathQueue.Dequeue();

                foreach (DirectoryInfo diChild in GetAllDirPath(path))
                {
                    pathQueue.Enqueue(diChild.FullName);
                }

                //查找该目录下的所有文件,依次处理
                foreach (FileInfo fi in GetAllFilePath(path))
                {
                    al.Add(fi);
                }
            }
            return((FileInfo[])al.ToArray(typeof(FileInfo)));
        }
Пример #11
0
    /// <summary>
    /// 异步加载AB
    /// </summary>
    /// <param name="abPath"></param>
    public void LoadAssetBundleAsyn(string abPath)
    {
        CMAssetBundle cmAB = null;

        if (!m_dicAssetBundleDatas.TryGetValue(abPath, out cmAB))
        {
            cmAB = CMAssetBundle.Create(abPath);
            m_dicAssetBundleDatas.Add(abPath, cmAB);
        }
        if (cmAB.GetTaskState() != CMABTaskState.CMTaskState_None)
        {
            //已经在加载了
            return;
        }

        string[] dependenciesPath = GetABAllDependencies(cmAB.ABPath);

        if (null != dependenciesPath)
        {
            for (int i = 0, max = dependenciesPath.Length; i < max; i++)
            {
                if (!waitingABPath.Contains(dependenciesPath[i]))
                {
                    waitingABPath.Enqueue(dependenciesPath[i]);
                }
            }
        }

        waitingABPath.Enqueue(abPath);
        cmAB.OnWaitingStart();
        //DoNextABLoad();
        ProcessABLoadAsyn();
    }
Пример #12
0
        /// <summary>
        /// store a list to file and refresh list
        /// </summary>
        /// <param name="path"></param>
        private void SaveRecentFile(string path)
        {
            recentToolStripMenuItem.DropDownItems.Clear(); //clear all recent list from menu
            LoadRecentList();                              //load list from file
            if (!(MRUlist.Contains(path)))                 //prevent duplication on recent list
            {
                MRUlist.Enqueue(path);                     //insert given path into list
            }
            while (MRUlist.Count > MRUnumber)              //keep list number not exceeded given value
            {
                MRUlist.Dequeue();
            }
            foreach (string item in MRUlist)
            {
                ToolStripMenuItem fileRecent = new ToolStripMenuItem(item, null, RecentFile_click); //create new menu for each item in list
                recentToolStripMenuItem.DropDownItems.Add(fileRecent);                              //add the menu to "recent" menu
            }
            //writing menu list to file
            StreamWriter stringToWrite = new StreamWriter(System.Environment.CurrentDirectory + "\\Recent.txt"); //create file called "Recent.txt" located on app folder

            foreach (string item in MRUlist)
            {
                stringToWrite.WriteLine(item); //write list to stream
            }
            stringToWrite.Flush();             //write stream to file
            stringToWrite.Close();             //close the stream and reclaim memory
        }
Пример #13
0
        public IEnumerable <IEnumerable <int> > TraverseByLevel()
        {
            var nodesQueue = new System.Collections.Generic.Queue <Node>();

            nodesQueue.Enqueue(_root);

            while (nodesQueue.Count > 0)
            {
                var currentLevelNodes = nodesQueue.Count;
                var currentLevel      = new List <int>();
                for (var index = 0; index < currentLevelNodes; ++index)
                {
                    var node = nodesQueue.Dequeue();
                    currentLevel.Add(node.Value);
                    if (node.Left != null)
                    {
                        nodesQueue.Enqueue(node.Left);
                    }
                    if (node.Right != null)
                    {
                        nodesQueue.Enqueue(node.Right);
                    }
                }

                yield return(currentLevel);
            }
        }
        public void Reset(Stream stream)
        {
            TraceOutput(TraceBits.Session, "-------------------------------------------------------");
            TraceOutput(TraceBits.Session, "Reset {0:X8} firstDone({1})", this.GetHashCode(), _firstWriteDone);

            if (!_firstWriteDone)
            {
                return;
            }

            // reset all status
            _toWrite.Clear();
            _toFill.Clear();
            foreach (var workitem in _pool)
            {
                _toFill.Enqueue(workitem.index);
                workitem.ordinal = -1;
            }

            _firstWriteDone      = false;
            _totalBytesProcessed = 0L;
            _runningCrc          = new Ionic.Crc.CRC32();
            _isClosed            = false;
            _currentlyFilling    = -1;
            _lastFilled          = -1;
            _lastWritten         = -1;
            _latestCompressed    = -1;
            _outStream           = stream;
        }
 public static void RecordProductViews(string bvin, MerchantTribeApplication app)
 {
     if (WebAppSettings.LastProductsViewedCookieName != string.Empty)
     {
         string SavedProductIDs = SessionManager.GetCookieString(WebAppSettings.LastProductsViewedCookieName, app.CurrentStore);
         if (SavedProductIDs != string.Empty)
         {
             string[] AllIDs = SavedProductIDs.Split(',');
             System.Collections.Generic.Queue<string> q = new System.Collections.Generic.Queue<string>();
             q.Enqueue(bvin);
             foreach (string id in AllIDs)
             {
                 if (q.Count < 10)
                 {
                     if (!q.Contains(id))
                     {
                         q.Enqueue(id);
                     }
                 }
             }
             SessionManager.SetCookieString(WebAppSettings.LastProductsViewedCookieName, string.Join(",", q.ToArray()), app.CurrentStore);
         }
         else
         {
             SessionManager.SetCookieString(WebAppSettings.LastProductsViewedCookieName, bvin, app.CurrentStore);
         }
     }
 }
Пример #16
0
 public void MockReceive(byte[] data, UdpEndPoint fromEndPoint)
 {
     _ReceiveQueue.Enqueue(new ReceivedUdpData()
     {
         Buffer = data, ReceivedFrom = fromEndPoint, ReceivedBytes = data.Length
     });
     _DataAvailableSignal.Set();
 }
Пример #17
0
        private void Instance_QRCodeAdded(object sender, QRCodeEventArgs <Microsoft.MixedReality.QR.QRCode> e)
        {
            Debug.Log("QRCodesVisualizer Instance_QRCodeAdded");

            lock (pendingActions)
            {
                pendingActions.Enqueue(new ActionData(ActionData.Type.Added, e.Data));
            }
        }
Пример #18
0
        private void Instance_QRCodeAdded(object sender, QRCodeEventArgs <QRCodesTrackerPlugin.QRCode> e)
        {
            Debug.Log("QRCodesVisualizer Instance_QRCodeAdded");

            lock (pendingActions)
            {
                pendingActions.Enqueue(new ActionData(ActionData.Type.Added, e.Data));
            }
        }
Пример #19
0
 private void GraffitiForm_MouseDown(object sender, MouseEventArgs e)
 {
     if (this.rectangleRadioButton.Checked)
     {
         if (e.Button == MouseButtons.Left)
         {
             if (isDown)
             {
                 this.Invalidate();
                 Point pNow = new Point(e.X, e.Y);
                 DrawRectangle(lineColor, this.prept, new Size(pNow.X - this.prept.X, pNow.Y - this.prept.Y));
                 this.movept = pNow;
                 pQueue.Enqueue(new Rectangle(this.prept.X, this.prept.Y, pNow.X - this.prept.X, pNow.Y - this.prept.Y));
                 //DrawLine(lineColor, this.prept, pNow);
                 this.prept = pNow;
                 isDown     = false;
             }
             else
             {
                 this.prept = new Point(e.X, e.Y);
                 isDown     = true;
             }
             //this.pQueue.Enqueue(this.prept);
         }
         if (e.Button == MouseButtons.Right)
         {
             isDown = false;
             //DrawLine(this.bColor, this.prept, this.movept);
         }
     }
     if (this.lineRadioButton.Checked)
     {
         if (e.Button == MouseButtons.Left)
         {
             if (isDown)
             {
                 this.Invalidate();
                 Point pNow = new Point(e.X, e.Y);
                 DrawLine(lineColor, this.prept, pNow);
                 this.prept  = pNow;
                 this.movept = pNow;
             }
             else
             {
                 this.prept = new Point(e.X, e.Y);
                 isDown     = true;
             }
             this.pQueue.Enqueue(this.prept);
         }
         if (e.Button == MouseButtons.Right)
         {
             isDown = false;
             DrawLine(this.bColor, this.prept, this.movept);
         }
     }
 }
        public override ValidationError ValidateActivityChange(Activity activity, ActivityChangeAction action)
        {
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }

            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            AddedActivityAction addedAction = action as AddedActivityAction;

            if (addedAction != null)
            {
                //Check existence of nested PersistOnClose/ICompensatable/SupportsTransaction nested anywhere
                //in the added activity branch
                System.Collections.Generic.Queue <Activity> childrenQueue = new System.Collections.Generic.Queue <Activity>();
                childrenQueue.Enqueue(addedAction.AddedActivity);

                while (childrenQueue.Count != 0)
                {
                    Activity childActivity = childrenQueue.Dequeue();

                    if (childActivity.SupportsTransaction)
                    {
                        return(new ValidationError(SR.GetString(SR.Error_AtomicScopeNestedInNonLRT), ErrorNumbers.Error_AtomicScopeNestedInNonLRT));
                    }

                    if (childActivity.PersistOnClose)
                    {
                        return(new ValidationError(SR.GetString(SR.Error_NestedPersistOnClose, activity.QualifiedName), ErrorNumbers.Error_NestedPersistOnClose));
                    }

                    if (childActivity is ICompensatableActivity)
                    {
                        return(new ValidationError(SR.GetString(SR.Error_NestedCompensatableActivity, activity.QualifiedName), ErrorNumbers.Error_NestedCompensatableActivity));
                    }

                    CompositeActivity compositeActivity = childActivity as CompositeActivity;

                    if (compositeActivity != null)
                    {
                        foreach (Activity grandChild in compositeActivity.EnabledActivities)
                        {
                            childrenQueue.Enqueue(grandChild);
                        }
                    }
                }
            }
            return(base.ValidateActivityChange(activity, action));
        }
Пример #21
0
        private void ReaddChildNodes(Node removedNode)
        {
            // Leaf Check
            if (removedNode.LeftChild == null && removedNode.RightChild == null)
            {
                return;
            }

            // The folllowing code might seem a little redundant but we're using
            // 2 queues so we can add the child nodes back in, in (more or less)
            // the same order they were added in the first place
            var nodesToReadd = new System.Collections.Generic.Queue <Node>();

            var nodesToReaddQueue = new System.Collections.Generic.Queue <Node>();

            if (removedNode.LeftChild != null)
            {
                nodesToReaddQueue.Enqueue(removedNode.LeftChild);
            }

            if (removedNode.RightChild != null)
            {
                nodesToReaddQueue.Enqueue(removedNode.RightChild);
            }

            while (nodesToReaddQueue.Count > 0)
            {
                Node nodeToReadd = nodesToReaddQueue.Dequeue();

                nodesToReadd.Enqueue(nodeToReadd);

                if (nodeToReadd.LeftChild != null)
                {
                    nodesToReaddQueue.Enqueue(nodeToReadd.LeftChild);
                    nodeToReadd.LeftChild = null;
                }

                if (nodeToReadd.RightChild != null)
                {
                    nodesToReaddQueue.Enqueue(nodeToReadd.RightChild);
                    nodeToReadd.RightChild = null;
                }
            }

            while (nodesToReadd.Count > 0)
            {
                var nodeToReadd = nodesToReadd.Dequeue();

                this._count--;
                Add(this._locate(nodeToReadd.Value), nodeToReadd.Value);
            }
        }
Пример #22
0
        public void BFS(TextWriter tw)
        {
            System.Collections.Generic.Queue <BSTNode <T> > traversalQueue = new System.Collections.Generic.Queue <BSTNode <T> >();

            traversalQueue.Enqueue(Root);

            while (traversalQueue.Count > 0)
            {
                var tmp = traversalQueue.Dequeue();
                tw.WriteLine(tmp.Value);
                traversalQueue.Enqueue(tmp.LeftChild);
                traversalQueue.Enqueue(tmp.RightChild);
            }
        }
Пример #23
0
    public void Push(int input)
    {
        queue2.Enqueue(input);

        while (queue1.Count > 0)
        {
            queue2.Enqueue(queue1.Dequeue());
        }

        var temp = queue1;

        queue1 = queue2;
        queue2 = temp;
    }
Пример #24
0
    void onchanged(object source, System.IO.FileSystemEventArgs e)
    {
        log(String.Format("modified {0}", e.Name));
        var name = nameof(e.FullPath, true);

        log(String.Format("Recompiling {0}", name));
        if (rezolve.ContainsKey(name))
        {
            Action thejam = delegate() { glitch_object(name); };
            lock (queuelock) {
                queue.Enqueue(thejam);
            }
        }
        Compile(name, e.FullPath);
    }
Пример #25
0
 private void ReceiveData()
 {
     try {
         while (true)
         {
             _IdleQueue.Enqueue(_Reader.ReadLine());
             //if (!_Stream.DataAvailable) {
             _IdleEventsMre.Set();
             //}
         }
     } catch (ThreadAbortException) {
     } catch (Exception ex) {
         Console.WriteLine(ex.Message);
     }
 }
Пример #26
0
 protected override void HandleDataPoints(DataPoint[] dataPoints)
 {
     foreach (DataPoint dataPoint in dataPoints)
     {
         waitingPoints.Enqueue(dataPoint);
     }
 }
Пример #27
0
        public FileMessageQueue(string queueName, string path)
        {
            m_QueueName = queueName;
            m_Path      = path;
            m_Event     = new ManualResetEvent(false);
            m_Queue     = new Queue <string>(1000000);

            if (path.StartsWith("."))
            {
                var directory = System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location);
                path = System.IO.Path.Combine(directory.TrimEnd('\\'), path.TrimStart('.').TrimStart('\\'));
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
            }

            m_FileWatcher              = new FileSystemWatcher();
            m_FileWatcher.Path         = path;
            m_FileWatcher.NotifyFilter = NotifyFilters.CreationTime;
            m_FileWatcher.Created     += (s, arg) =>
            {
                m_Queue.Enqueue(arg.FullPath);
                m_Event.Set();
            };
            m_FileWatcher.Filter = Filter;
            m_FileWatcher.EnableRaisingEvents = true;
        }
Пример #28
0
 void log(string mesg)
 {
     lock (errorlock) {
         log_queue.Enqueue(mesg);
     }
     Debug.Log(mesg);
 }
Пример #29
0
        private void queueNewPiece()
        {
            TetrisShape.TetrisShapes ts1 = (TetrisShape.TetrisShapes)Convert.ToInt32(_rnd.NextDouble() * 7);
            TetrisShape.TetrisShapes ts2 = (TetrisShape.TetrisShapes)Convert.ToInt32(_rnd.NextDouble() * 7);
            TetrisShape newShape;

            if (ts1 == TetrisShape.TetrisShapes.I)
            {
                newShape = new TetrisShape(ts1);
            }
            else
            {
                newShape = new TetrisShape(ts2);
            }
            // set the style
            newShape.setStroke(Border1);


            newShape.movePiece(TetrisShape.TetrisMoves.LEFT, 8);
            newShape.movePiece(TetrisShape.TetrisMoves.DOWN, 8);
            shapeQueue.Enqueue(newShape);
            // move all piece is the queue up enough space to fit the new piece.
            foreach (TetrisShape ts in shapeQueue)
            {
                ts.movePiece(TetrisShape.TetrisMoves.UP, 4);
                updateShape(ts, TimeSpan.FromMilliseconds(_gameTimer.Interval));
            }
        }
Пример #30
0
        public void EnQueue(ThreadTask o, bool spin)
        {
            // If the queue is full, wait for an item to be removed
            while (queue.Count >= maxSize)
            {
                if (terminate)
                {
                    throw new CollectionTerminatedException();
                }
                if (!spin || processorCount == 1)
                {
                    Factory.Parallel.Yield();
                }
                enqueueSpins++;
            }
            enqueueSpins += Lock(spin);
            ThreadTask task = (ThreadTask)o;

            queue.Enqueue(task);

            // We always need to pulse, even if the queue wasn't
            // empty before. Otherwise, if we add several items
            // in quick succession, we may only pulse once, waking
            // a single thread up, even if there are multiple threads
            // waiting for items.
            UnLock();
        }
Пример #31
0
 /// <summary>
 /// AddData
 /// </summary>
 /// <param name="data"></param>
 public void AddData(RTPPacket packet)
 {
     try
     {
         //Wenn kein Überlauf
         if (m_Overflow == false)
         {
             //Maximalgrösse beachten
             if (m_Buffer.Count <= m_MaxRTPPackets)
             {
                 m_Buffer.Enqueue(packet);
                 //m_Buffer.OrderBy(x => x.SequenceNumber);
             }
             else
             {
                 //Bufferüberlauf
                 m_Overflow = true;
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(String.Format("JitterBuffer.cs | AddData() | {0}", ex.Message));
     }
 }
        public override ValidationError ValidateActivityChange(Activity activity, ActivityChangeAction action)
        {
            if (activity == null)
                throw new ArgumentNullException("activity");

            if (action == null)
                throw new ArgumentNullException("action");

            AddedActivityAction addedAction = action as AddedActivityAction;

            if (addedAction != null)
            {
                //Check existence of nested PersistOnClose/ICompensatable/SupportsTransaction nested anywhere
                //in the added activity branch
                System.Collections.Generic.Queue<Activity> childrenQueue = new System.Collections.Generic.Queue<Activity>();
                childrenQueue.Enqueue(addedAction.AddedActivity);

                while (childrenQueue.Count != 0)
                {
                    Activity childActivity = childrenQueue.Dequeue();

                    if (childActivity.SupportsTransaction)
                        return new ValidationError(SR.GetString(SR.Error_AtomicScopeNestedInNonLRT), ErrorNumbers.Error_AtomicScopeNestedInNonLRT);

                    if (childActivity.PersistOnClose)
                        return new ValidationError(SR.GetString(SR.Error_NestedPersistOnClose, activity.QualifiedName), ErrorNumbers.Error_NestedPersistOnClose);

                    if (childActivity is ICompensatableActivity)
                        return new ValidationError(SR.GetString(SR.Error_NestedCompensatableActivity, activity.QualifiedName), ErrorNumbers.Error_NestedCompensatableActivity);

                    CompositeActivity compositeActivity = childActivity as CompositeActivity;

                    if (compositeActivity != null)
                    {
                        foreach (Activity grandChild in compositeActivity.EnabledActivities)
                        {
                            childrenQueue.Enqueue(grandChild);
                        }
                    }
                }
            }
            return base.ValidateActivityChange(activity, action);
        }
        private void _InitializePoolOfWorkItems()
        {
            _toWrite = new Queue<int>();
            _toFill = new Queue<int>();
            _pool = new System.Collections.Generic.List<WorkItem>();
            int nTasks = BufferPairsPerCore * Environment.ProcessorCount;
            nTasks = Math.Min(nTasks, _maxBufferPairs);
            for(int i=0; i < nTasks; i++)
            {
                _pool.Add(new WorkItem(_bufferSize, _compressLevel, Strategy, i));
                _toFill.Enqueue(i);
            }

            _newlyCompressedBlob = new AutoResetEvent(false);
            _runningCrc = new CRC32();
            _currentlyFilling = -1;
            _lastFilled = -1;
            _lastWritten = -1;
            _latestCompressed = -1;
        }