예제 #1
0
        private void OnGUI()
        {
            if (lastPassDetectedNoWebTestsSoDisplayDebugAsExample && testsAndTheirDependenciesList.Count == 0)
            {
                MapDependencies();
            }

            GUIStyle refButton = new GUIStyle(GUI.skin.button);

            refButton.normal.textColor = EditorGUIUtility.isProSkin ? Color.white : Color.black;
            Color defaultBgColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.gray;
            if (GUI.Button(new Rect(0, 0, 75, 25), "Refresh", refButton))
            {
                inspectedNodeWindow           = -1;
                RenderedNodes                 = new List <DependencyNode>();
                testsAndTheirDependenciesList = new List <KeyValuePair <string, string[]> >();
                DependencyWebs                = new List <DependencyNode>();
                MapDependencies();
            }
            GUI.backgroundColor = defaultBgColor;

            Rect allSize = new Rect(0, 0, lastRenderX + infoBoxMinWidth, maxWindowY + infoBoxMinWidth);

            scroll = GUI.BeginScrollView(new Rect(0, 0, lastRenderX, lastRenderY), scroll, new Rect(0, 0, lastRenderX + infoBoxMinWidth, lastRenderY + infoBoxMinWidth), GUIStyle.none, GUIStyle.none);
            GUI.Box(allSize, string.Empty);

            for (int all = 0; all < DependencyWebs.Count; all++)
            {
                int            index      = 0;
                DependencyNode parentNode = DependencyWebs[all];
                if (!RenderedNodes.Where(x => x.TestName == parentNode.TestName).Any())
                {
                    RenderedNodes.Add(parentNode);
                    index = RenderedNodes.Count - 1;
                    float width   = DetermineRectWidthBasedOnLengthOfString(RenderedNodes[index].TestName);
                    Rect  newRect = originRect;
                    newRect.width             = width;
                    RenderedNodes[index].rect = GenerateNewNonOverlappingRectPositionForNewNode(newRect);
                }
                else
                {
                    index = RenderedNodes.FindIndex(a => a.TestName == parentNode.TestName);
                }

                //Create new node, or find existing one, and draw lines between this node and the dependency.
                List <KeyValuePair <DependencyNodeConnectionType, string> > LinkedNodeTestNames = RenderedNodes[index].Dependencies.ToList();
                for (int s = 0; s < LinkedNodeTestNames.Count; s++)
                {
                    if (LinkedNodeTestNames[s].Key == DependencyNodeConnectionType.Incoming)
                    {
                        string         testName = LinkedNodeTestNames[s].Value;
                        DependencyNode thisNode = new DependencyNode();

                        int indexChild = 0;

                        List <DependencyNode> match = RenderedNodes.Where(x => x.TestName == testName).ToList();
                        if (!match.Any())
                        {
                            thisNode.TestName     = testName;
                            thisNode.Dependencies = DependencyWebs.Where(x => x.TestName == thisNode.TestName).Select(x => x.Dependencies).Single();
                            RenderedNodes.Add(thisNode);
                            indexChild = RenderedNodes.Count - 1;
                            float width   = DetermineRectWidthBasedOnLengthOfString(RenderedNodes[indexChild].TestName);
                            Rect  newRect = RenderedNodes[all].rect;
                            newRect.width = width;
                            RenderedNodes[indexChild].rect = GenerateNewNonOverlappingRectPositionForNewNode(newRect);
                        }
                        else
                        {
                            indexChild = RenderedNodes.FindIndex(a => a.TestName == testName);
                        }

                        Handles.BeginGUI();
                        Handles.DrawBezier(RenderedNodes[index].rect.center, RenderedNodes[indexChild].rect.center, new Vector2(RenderedNodes[index].rect.xMax + 50f, RenderedNodes[index].rect.center.y), new Vector2(RenderedNodes[indexChild].rect.xMin - 50f, RenderedNodes[indexChild].rect.center.y), Color.cyan, null, 5f);
                        Handles.EndGUI();
                    }
                }
            }

            GUIStyle f = new GUIStyle(EditorStyles.foldout);

            f.richText = true;

            //Render each node window object.
            BeginWindows();
            for (int i = 0; i < RenderedNodes.Count; i++)
            {
                RenderedNodes[i].rect = GUI.Window(i, RenderedNodes[i].rect, WindowEvents, RenderedNodes[i].TestName);
            }
            EndWindows();

            string nodeDetails = inspectedNodeWindow >= 0 ? GetNodeDetails(RenderedNodes[inspectedNodeWindow]) : GetNodeDetails(new DependencyNode());
            float  boxHeight   = TestMonitorHelpers.DetermineRectHeightBasedOnLinesInNodeDetails(nodeDetails) + 50;
            float  boxWidth    = longestTestNameInInfoBox > infoBoxMinWidth ? longestTestNameInInfoBox : infoBoxMinWidth;

            bool overflowX = boxWidth > infoBoxMinWidth;

            //Account for size of scroll bar in scrollable space
            if (overflowX)
            {
                boxHeight += 40;
            }
            float scrollViewHeight = boxHeight < position.height ? boxHeight : position.height;
            bool  overflowY        = scrollViewHeight == position.height;

            if (overflowY)
            {
                boxWidth += 40;
            }

            GUI.EndScrollView();

            GUIStyle verticalScrollBar   = new GUIStyle(GUI.skin.verticalScrollbar);
            GUIStyle horizontalScrollBar = overflowX ? new GUIStyle(GUI.skin.horizontalScrollbar) : GUIStyle.none;

            infoBoxScroll = GUI.BeginScrollView(new Rect(position.width - infoBoxMinWidth, 0, infoBoxMinWidth, scrollViewHeight), infoBoxScroll, new Rect(new Vector2(position.width - (infoBoxMinWidth - 5), 4), new Vector2(boxWidth, boxHeight)), horizontalScrollBar, verticalScrollBar);

            //Display selected node's details in details panel.
            GUIStyle infoBox = new GUIStyle(GUI.skin.box);

            infoBox.richText          = true;
            infoBox.normal.background = MakeTextureFromColor(new Color(0.175f, 0.175f, 0.175f, 1f));
            infoBox.alignment         = TextAnchor.UpperLeft;
            GUI.Box(new Rect(new Vector2(position.width - (infoBoxMinWidth - 5), 4), new Vector2(boxWidth, boxHeight)), nodeDetails, infoBox);

            lastRenderX = position.width + infoBoxMinWidth;
            lastRenderY = position.height;

            GUI.EndScrollView();
        }
