Exemple #1
0
    /// <summary>
    /// Creates a DGML graph from a collection of types. The graph contains
    /// nodes for interfaces (denoted as ovals) and classes (denoted as boxes), dashed edges for inheritance relations,
    /// normal edges for associations. Abstract classes are denoted as dashed boxes.
    /// </summary>
    /// <param name="types"></param>
    /// <returns></returns>
    public static DirectedGraph Types2Dgml(IEnumerable <Type> types)
    {
        var typesCollection = types.ToArray();
        var builder         = new DgmlBuilder(new HubNodeAnalysis(), new CategoryColorAnalysis())
        {
            NodeBuilders = new[]
            {
                new NodeBuilder <Type>(Class2Node, x => x.IsClass),
                new NodeBuilder <Type>(Interface2Node, x => x.IsInterface),
                new NodeBuilder <Type>(Enum2Node, x => x.IsEnum)
            },
            LinkBuilders = new[]
            {
                new LinksBuilder <Type>(x => Property2Links(x, typesCollection)),
                new LinksBuilder <Type>(x => Method2Links(x, typesCollection)),
                new LinksBuilder <Type>(x => Field2Links(x, typesCollection), x => x.IsEnum == false),
                new LinksBuilder <Type>(x => TypeInheritance2Links(x, typesCollection)),
                new LinksBuilder <Type>(x => GenericType2Links(x, typesCollection)),
                new LinksBuilder <Type>(x => ConstructorInjection2Links(x, typesCollection)),
            },
            CategoryBuilders = new[] { new CategoryBuilder <Type>(Type2Category) },
            StyleBuilders    = new StyleBuilder[]
            {
                new StyleBuilder <Node>(InterfaceStyle, x => x.HasCategory(InterfaceType)),
                new StyleBuilder <Node>(EnumStyle, x => x.HasCategory(EnumType)),
                new StyleBuilder <Node>(AbstractStyle, x => x.HasCategory(AbstractClassType)),
                new StyleBuilder <Link>(AssociationStyle, x => x.HasCategory(AssociationRelation)),
                new StyleBuilder <Link>(InheritanceStyle, x => x.HasCategory(InheritanceRelation))
            }
        };

        return(builder.Build(typesCollection));
    }
        public string GenerateDgmlContent(dynamic context)
        {
            Type type        = context.GetType();
            var  dgmlBuilder = new DgmlBuilder();

            var debugView = CreateDebugView(context);
            var dgml      = dgmlBuilder.Build(debugView, type.Name);

            return(dgml);
        }
        public static string AsDgml(this DbContext context)
        {
            Type type        = context.GetType();
            var  dgmlBuilder = new DgmlBuilder();

            var debugView = CreateDebugView(context);
            var dgml      = dgmlBuilder.Build(debugView, type.Name);

            return(dgml);
        }
Exemple #4
0
        public void BuildSample1()
        {
            // Act
            var result = DgmlBuilder.Build(ReadAllText("Aw2014Person.txt"), "test", template);

            // Assert
            Assert.AreNotEqual(null, result);

            File.WriteAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Aw2014Person.dgml"), result, Encoding.UTF8);
        }
Exemple #5
0
        public void BuildLongView50()
        {
            // Act
            var result = DgmlBuilder.Build(ReadAllText("longview50.txt"), "test", template);

            // Assert
            Assert.AreNotEqual(null, result);

            File.WriteAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, @"LongView50.dgml"), result, Encoding.UTF8);
        }
