Exemplo n.º 1
0
        public static void GroupClashes(ClashTest selectedClashTest, GroupingMode groupingMode, GroupingMode subgroupingMode, bool keepExistingGroups)
        {
            //Get existing clash result
            List <ClashResult>      clashResults      = GetIndividualClashResults(selectedClashTest, keepExistingGroups).ToList();
            List <ClashResultGroup> clashResultGroups = new List <ClashResultGroup>();

            //Create groups according to the first grouping mode
            CreateGroup(ref clashResultGroups, groupingMode, clashResults, "");

            //Optionnaly, create subgroups
            if (subgroupingMode != GroupingMode.None)
            {
                CreateSubGroups(ref clashResultGroups, subgroupingMode);
            }

            //Remove groups with only one clash
            List <ClashResult> ungroupedClashResults = RemoveOneClashGroup(ref clashResultGroups);

            //Backup the existing group, if necessary
            if (keepExistingGroups)
            {
                clashResultGroups.AddRange(BackupExistingClashGroups(selectedClashTest));
            }

            //Process these groups and clashes into the clash test
            ProcessClashGroup(clashResultGroups, ungroupedClashResults, selectedClashTest);
        }
Exemplo n.º 2
0
        private static List <ClashResultGroup> GroupByElementOfAGivenSelection(List <ClashResult> results, GroupingMode mode, string initialName)
        {
            Dictionary <ModelItem, ClashResultGroup> groups = new Dictionary <ModelItem, ClashResultGroup>();
            ClashResultGroup        currentGroup;
            List <ClashResultGroup> emptyClashResultGroups = new List <ClashResultGroup>();

            foreach (ClashResult result in results)
            {
                //Cannot add original result to new clash test, so I create a copy
                ClashResult copiedResult = (ClashResult)result.CreateCopy();
                ModelItem   modelItem    = null;

                if (mode == GroupingMode.SelectionA)
                {
                    if (copiedResult.CompositeItem1 != null)
                    {
                        modelItem = GetSignificantAncestorOrSelf(copiedResult.CompositeItem1);
                    }
                    else if (copiedResult.CompositeItem2 != null)
                    {
                        modelItem = GetSignificantAncestorOrSelf(copiedResult.CompositeItem2);
                    }
                }
                else if (mode == GroupingMode.SelectionB)
                {
                    if (copiedResult.CompositeItem2 != null)
                    {
                        modelItem = GetSignificantAncestorOrSelf(copiedResult.CompositeItem2);
                    }
                    else if (copiedResult.CompositeItem1 != null)
                    {
                        modelItem = GetSignificantAncestorOrSelf(copiedResult.CompositeItem1);
                    }
                }

                string displayName = "Empty clash";
                if (modelItem != null)
                {
                    displayName = modelItem.DisplayName;
                    //Create a group
                    if (!groups.TryGetValue(modelItem, out currentGroup))
                    {
                        currentGroup = new ClashResultGroup();
                        if (string.IsNullOrEmpty(displayName))
                        {
                            displayName = modelItem.Parent.DisplayName;
                        }
                        if (string.IsNullOrEmpty(displayName))
                        {
                            displayName = "Unnamed Parent";
                        }
                        currentGroup.DisplayName = initialName + displayName;
                        groups.Add(modelItem, currentGroup);
                    }

                    //Add to the group
                    currentGroup.Children.Add(copiedResult);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("test");
                    ClashResultGroup oneClashResultGroup = new ClashResultGroup();
                    oneClashResultGroup.DisplayName = "Empty clash";
                    oneClashResultGroup.Children.Add(copiedResult);
                    emptyClashResultGroups.Add(oneClashResultGroup);
                }
            }

            List <ClashResultGroup> allGroups = groups.Values.ToList();

            allGroups.AddRange(emptyClashResultGroups);
            return(allGroups);
        }
Exemplo n.º 3
0
        public void Test_CreateNodeFromExecutionPort_FromOutput(TestingMode testingMode, GroupingMode groupingMode)
        {
            var inGroupTest = groupingMode == GroupingMode.Grouped;
            var stack       = GraphModel.CreateStack("Stack", Vector2.zero);
            var output0     = stack.OutputPorts[0];
            var group       = inGroupTest ? GraphModel.CreateGroupNode(string.Empty, Vector2.zero) : null;

            TestPrereqActionPostreq(testingMode,
                                    () =>
            {
                Assert.That(GetStackCount(), Is.EqualTo(1));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));
                return(new CreateNodeFromExecutionPortAction(output0, Vector2.down, groupModel: group));
            },
                                    () =>
            {
                Assert.That(GetStackCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));

                var newStack = GetStack(1);
                Assert.That(newStack, Is.TypeOf <StackModel>());
                Assert.That(newStack.IsGrouped, Is.EqualTo(inGroupTest));
                Assert.That(newStack.GroupNodeModel, Is.EqualTo(group));
                Assert.That(stack.OutputPorts[0].ConnectionPortModels.First(),
                            Is.EqualTo(newStack.InputPorts[0]));
            });
        }
Exemplo n.º 4
0
        public void Test_CreateNodeFromLoopPort_CreateLoopStack(TestingMode testingMode, GroupingMode groupingMode)
        {
            bool inGroupTest = groupingMode == GroupingMode.Grouped;
            var  stack       = GraphModel.CreateStack(string.Empty, Vector2.zero);
            var  loopNode    = stack.CreateStackedNode <WhileNodeModel>("loop");
            var  stackCount  = GetStackCount();
            var  group       = inGroupTest ? GraphModel.CreateGroupNode(string.Empty, Vector2.zero) : null;

            TestPrereqActionPostreq(testingMode,
                                    () =>
            {
                Assert.That(GetStackCount(), Is.EqualTo(stackCount));
                var portModel = loopNode.OutputPort;
                Assert.That(portModel.Connected, Is.False);
                return(new CreateNodeFromLoopPortAction(loopNode.OutputPort, Vector2.zero, groupModel: group));
            },
                                    () =>
            {
                Assert.That(GetStackCount(), Is.EqualTo(stackCount + 1));
                var portModel = loopNode.OutputPort;
                Assert.That(portModel.Connected, Is.True);
                var connectedStack = portModel.ConnectionPortModels.Single().NodeModel;
                Assert.That(connectedStack, Is.TypeOf <WhileHeaderModel>());
                Assert.That(connectedStack.IsGrouped, Is.EqualTo(inGroupTest));
                Assert.That(connectedStack.GroupNodeModel, Is.EqualTo(group));
            });
        }
Exemplo n.º 5
0
        public void Test_CreateEdgeAction_Itemize(TestingMode testingMode, GroupingMode groupingMode, ItemizeOptions options, ItemizeTestType itemizeTest, Func <VSGraphModel, IHasMainOutputPort> makeNode)
        {
            // save initial itemize options
            VSPreferences  pref           = ((TestState)m_Store.GetState()).Preferences;
            ItemizeOptions initialOptions = pref.CurrentItemizeOptions;
            bool           inGroupTest    = groupingMode == GroupingMode.Grouped;

            try
            {
                // create int node
                IHasMainOutputPort node0   = makeNode(GraphModel);
                IPortModel         output0 = node0.OutputPort;

                // create Addition node
                BinaryOperatorNodeModel opNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

                GroupNodeModel group = null;
                if (inGroupTest)
                {
                    // Create GroupNode
                    group = GraphModel.CreateGroupNode("", Vector2.zero);
                    group.AddNode(opNode);
                }

                // enable Itemize depending on the test case
                var itemizeOptions = ItemizeOptions.Nothing;
                pref.CurrentItemizeOptions = (itemizeTest == ItemizeTestType.Enabled) ? options : itemizeOptions;

                // connect int to first input
                m_Store.Dispatch(new CreateEdgeAction(opNode.InputPortA, output0));
                m_Store.Update();

                // test how the node reacts to getting connected a second time
                TestPrereqActionPostreq(testingMode,
                                        () =>
                {
                    var binOp            = GraphModel.GetAllNodes().OfType <BinaryOperatorNodeModel>().First();
                    IPortModel input0    = binOp.InputPortA;
                    IPortModel input1    = binOp.InputPortB;
                    IPortModel binOutput = binOp.OutputPort;
                    Assert.That(GetNodeCount(), Is.EqualTo(inGroupTest ? 3 : 2));
                    Assert.That(GetEdgeCount(), Is.EqualTo(1));
                    Assert.That(input0, Is.ConnectedTo(output0));
                    Assert.That(input1, Is.Not.ConnectedTo(output0));
                    Assert.That(binOutput.Connected, Is.False);
                    Assert.False(node0.IsGrouped);
                    Assert.That(node0.GroupNodeModel, Is.EqualTo(null));
                    return(new CreateEdgeAction(input1, output0));
                },
                                        () =>
                {
                    var binOp            = GraphModel.GetAllNodes().OfType <BinaryOperatorNodeModel>().First();
                    IPortModel input0    = binOp.InputPortA;
                    IPortModel input1    = binOp.InputPortB;
                    IPortModel binOutput = binOp.OutputPort;
                    Assert.That(GetEdgeCount(), Is.EqualTo(2));
                    Assert.That(input0, Is.ConnectedTo(output0));
                    Assert.That(binOutput.Connected, Is.False);
                    Assert.False(node0.IsGrouped);
                    Assert.That(node0.GroupNodeModel, Is.EqualTo(null));

                    if (itemizeTest == ItemizeTestType.Enabled)
                    {
                        Assert.That(GetNodeCount(), Is.EqualTo(inGroupTest ? 4 : 3));
                        IHasMainOutputPort newNode = GetNode(inGroupTest ? 3 : 2) as IHasMainOutputPort;
                        Assert.That(newNode, Is.Not.Null);
                        Assert.That(newNode, Is.TypeOf(node0.GetType()));
                        // ReSharper disable once PossibleNullReferenceException
                        Assert.That(newNode.IsGrouped, Is.EqualTo(inGroupTest));
                        Assert.That(newNode.GroupNodeModel, Is.EqualTo(group));
                        IPortModel output1 = newNode.OutputPort;
                        Assert.That(input1, Is.ConnectedTo(output1));
                    }
                    else
                    {
                        Assert.That(GetNodeCount(), Is.EqualTo(inGroupTest ? 3: 2));
                    }
                });
            }
            finally
            {
                // restore itemize options
                pref.CurrentItemizeOptions = initialOptions;
            }
        }
Exemplo n.º 6
0
        public void Test_CreateNodeFromOutputPort_NoConnection(TestingMode testingMode, GroupingMode groupingMode)
        {
            var db = new GraphElementSearcherDatabase(Stencil).AddMethods(typeof(Vector2),
                                                                          BindingFlags.Static | BindingFlags.Public).Build();
            var item = (GraphNodeModelSearcherItem)db.Search("distance", out _).First();

            var inGroupTest = groupingMode == GroupingMode.Grouped;
            var node0       = GraphModel.CreateNode <Type1FakeNodeModel>("Node0", Vector2.zero);
            var output0     = node0.Output;
            var group       = inGroupTest ? GraphModel.CreateGroupNode(string.Empty, Vector2.zero) : null;

            TestPrereqActionPostreq(testingMode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(inGroupTest ? 2 : 1));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));
                return(new CreateNodeFromOutputPortAction(output0, Vector2.down, item, null, group));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(inGroupTest ? 3 : 2));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));

                var newNode = GetNode(inGroupTest ? 2 : 1);
                Assert.That(newNode, Is.TypeOf <FunctionCallNodeModel>());
                Assert.That(newNode.IsGrouped, Is.EqualTo(inGroupTest));
                Assert.That(newNode.GroupNodeModel, Is.EqualTo(group));

                var portModel = node0.OutputsByDisplayOrder.First();
                Assert.That(portModel.ConnectionPortModels.Count(), Is.EqualTo(0));
            });
        }
Exemplo n.º 7
0
        private static void CreateSubGroups(ref List <ClashResultGroup> clashResultGroups, GroupingMode mode)
        {
            List <ClashResultGroup> clashResultSubGroups = new List <ClashResultGroup>();

            foreach (ClashResultGroup group in clashResultGroups)
            {
                List <ClashResult> clashResults = new List <ClashResult>();

                foreach (SavedItem item in group.Children)
                {
                    ClashResult clashResult = item as ClashResult;
                    if (clashResult != null)
                    {
                        clashResults.Add(clashResult);
                    }
                }

                List <ClashResultGroup> clashResultTempSubGroups = new List <ClashResultGroup>();
                CreateGroup(ref clashResultTempSubGroups, mode, clashResults, group.DisplayName + "_");
                clashResultSubGroups.AddRange(clashResultTempSubGroups);
            }

            clashResultGroups = clashResultSubGroups;
        }
Exemplo n.º 8
0
 static object[] MakeItemizeTestCase(TestingMode testingMode, GroupingMode groupingMode, ItemizeOptions options, ItemizeTestType itemizeTest, Func <VSGraphModel, IHasMainOutputPort> makeNode)
 {
     return(new object[] { testingMode, groupingMode, options, itemizeTest, makeNode });
 }