예제 #2
0
        //DependencyWebs consists of a Key (the id of the web list) and a Value (a list of KeyValuePairs which consist of a DependencyWeb method and the method that this declares as a dependency.
        void MapDependencies()
        {
            //Get all automation test methods.
            List <KeyValuePair <string, MethodInfo> > allTestMethods = new List <KeyValuePair <string, MethodInfo> >();
            List <Type> AutomationClasses = AutomationMaster.GetAutomationClasses().FindAll(x => lastPassDetectedNoWebTestsSoDisplayDebugAsExample || !x.GetCustomAttributes(false).OfType <DebugClass>().Any());           //Ignore debug classes.

            for (int i = 0; i < AutomationClasses.Count(); i++)
            {
                List <MethodInfo> methods = AutomationClasses[i].GetMethods().Where(y => y.GetCustomAttributes(false).OfType <Automation>().Any()).ToList();
                for (int x = 0; x < methods.Count(); x++)
                {
                    allTestMethods.Add(new KeyValuePair <string, MethodInfo>(methods[x].Name, methods[x]));
                }
            }

            //From all methods, get methods that declare dependencies.
            List <KeyValuePair <string, MethodInfo> > allDependencyTests = allTestMethods.Where(x => {
                return(x.Value.GetCustomAttributes(typeof(DependencyWeb), false).Any());
            }).ToList();

            testsAndTheirDependenciesList = new List <KeyValuePair <string, string[]> >();

            if (allDependencyTests.Count == 0)
            {
                lastPassDetectedNoWebTestsSoDisplayDebugAsExample = true;                 //Show DependencyTests marked as Debug, as a demo for what this window shows when a user has their own DependencyTests.
                return;
            }

            //Get list of every test name associated with its declared dependencies.
            for (int i = 0; i < allDependencyTests.Count; i++)
            {
                DependencyWeb dw      = (DependencyWeb)Attribute.GetCustomAttribute(allDependencyTests[i].Value, typeof(DependencyWeb));
                List <string> dtNames = dw.Dependencies;
                dtNames.AddRange(dw.OneOfDependencies);
                testsAndTheirDependenciesList.Add(new KeyValuePair <string, string[]>(allDependencyTests[i].Key, dtNames.ToArray()));
            }

            //List of all methods.
            List <string> allInvolvedTestMethods = new List <string>();

            //Build dependency web connections.
            for (int t = 0; t < testsAndTheirDependenciesList.Count; t++)
            {
                allInvolvedTestMethods.Add(testsAndTheirDependenciesList[t].Key);
                allInvolvedTestMethods.AddRange(testsAndTheirDependenciesList[t].Value);
            }
            allInvolvedTestMethods = allInvolvedTestMethods.Distinct().ToList();

            for (int all = 0; all < allInvolvedTestMethods.Count; all++)
            {
                string         method = allInvolvedTestMethods[all];
                DependencyNode node   = new DependencyNode();
                node.TestName = method;

                List <KeyValuePair <string, string[]> > matchChild = testsAndTheirDependenciesList.Where(x => x.Key == method).ToList();
                if (matchChild.Any())
                {
                    List <string> children = matchChild.Single().Value.ToList();
                    for (int c = 0; c < children.Count; c++)
                    {
                        node.AddDependency(DependencyNodeConnectionType.Outgoing, children[c]);
                    }
                }

                List <string> parents = testsAndTheirDependenciesList.Where(x => x.Value.Contains(method)).Select(x => x.Key).ToList();
                if (parents.Any())
                {
                    for (int p = 0; p < parents.Count; p++)
                    {
                        node.AddDependency(DependencyNodeConnectionType.Incoming, parents[p]);
                    }
                }

                DependencyWebs.Add(node);
            }
        }