Exemple #6
0
        public void BuildPfizer()
        {
            // Act
            var builder = new DgmlBuilder();
            var result  = builder.Build(File.ReadAllText("Pfizer.txt"), "test");

            // Assert
            Assert.AreNotEqual(result, null);

            File.WriteAllText(@"C:\temp\pfizer.dgml", result, Encoding.UTF8);
        }
        /// <summary>
        /// Extension method that converts a Structurizr C4 model to DGML.
        /// </summary>
        /// <param name="workspace"></param>
        /// <returns></returns>
        public static DirectedGraph ToDgml(this Workspace workspace)
        {
            var builder = new DgmlBuilder
            {
                NodeBuilders = new NodeBuilder[]
                {
                    new NodeBuilder <ElementView>(CreateNode)
                },
                LinkBuilders = new LinkBuilder[]
                {
                    new LinkBuilder <RelationshipView>(CreateLink)
                },
                CategoryBuilders = new CategoryBuilder[]
                {
                    new CategoryBuilder <ElementView>(CreateCategory)
                },
                StyleBuilders = new List <StyleBuilder>
                {
                    new StyleBuilder <Node>(x => CreateStyleForNode(workspace, x)),
                }
            };
            var contextElements   = workspace.Views.SystemContextViews.SelectMany(x => x.Elements).Distinct().ToArray();
            var contextLinks      = workspace.Views.SystemContextViews.SelectMany(x => x.Relationships).Distinct().ToArray();
            var containerElements = workspace.Views.ContainerViews.SelectMany(x => x.Elements).Distinct().ToArray();
            var containerLinks    = workspace.Views.ContainerViews.SelectMany(x => x.Relationships).Distinct().ToArray();
            var componentElements = workspace.Views.ComponentViews.SelectMany(x => x.Elements).Distinct().ToArray();
            var componentLinks    = workspace.Views.ComponentViews.SelectMany(x => x.Relationships).Distinct().ToArray();

            var graph = builder.Build(
                contextElements,
                contextLinks,
                containerElements,
                containerLinks,
                componentElements,
                componentLinks);

            return(graph);
        }
Exemple #8
0
        public static void GenerateDgml(Solution solution)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            var projects = solution.Projects.Select(p => new ProjectGraphInfo(p)).ToArray();

            try
            {
                var builder = new DgmlBuilder
                {
                    NodeBuilders = new[]
                    {
                        new NodeBuilder <ProjectGraphInfo>(p => Project2Node(p)),
                        new NodesBuilder <ProjectGraphInfo>(p => ProjectFolder2Node(p))
                    },
                    LinkBuilders = new[]
                    {
                        new LinksBuilder <ProjectGraphInfo>(p => Project2Link(p))
                    },
                    StyleBuilders = new[]
                    {
                        new StyleBuilder <Node>(VcProjectStyle, x => x.HasCategory(VcProjectType)),
                        new StyleBuilder <Node>(VsProjectStyle, x => x.HasCategory(VsProjectType)),
                        new StyleBuilder <Node>(FolderStyle, x => x.HasCategory(FolderType)),
                        new StyleBuilder <Node>(UnitTestFolderStyle, x => x.HasCategory(UnitTestFolderType))
                    }
                };

                var graph    = builder.Build(projects);
                var filepath = solution.FilePath + ".dgml";

                graph.WriteToFile(filepath);
                solution.NativeSolution.DTE.ItemOperations.OpenFile(filepath);
            }
            catch (Exception)
            { }
        }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphCreator"/> class.
        /// </summary>
        /// <param name="graph">A dictionary of the parts to include in the rejection graph.</param>
        internal GraphCreator(Dictionary <string, PartNode> graph)
        {
            this.RejectionGraph = graph;

            // Tell the DGML creator how to create nodes, categorize them and create edges between.
            var nodeCreator = new[]
            {
                new NodeBuilder <PartNode>(this.NodeConverter),
            };
            var edgeCreator = new[]
            {
                new LinksBuilder <PartNode>(this.EdgeGenerator),
            };
            var categoryCreator = new[]
            {
                new CategoryBuilder <PartNode>(x => new Category {
                    Id = x.Level.ToString()
                }),
            };

            StyleBuilder[] styleCreator =
            {
                new StyleBuilder <Node>(RejectionExpectedNode),
                new StyleBuilder <Link>(EdgeStyle),
            };
            var builder = new DgmlBuilder
            {
                NodeBuilders     = nodeCreator,
                LinkBuilders     = edgeCreator,
                CategoryBuilders = categoryCreator,
                StyleBuilders    = styleCreator,
            };
            IEnumerable <PartNode> nodes = this.RejectionGraph.Values;

            this.Dgml = builder.Build(nodes);
        }