Пример #1
0
        public DGMLGraph ToDGMLGraph()
        {
            DGMLGraph dgmlGraph = new DGMLGraph();

            foreach (GraphItem node in GraphItems)
            {
                dgmlGraph.Nodes.Add(new DGMLGraph.Node {
                    Id = node.AbsoluteFilename, Label = node.FormattedName
                });
                foreach (Include include in node.Includes)
                {
                    dgmlGraph.Links.Add(new DGMLGraph.Link {
                        Source = node.AbsoluteFilename, Target = include.IncludedFile?.AbsoluteFilename ?? null
                    });
                }
            }

            return(dgmlGraph);
        }
        static public DGMLGraph ToDGMLGraph(this IncludeGraph graph, bool folderGrouping, bool expandGroups)
        {
            var uniqueTransitiveChildrenMap = FindUniqueChildren(graph.GraphItems);

            DGMLGraph dgmlGraph = new DGMLGraph();

            foreach (GraphItem node in graph.GraphItems)
            {
                dgmlGraph.Nodes.Add(new DGMLGraph.Node
                {
                    Id          = node.AbsoluteFilename,
                    Label       = node.FormattedName,
                    Background  = null,
                    NumIncludes = node.Includes.Count,
                    NumUniqueTransitiveChildren = uniqueTransitiveChildrenMap[node].Count,
                });
                foreach (Include include in node.Includes)
                {
                    dgmlGraph.Links.Add(new DGMLGraph.Link {
                        Source = node.AbsoluteFilename, Target = include.IncludedFile?.AbsoluteFilename ?? null
                    });
                }
            }

            if (folderGrouping)
            {
                // Reusing a ViewModel datastructure is arguably a bit ugly, but it matches exactly what we want.
                // TODO: Consider splitting functionallity out.
                var folderGroupingRoot = new FolderIncludeTreeViewItem_Root(graph.GraphItems, null);
                foreach (var child in folderGroupingRoot.Children)
                {
                    AddFolderGroupingRecursive(dgmlGraph, child, null, expandGroups);
                }
            }


            return(dgmlGraph);
        }
        private static void AddFolderGroupingRecursive(DGMLGraph dgml, IncludeTreeViewItem child, FolderIncludeTreeViewItem_Folder parent, bool expandGroups)
        {
            if (parent != null)
            {
                dgml.Links.Add(new DGMLGraph.Link {
                    Type = DGMLGraph.Link.LinkType.GroupContains, Source = parent.AbsoluteFilename, Target = child.AbsoluteFilename
                });
            }

            if (child is FolderIncludeTreeViewItem_Folder folder)
            {
                dgml.Nodes.Add(new DGMLGraph.Node
                {
                    Id            = folder.AbsoluteFilename,
                    Label         = folder.Name,
                    GroupCollapse = expandGroups ? DGMLGraph.Node.GroupCollapseState.Expanded : DGMLGraph.Node.GroupCollapseState.Collapsed
                });
                foreach (var subChild in folder.Children)
                {
                    AddFolderGroupingRecursive(dgml, subChild, folder, expandGroups);
                }
            }
        }