Monday, April 22, 2013

Visual Studio 2012 Code Map - GraphCmd Tool

In this post we are going to discuss GraphCmd. It is a Visual Studio tool used to generate graphs for batch processing. It has been part of Visual Studio since 2010 Ultimate edition. It is not specific to code map but generic graphs generated in the form of DGML files. The tool is generally used to generate DGML files based on other DGML files by applying filtering on the source graph.

The graph is generated by the tool using the parameters specific to the tool. The list of parameters can be found using -? parameter with the application. Here we are using the application using Developer Command Prompt for VS2012 installed with Visual Studio 2012.2 Ultimate.

Directed Graph Query Language [ DGQL ]
Directed Graph Query Language is a query language in Visual Studio to query elements in a graph. it's actions are non-commutative and non-associative decorators [See Decorator pattern]. I have never been able to find any good documentation of the language. There are only a few examples mentioned here [ ] but this has also been discussed as a side note without putting special focus on the topic. It was easier to save DGQL queries in Visual Studio 2010 Ultimate as it allowed saving it from Architecture explorer. This feature also has been removed from Visual Studio 2012 Ultimate. The purpose of this post is not to learn DGQL but to discuss about GraphCmd so we would keep our focus on the tool.

Generating Filtered Graph
The selection of nodes for GraphCmd can be specified using -exec or -query switches. The former supports the specification of the query in a file while later supports the specification directly in a DGQL statement.

The above command would generate a new DGML file. It would have nodes fitting the DGQL statement passed as -exec or -query parameters. For our sample project, it is generated as follows:

Exception while Graph Generation
There might be exceptions in generating the output graph based on the input parameters. There might be exceptions due to incorrect DGQL statement. Below is a command where we have a bad DGQL action statement. This would result in an exception. You would still see one node saved in the graph. This is because we have -exceptions parameter in the GraphCmd command.

The graph is still generated but an exception node is generated in the graph.

Missing the -exceptions statement wouldn't generate nodes. The exception is shown on the prompt if we are running the command ourselves.

The generated graph would be missing statements. For our case, the updated MyGraph.dgml is updated.

GraphCmd is a great tool in supporting what it promises to support. There are a lots of limitations what you would expect this tool to support that it doesn't provide. Some of the limitations are as follows:
  • The tool just supports selecting and filtering an already existing DGML file into a new DGML file. There is no support for providing solution file as an input or elements from a code. This would be a great enhancement.

  • GraphCmd is a Visual Studio tool so we need a visual studio license to run it. This can be part of Windows SDK to support installation on a build machine.

  • The tool doesn't support creating a DGML output based on some source solution file. It would have been great if we could create it as part of a solution file. This can make our life a lot easier to write unit tests to enforce coding policies by writing some unit tests around the geneated DGML output for a solution file.

No comments: