• Blog
  • Info Support
  • Career
  • Training
  • International Group
  • Info Support
  • Blog
  • Career
  • Training
  • International Group
  • Search
logo InfoSupport
  • Latest blogs
  • Popular blogs
  • Experts
      • All
      • Bloggers
      • Speakers
  • Meet us
  • About us
    • nl
    • en
    • .NET
    • 3D printing
    • Advanced Analytics
    • Agile
    • Akka
    • Alexa
    • Algorithms
    • Api's
    • Architectuur
    • Artificial Intelligence
    • ATDD
    • Augmented Reality
    • AWS
    • Azure
    • Big Data
    • Blockchain
    • Business Intelligence
    • Chatbots
    • Cloud
    • Code Combat
    • Cognitive Services
    • Communicatie
    • Containers
    • Continuous Delivery
    • CQRS
    • Cyber Security
    • Dapr
    • Data
    • Data & Analystics
    • Data Science
    • Data Warehousing
    • Databricks
    • DataOps
    • Developers life
    • DevOps
    • Digital Days
    • Digital Twin
    • Docker
    • eHealth
    • Enterprise Architecture
    • Event Sourcing
    • Hacking
    • Infrastructure & Hosting
    • Innovatie
    • Integration
    • Internet of Things
    • Java
    • Machine Learning
    • Microservices
    • Microsoft
    • Microsoft Bot Framework
    • Microsoft Data Platform
    • Mobile Development
    • Mutation Testing
    • Open source
    • Pepper
    • Power BI
    • Privacy & Ethiek
    • Python
    • Quality Assistance & Test
    • Quality Assurance & Test
    • Requirements Management
    • Scala
    • Scratch
    • Security
    • SharePoint
    • Software Architecture
    • Software development
    • Software Factory
    • SQL Server
    • SSL
    • Start-up
    • Startup thinking
    • Stryker
    • Test Quality
    • Testing
    • TLS
    • TypeScript
    • Various
    • Web Development
    • Web-scale IT
    • Xamarin
    • All
    • Bloggers
    • Speakers