Exemplo n.º 9
0
        private static void CreateGroup(ref List <ClashResultGroup> clashResultGroups, GroupingMode groupingMode, List <ClashResult> clashResults, string initialName)
        {
            //group all clashes
            switch (groupingMode)
            {
            case GroupingMode.None:
                return;

            case GroupingMode.Level:
                clashResultGroups = GroupByLevel(clashResults, initialName);
                break;

            case GroupingMode.GridIntersection:
                clashResultGroups = GroupByGridIntersection(clashResults, initialName);
                break;

            case GroupingMode.SelectionA:
            case GroupingMode.SelectionB:
                clashResultGroups = GroupByElementOfAGivenSelection(clashResults, groupingMode, initialName);
                break;

            case GroupingMode.ModelA:
            case GroupingMode.ModelB:
                clashResultGroups = GroupByElementOfAGivenModel(clashResults, groupingMode, initialName);
                break;

            case GroupingMode.ApprovedBy:
            case GroupingMode.AssignedTo:
            case GroupingMode.Status:
                clashResultGroups = GroupByProperties(clashResults, groupingMode, initialName);
                break;
            }
        }
Exemplo n.º 10
0
        private static List <ClashResultGroup> GroupByProperties(List <ClashResult> results, GroupingMode mode, string initialName)
        {
            Dictionary <string, ClashResultGroup> groups = new Dictionary <string, ClashResultGroup>();
            ClashResultGroup currentGroup;

            foreach (ClashResult result in results)
            {
                //Cannot add original result to new clash test, so I create a copy
                ClashResult copiedResult  = (ClashResult)result.CreateCopy();
                string      clashProperty = null;

                if (mode == GroupingMode.ApprovedBy)
                {
                    clashProperty = copiedResult.ApprovedBy;
                }
                else if (mode == GroupingMode.AssignedTo)
                {
                    clashProperty = copiedResult.AssignedTo;
                }
                else if (mode == GroupingMode.Status)
                {
                    clashProperty = copiedResult.Status.ToString();
                }

                if (string.IsNullOrEmpty(clashProperty))
                {
                    clashProperty = "Unspecified";
                }

                if (!groups.TryGetValue(clashProperty, out currentGroup))
                {
                    currentGroup             = new ClashResultGroup();
                    currentGroup.DisplayName = initialName + clashProperty;
                    groups.Add(clashProperty, currentGroup);
                }
                currentGroup.Children.Add(copiedResult);
            }

            return(groups.Values.ToList());
        }
Exemplo n.º 11
0
    private void OnGUI()
    {
        // Create the string input field for providing the parent name
        ParentName = EditorGUILayout.TextField("Parent Name", ParentName);

        // If the ParentName is invalid, revert it to the default
        if (string.IsNullOrEmpty(ParentName))
        {
            ParentName = "Root";
        }

        // Create the enum pop-up list for specifying the grouping mode
        GroupAt = (GroupingMode)EditorGUILayout.EnumPopup("Group At", GroupAt);
        // Supply a pair of labels explaining what the choice of grouping mode does
        var description = GroupingModeDescriptions[GroupAt];

        EditorGUILayout.LabelField("Places the parent at the");
        EditorGUILayout.LabelField(description);

        // Only create the Vector3 input fields for the specified position
        // if GroupAt is equal to GroupingMode.SpecifiedPosition
        if (GroupAt == GroupingMode.SpecifiedPosition)
        {
            SpecifiedPosition = EditorGUILayout.Vector3Field("Position", SpecifiedPosition);
        }

        // Create the boolean check box for specifying whether to close the window at the end
        CloseWhenFinished = EditorGUILayout.Toggle("Close When Finished", CloseWhenFinished);

        // Grouping can only happen if there is at least one object selected
        var relevantObjects  = Selection.GetFiltered <GameObject>(SelectionMode.Editable);
        var notEnoughObjects = relevantObjects.Length == 0;

        // Create a flexible space to align the Group button at the bottom of the window
        GUILayout.FlexibleSpace();

        // The Group button will be grayed out if there isn't at least one object selected
        EditorGUI.BeginDisabledGroup(notEnoughObjects);

        // Create the button to do the actual grouping. If it's pressed, run the Group function
        if (GUILayout.Button("Group", GUILayout.Height(ButtonHeight)))
        {
            Group();
        }

        EditorGUI.EndDisabledGroup();

        // If there are enough objects...
        if (!notEnoughObjects)
        {
            // ... Process the keyboard input to check for the Enter key
            var e = Event.current;

            // if the Return or Enter key is pressed, run the Group function
            if (e.type == EventType.KeyDown)
            {
                if (e.keyCode == KeyCode.Return || e.keyCode == KeyCode.KeypadEnter)
                {
                    Group();
                }
            }
        }
    }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            try
            {
                bool             show_help  = false;
                HashSet <string> typeFilter = new HashSet <string>();
                HashSet <int>    pidFilter  = new HashSet <int>();
                HashSet <string> nameFilter = new HashSet <string>();
                bool             noquery    = false;
                GroupingMode     mode       = GroupingMode.Pid;
                ShareMode        shareMode  = ShareMode.None;
                bool             showsd     = false;

                OptionSet opts = new OptionSet()
                {
                    { "t|type=", "An object type to filter on, can be repeated", v => typeFilter.Add(v.Trim().ToLower()) },
                    { "p|pid=", "A PID to filter on, can be repeated", v => pidFilter.Add(int.Parse(v.Trim())) },
                    { "n|name=", "Specify a process by name", v => nameFilter.Add(v.ToLower()) },
                    { "q|noquery", "Don't query for names/typenames", v => noquery = v != null },
                    { "g|group=", "Specify a grouping, defaults to pid, can be object,name,type", v => mode = (GroupingMode)Enum.Parse(typeof(GroupingMode), v, true) },
                    { "s|share=", "When grouping, filter on shared, can be none,partial or all", v => shareMode = (ShareMode)Enum.Parse(typeof(ShareMode), v, true) },
                    { "sd", "Display the security descriptor associated with the kernel object", v => showsd = v != null },
                    { "h|help", "show this message and exit",
                      v => show_help = v != null },
                };

                opts.Parse(args);

                if (show_help)
                {
                    ShowHelp(opts);
                }
                else
                {
                    IEnumerable <NtProcess> filtered = NtProcess.GetProcesses(ProcessAccessRights.MaximumAllowed);

                    if (pidFilter.Count > 0)
                    {
                        filtered = filtered.Where(ps => pidFilter.Contains(ps.ProcessId));
                    }

                    if (nameFilter.Count > 0)
                    {
                        filtered = filtered.Where(ps => nameFilter.Contains(ps.FullPath, StringComparer.OrdinalIgnoreCase));
                    }

                    HashSet <int>            pids      = new HashSet <int>(filtered.Select(process => process.ProcessId));
                    Dictionary <int, string> pidToName = filtered.ToDictionary(pk => pk.ProcessId, pv => pv.FullPath);

                    List <NtHandle> totalHandles = new List <NtHandle>();

                    foreach (int pid in pids)
                    {
                        if (pid == Process.GetCurrentProcess().Id)
                        {
                            continue;
                        }

                        IEnumerable <NtHandle> handles = NtSystemInfo.GetHandles(pid, true).Where(ent => (typeFilter.Count == 0) || typeFilter.Contains(ent.ObjectType.ToLower()));
                        totalHandles.AddRange(handles);
                        if (mode == GroupingMode.Pid)
                        {
                            Console.WriteLine("Process ID: {0} - Name: {1}", pid, pidToName[pid]);
                            foreach (NtHandle ent in handles)
                            {
                                Console.WriteLine("{0:X04}: {1:X016} {2:X08} {3,20} {4}", ent.Handle, ent.Object, ent.GrantedAccess, ent.ObjectType, ent.Name);
                                if (showsd && ent.SecurityDescriptor != null)
                                {
                                    Console.WriteLine("SDDL: {0}", ent.SecurityDescriptor.ToSddl());
                                }
                            }
                            Console.WriteLine();
                        }
                    }

                    switch (mode)
                    {
                    case GroupingMode.Type:
                        PrintGrouping(totalHandles.GroupBy(f => f.ObjectType), pidToName, k => String.Format("Type: {0}", k),
                                      e => String.Format("{0:X08} {1:X08} {2}", e.Object, e.GrantedAccess, e.Name),
                                      shareMode, pids.Count, showsd);
                        break;

                    case GroupingMode.Object:
                        PrintGrouping(totalHandles.GroupBy(f => f.Object), pidToName, k => String.Format("Object: {0:X08}", k),
                                      e => String.Format("{0,20} {1:X08} {2}", e.ObjectType, e.GrantedAccess, e.Name),
                                      shareMode, pids.Count, showsd);
                        break;

                    case GroupingMode.Name:
                        PrintGrouping(totalHandles.GroupBy(f => f.ObjectType), pidToName, k => String.Format("Name: {0:X08}", k),
                                      e => String.Format("{0:X08} {1,20} {2:X08} {2}", e.Object, e.Name, e.GrantedAccess),
                                      shareMode, pids.Count, showsd);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
 public GroupingByFeature()
 {
     GroupingMode = GroupingMode.Feature;
 }