public static int HighlightAllNodes(TreeView CallGraphTreeView, string InText, bool bTextIsRegex, bool bInMatchCase, out TreeNode FirstResult, out long AllocationSize, out int AllocationCount)
        {
            var SearchParams = new FNodeSearchParams(InText, bTextIsRegex, bInMatchCase);

            var MatchingNodes   = new List <FCallGraphNode>();
            var NodeSearchState = new FNodeSearchState();

            foreach (FCallGraphNode RootNode in ((FCallGraphTreeViewTag)CallGraphTreeView.Tag).RootNodes)
            {
                GetAllMatchingNodes(RootNode, MatchingNodes, NodeSearchState, SearchParams);
            }

            CallGraphTreeView.BeginUpdate();
            foreach (FCallGraphNode MatchingNode in MatchingNodes)
            {
                EnsureTreeNode(MatchingNode);

                MatchingNode.TreeNode.BackColor = Color.CornflowerBlue;
                MatchingNode.TreeNode.EnsureVisible();
            }
            CallGraphTreeView.EndUpdate();

            FirstResult = null;
            if (MatchingNodes.Count > 0)
            {
                FirstResult = MatchingNodes[0].TreeNode;
            }

            AllocationSize  = NodeSearchState.AllocationSize;
            AllocationCount = NodeSearchState.AllocationCount;

            return(MatchingNodes.Count);
        }
        public static int HighlightAllNodes(TreeView CallGraphTreeView, string InText, bool bTextIsRegex, bool bInMatchCase, out TreeNode FirstResult, out long AllocationSize, out int AllocationCount)
        {
            SetUpSearchVariables(InText, bTextIsRegex, bInMatchCase);

            FNodeSearchState NodeSearchState = new FNodeSearchState();

            FirstResult = null;
            int ResultCount = HighlightAllNodesAux(CallGraphTreeView, CallGraphTreeView.Nodes, NodeSearchState, ref FirstResult);

            if (FirstResult != null)
            {
                FirstResult.EnsureVisible();
            }

            AllocationSize  = NodeSearchState.AllocationSize;
            AllocationCount = NodeSearchState.AllocationCount;

            return(ResultCount);
        }
        private static int HighlightAllNodesAux(TreeView CallGraphTreeView, TreeNodeCollection TreeNodes, FNodeSearchState SearchState, ref TreeNode FirstResult)
        {
            int ResultCount = 0;

            for (int NodeIndex = 0; NodeIndex < TreeNodes.Count; NodeIndex++)
            {
                TreeNode N          = TreeNodes[NodeIndex];
                bool     bNodeMatch = false;
                if (SearchRegex != null)
                {
                    bNodeMatch = SearchRegex.Match(N.Text).Success;
                }
                else
                {
                    if (bMatchCase)
                    {
                        bNodeMatch = N.Text.IndexOf(SearchText, StringComparison.InvariantCulture) != -1;
                    }
                    else
                    {
                        bNodeMatch = N.Text.IndexOf(SearchText, StringComparison.InvariantCultureIgnoreCase) != -1;
                    }
                }

                if (bNodeMatch)
                {
                    if (FirstResult == null)
                    {
                        FirstResult = N;
                    }

                    N.BackColor = Color.CornflowerBlue;
                    N.EnsureVisible();
                    ResultCount++;

                    FNodePayload payload = ( FNodePayload )N.Tag;
                    if (!SearchState.CallStacks.Contains(payload.CallStacks[0]))
                    {
                        // if one callstack from this node is new, then all must be, due to the way the graph is arranged
                        // and the order in which it is searched

                        SearchState.CallStacks.AddRange(payload.CallStacks);
                        SearchState.AllocationCount += payload.AllocationCount;
                        SearchState.AllocationSize  += payload.AllocationSize;
                    }
                }

                ResultCount += HighlightAllNodesAux(CallGraphTreeView, N.Nodes, SearchState, ref FirstResult);
            }

            return(ResultCount);
        }
        private static void GetAllMatchingNodes(FCallGraphNode ParentNode, List <FCallGraphNode> MatchingNodes, FNodeSearchState SearchState, FNodeSearchParams SearchParams)
        {
            foreach (FCallGraphNode ChildNode in ParentNode.Children)
            {
                if (SearchParams.DoesNodeMatchSearch(ChildNode))
                {
                    MatchingNodes.Add(ChildNode);

                    if (!SearchState.CallStacks.Contains(ChildNode.CallStacks[0]))
                    {
                        // If one callstack from this node is new, then all must be, due to the way the graph is arranged and the order in which it is searched
                        foreach (FCallStack CallStack in ChildNode.CallStacks)
                        {
                            SearchState.CallStacks.Add(CallStack);
                        }
                        SearchState.AllocationSize  += ChildNode.AllocationSize;
                        SearchState.AllocationCount += ChildNode.AllocationCount;
                    }
                }

                GetAllMatchingNodes(ChildNode, MatchingNodes, SearchState, SearchParams);
            }
        }
        private static int HighlightAllNodesAux( TreeView CallGraphTreeView, TreeNodeCollection TreeNodes, FNodeSearchState SearchState, ref TreeNode FirstResult )
        {
            int ResultCount = 0;

            for( int NodeIndex = 0; NodeIndex < TreeNodes.Count; NodeIndex++ )
            {
                TreeNode N = TreeNodes[ NodeIndex ];
                bool bNodeMatch = false;
                if( SearchRegex != null )
                {
                    bNodeMatch = SearchRegex.Match( N.Text ).Success;
                }
                else
                {
                    if( bMatchCase )
                    {
                        bNodeMatch = N.Text.IndexOf( SearchText, StringComparison.InvariantCulture ) != -1;
                    }
                    else
                    {
                        bNodeMatch = N.Text.IndexOf( SearchText, StringComparison.InvariantCultureIgnoreCase ) != -1;
                    }
                }

                if( bNodeMatch )
                {
                    if( FirstResult == null )
                    {
                        FirstResult = N;
                    }

                    N.BackColor = Color.CornflowerBlue;
                    N.EnsureVisible();
                    ResultCount++;

                    FNodePayload payload = ( FNodePayload )N.Tag;
                    if( !SearchState.CallStacks.Contains( payload.CallStacks[ 0 ] ) )
                    {
                        // if one callstack from this node is new, then all must be, due to the way the graph is arranged
                        // and the order in which it is searched

                        SearchState.CallStacks.AddRange( payload.CallStacks );
                        SearchState.AllocationCount += payload.AllocationCount;
                        SearchState.AllocationSize += payload.AllocationSize;
                    }
                }

                ResultCount += HighlightAllNodesAux( CallGraphTreeView, N.Nodes, SearchState, ref FirstResult );
            }

            return ResultCount;
        }
        public static int HighlightAllNodes( TreeView CallGraphTreeView, string InText, bool bTextIsRegex, bool bInMatchCase, out TreeNode FirstResult, out long AllocationSize, out int AllocationCount )
        {
            SetUpSearchVariables( InText, bTextIsRegex, bInMatchCase );

            FNodeSearchState NodeSearchState = new FNodeSearchState();
            FirstResult = null;
            int ResultCount = HighlightAllNodesAux( CallGraphTreeView, CallGraphTreeView.Nodes, NodeSearchState, ref FirstResult );

            if( FirstResult != null )
            {
                FirstResult.EnsureVisible();
            }

            AllocationSize = NodeSearchState.AllocationSize;
            AllocationCount = NodeSearchState.AllocationCount;

            return ResultCount;
        }
		private static void GetAllMatchingNodes(FCallGraphNode ParentNode, List<FCallGraphNode> MatchingNodes, FNodeSearchState SearchState, FNodeSearchParams SearchParams)
		{
			foreach (FCallGraphNode ChildNode in ParentNode.Children)
			{
				if (SearchParams.DoesNodeMatchSearch(ChildNode))
				{
					MatchingNodes.Add(ChildNode);

					if (!SearchState.CallStacks.Contains(ChildNode.CallStacks[0]))
					{
						// If one callstack from this node is new, then all must be, due to the way the graph is arranged and the order in which it is searched
						foreach (FCallStack CallStack in ChildNode.CallStacks)
						{
							SearchState.CallStacks.Add(CallStack);
						}
						SearchState.AllocationSize += ChildNode.AllocationSize;
						SearchState.AllocationCount += ChildNode.AllocationCount;
					}
				}

				GetAllMatchingNodes(ChildNode, MatchingNodes, SearchState, SearchParams);
			}
		}
		public static int HighlightAllNodes( TreeView CallGraphTreeView, string InText, bool bTextIsRegex, bool bInMatchCase, out TreeNode FirstResult, out long AllocationSize, out int AllocationCount )
		{
			var SearchParams = new FNodeSearchParams(InText, bTextIsRegex, bInMatchCase);

			var MatchingNodes = new List<FCallGraphNode>();
			var NodeSearchState = new FNodeSearchState();
			foreach (FCallGraphNode RootNode in ((FCallGraphTreeViewTag)CallGraphTreeView.Tag).RootNodes)
			{
				GetAllMatchingNodes(RootNode, MatchingNodes, NodeSearchState, SearchParams);
			}

			CallGraphTreeView.BeginUpdate();
			foreach (FCallGraphNode MatchingNode in MatchingNodes)
			{
				EnsureTreeNode(MatchingNode);

				MatchingNode.TreeNode.BackColor = Color.CornflowerBlue;
				MatchingNode.TreeNode.EnsureVisible();
			}
			CallGraphTreeView.EndUpdate();

			FirstResult = null;
			if (MatchingNodes.Count > 0)
			{
				FirstResult = MatchingNodes[0].TreeNode;
			}

			AllocationSize = NodeSearchState.AllocationSize;
			AllocationCount = NodeSearchState.AllocationCount;

			return MatchingNodes.Count;
		}