예제 #1
0
 public void StartSearch(Node node, String searchText, SearchProgress updator, ReflectionSearchResult resultRoot)
 {
     if (searchCoroutine != null)
     {
         StopCoroutine(searchCoroutine);
         searchCoroutine = null;
     }
     VisitedInstanceIDs.Clear();
     resultRoot.Clear();
     resultRoot.Node = node;
     StopAllCoroutines();
     updator(0, 0, 1);
     if (node == null)
     {
         return;
     }
     SequenceNumber++;
     Main.Log($"seq: {SequenceNumber} - search for: {searchText}");
     if (searchText.Length == 0)
     {
     }
     else
     {
         var todo = new List <Node> {
             node
         };
         searchCoroutine = Search(searchText, todo, 0, 0, SequenceNumber, updator, resultRoot);
         StartCoroutine(searchCoroutine);
     }
 }
예제 #2
0
        private IEnumerator Search(String searchText, List <Node> todo, int depth, int visitCount, int sequenceNumber, SearchProgress updator, ReflectionSearchResult resultRoot)
        {
            yield return(null);

            if (sequenceNumber != SequenceNumber)
            {
                yield return(null);
            }
            var todoText = todo.Count > 0 ? todo.First().Name : "n/a";
            //Main.Log(depth, $"seq: {sequenceNumber} depth: {depth} - count: {todo.Count} - todo[0]: {todoText}");
            var newTodo = new List <Node> {
            };
            var breadth = todo.Count();

            foreach (var node in todo)
            {
                bool foundMatch    = false;
                var  instanceID    = node.InstanceID;
                bool alreadyVisted = false;
                if (instanceID is int instID)
                {
                    if (VisitedInstanceIDs.Contains(instID))
                    {
                        alreadyVisted = true;
                    }
                    else
                    {
                        VisitedInstanceIDs.Add(instID);
                    }
                }
                visitCount++;
                //Main.Log(depth, $"node: {node.Name} - {node.GetPath()}");
                try {
                    if (Matches(node.Name, searchText) || Matches(node.ValueText, searchText))
                    {
                        foundMatch = true;
                        updator(visitCount, depth, breadth);
                        resultRoot.AddSearchResult(node);
                        Main.Log(depth, $"matched: {node.GetPath()} - {node.ValueText}");
                        Main.Log($"{resultRoot.ToString()}");
                    }
                }
                catch (Exception e) {
                    Main.Log(depth, $"caught - {e}");
                }
                node.Matches = foundMatch;
                if (!foundMatch)
                {
                    //Main.Log(depth, $"NOT matched: {node.Name} - {node.ValueText}");
                    //if (node.Expanded == ToggleState.On && node.GetParent() != null) {
                    //    node.Expanded = ToggleState.Off;
                    //}
                    if (visitCount % 100 == 0)
                    {
                        updator(visitCount, depth, breadth);
                    }
                }
                if (node.hasChildren && !alreadyVisted)
                {
                    if (node.InstanceID is int instID2 && instID2 == this.GetInstanceID())
                    {
                        break;
                    }
                    if (node.Name == "searchCoroutine")
                    {
                        break;
                    }
                    //if (node.Name == "SyncRoot") break;
                    //if (node.Name == "normalized") break;

                    try {
                        foreach (var child in node.GetItemNodes())
                        {
                            //Main.Log(depth + 1, $"item: {child.Name}");
                            newTodo.Add(child);
                        }
                    }
                    catch (Exception e) {
                        Main.Log(depth, $"caught - {e}");
                    }
                    try {
                        foreach (var child in node.GetComponentNodes())
                        {
                            //Main.Log(depth + 1, $"comp: {child.Name}");
                            newTodo.Add(child);
                        }
                    }
                    catch (Exception e) {
                        Main.Log(depth, $"caught - {e}");
                    }
                    try {
                        foreach (var child in node.GetPropertyNodes())
                        {
                            //Main.Log(depth + 1, $"prop: {child.Name}");
                            newTodo.Add(child);
                        }
                    }
                    catch (Exception e) {
                        Main.Log(depth, $"caught - {e}");
                    }
                    try {
                        foreach (var child in node.GetFieldNodes())
                        {
                            //Main.Log(depth + 1, $"field: {child.Name}");
                            newTodo.Add(child);
                        }
                    }
                    catch (Exception e) {
                        Main.Log(depth, $"caught - {e}");
                    }
                }
                if (visitCount % 1000 == 0)
                {
                    yield return(null);
                }
            }
            if (newTodo.Count > 0 && depth < Main.settings.maxSearchDepth)
            {
                yield return(Search(searchText, newTodo, depth + 1, visitCount, sequenceNumber, updator, resultRoot));
            }
            else
            {
                Stop();
            }
        }