Home » Creating Custom DGML Diagrams using the Progression API
  • Creating Custom DGML Diagrams using the Progression API

    • By Marcel de Vries
    • .NET 14 years ago
    • .NET 0 comments
    • .NET .NET
    Creating Custom DGML Diagrams using the Progression API

    *Moved to: http://fluentbytes.com/creating-custom-dgml-diagrams-using-the-progression-api/

    Thursday night I presented a Session for the VSUG in Belgium, with the title “Modeling that works with code”. In this session I demonstrated how we can add more value into models and diagrams and how that can help us to keep our model in sync with the actual codebase we work on. (You can download the presentation here)

    During this session I also addressed the concept of creating your own custom DGML diagram, using the progression API, that can be found in the visual studio directories.

    In this post I want to describe how you can create a Custom DGML diagram. I will show you how you can use the standard Coverage files you get from the Microsoft Test tools and use that data to create a diagram that shows which classes have a coverage percentage below a defined quality bar.

    When you want to create a DGML diagram, you can do that by using the Progression API. You can find the classes you need in the following assemblies :

    • Microsoft.VisualStudio.Progression.Common
    • Microsoft.VisualStudio.Progression.GraphModel

    Just use the add reference dialog and browse to the following location:
    <installdrive>:Program Filesvisual Studio 10Common7IdePrivateAssemblies

    note:on a 64 bit machine this is program Files (x86) instead of program files

    I want to create a new diagram, so to start, I need an instance of a Graph object. This is nothing more than just creating an instance of the Graph class. Now I want to define some custom metadata to my Nodes, that contain the code coverage information. For that purpose, I register a custom metadata property of the type double with the name “CodeCoverage” and I register it to be available on the Nodes in my diagram.

    So the only thing I need to do is load the Code Coverage XML file, use an XLinq query to get only the Class nodes and then create a loop that generates the nodes I want to add to the diagram.

    The code for this is like follows:

    Graph DgmlGraph = Graph.Load(filetoAnnotate);
    GraphProperty codeCoverageProperty =
    GraphProperty.Register("CodeCoverage", typeof(double),
    GraphMetadata.Default, typeof(Node));
    var codeCoverageXmlFile = XElement.Load(coverageFileName);
    foreach (var classCoverageNode in codeCoverageXmlFile.Descendants("Class"))
    {
        var classname = classCoverageNode.Element("ClassName").Value;
        int linesCovered = int.Parse(classCoverageNode.Element("LinesCovered").Value);
        int linesNotCovered = int.Parse(classCoverageNode.Element("LinesNotCovered").Value);
        int linesPartiallyCovered =
            int.Parse(classCoverageNode.Element("LinesPartiallyCovered").Value);
        int totalLines = linesCovered + linesNotCovered + linesPartiallyCovered;
        double coveragePercentage = (linesCovered * 100 / totalLines);
        Node coverageNode = new Node(className);
        coverageNode.SetValue<double>(codeCoverageProperty, coveragePercentage);
        DgmlGraph.Nodes.Add(coverageNode);
    }

    So now I have a Graph, that contains nodes and each node has the percentage code coverage set.

    Finally, I need to define specific styles so the diagram shows which classes are below a certain code coverage percentage and which are above. For that you can add so called Conditional Styles to the diagram. This is also very straightforward to do.

    You just create a new ConditionalStyle object instance and give it the graph as argument. Then you define to what type of element it needs to be applied to in the DGML diagram. So for this purpose we define this style to be applied to the “Node “ type. Next you give it a Label and last but not least a Condition. The expressions that evaluate if it needs to apply the condition can use all information in the model. The expression syntax can be found here (http://msdn.microsoft.com/en-us/library/dd409453(VS.100).aspx#Highlight)

    So for this diagram, I want to apply the style to all nodes with Code Coverage > 80. Therefore I need to apply the following expression: “CodeCoverage > 80”

    var ConditionalStyle = new ConditionalStyle(DgmlGraph);
    ConditionalStyle.TargetType = typeof(Node);
    ConditionalStyle.GroupLabel = "Coverage > 80%";
    var Condition = new Condition(ConditionalStyle);
    Condition.Expression = "CodeCoverage > 80";
    ConditionalStyle.Conditions.Add(Condition);
    DgmlGraph.Styles.Add(ConditionalStyle);

    Now the last thing I need to do is define what property of a node visualization I want to change on this ConditionalStyle. I choose to set an Icon to be a green checkmark and the background to green

    var CodeCoverageSetterBackGround = new Setter(ConditionalStyle, “BackGround”);

    CodeCoverageSetterBackGround.Value = “#FF00FF00”;

    ConditionalStyle.Setters.Add(CodeCoverageSetterBackGround);

    var CodeCoverageSetterIcon = new Setter(ConditionalStyle, “Icon”);

    CodeCoverageSetterIcon.Value = “pack://application:,,,/Microsoft.VisualStudio.Progression.GraphControl;component/Icons/kpi_green_sym2_large.png”;

    ConditionalStyle.Setters.Add(CodeCoverageSetterIcon);

    I also did the same for coverage below 80% and set that style to be Red and use the Icon type “Node.Error”.

    So now when I run my program with a code coverage file, I will get the following results:

    clip_image002

    In a next post, I will show you how you can also leverage the DGML diagrams generated with the architecture explorer and then applying this same code coverage information to that diagram, so you can decide which classed need additional effort in getting better coverage.

    Cheers,

    Marcel

    Follow my new blog on http://fluentbytes.com

    Share this

Marcel de Vries

View profile

Related IT training

Go to training website

Related Consultancy solutions

Go to infosupport.com

Related blogs

  • What's new in C# 12, a developer perspective

    What's new in C# 12, a developer perspective Tom van den Berg - 3 weeks ago

  • Continuous validation - Ensuring Availability and Resil…

    Continuous validation - Ensuring Availability and Resil… Tom van den Berg - 1 month ago

  • Continuous validation - Ensuring Availability and Resil…

    Continuous validation - Ensuring Availability and Resil… Tom van den Berg - 1 month ago

Data Discovery Channel

  • Data+AI Summit 2023

  • Blijf je Azure cloud omgeving de baas met CloudXcellence

  • MLOps

Nieuwsbrief

* verplichte velden

Contact

  • Head office NL
  • Kruisboog 42
  • 3905 TG Veenendaal
  • T +31 318 552020
  • Call
  • Mail
  • Directions
  • Head office BE
  • Generaal De Wittelaan 17
  • bus 30 2800 Mechelen
  • T +32 15 286370
  • Call
  • Mail
  • Directions

Follow us

  • Twitter
  • Facebook
  • Linkedin
  • Youtube

Newsletter

Sign in

Extra

  • Media Library
  • Disclaimer
  • Algemene voorwaarden
  • ISHBS Webmail
  • Extranet
Beheer cookie toestemming
Deze website maakt gebruik van Functionele en Analytische cookies voor website optimalisatie en statistieken.
Functioneel Always active
De technische opslag of toegang is strikt noodzakelijk voor het legitieme doel het gebruik mogelijk te maken van een specifieke dienst waarom de abonnee of gebruiker uitdrukkelijk heeft gevraagd, of met als enig doel de uitvoering van de transmissie van een communicatie over een elektronisch communicatienetwerk.
Voorkeuren
De technische opslag of toegang is noodzakelijk voor het legitieme doel voorkeuren op te slaan die niet door de abonnee of gebruiker zijn aangevraagd.
Statistieken
De technische opslag of toegang die uitsluitend voor statistische doeleinden wordt gebruikt. De technische opslag of toegang die uitsluitend wordt gebruikt voor anonieme statistische doeleinden. Zonder dagvaarding, vrijwillige naleving door uw Internet Service Provider, of aanvullende gegevens van een derde partij, kan informatie die alleen voor dit doel wordt opgeslagen of opgehaald gewoonlijk niet worden gebruikt om je te identificeren.
Marketing
De technische opslag of toegang is nodig om gebruikersprofielen op te stellen voor het verzenden van reclame, of om de gebruiker op een website of over verschillende websites te volgen voor soortgelijke marketingdoeleinden.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Voorkeuren
{title} {title} {title}