Sage 300 and Visual Studio’s Code Maps

Introduction

The Sage 300 web screens are comprised of 113+ Visual Studio projects. This represents a large and complex code base. Simply opening a project and viewing the components and references to understand the relationships and dependencies can be a daunting task.

The relationships and dependencies between not only projects but also classes and methods are sometimes best understood when presented visually.

Microsoft’s Code Maps, which is a core feature of Visual Studio 2013 Ultimate and Visual Studio 2015/2017 Enterprise Editions, is a fantastic tool to assist with the visualization of these relationships and dependencies.

ReSharper, which all internal Sage 300 developers use, also offers a graphical code mapping feature. However, the features, functionality and even the debugging integration with Code Maps make Visual Studio tool, in my opinion, the best tool to use.

This post will introduce the Visual Studio Code Maps and present how developers can leverage this tool to graphically display relationships and dependencies for a project or projects, a class or a method. Code Maps can assist not only new developers, who do not know anything about the code base, but also experienced developers wanting to better understand relationships and dependencies.

Code Maps

Code Maps is an architectural tool in Visual Studio that generates a graph, like a dependency graph, to assist the developer with understanding and viewing the relationships and dependencies of a large code base in a visually appealing, dynamic and interactive graphical display.

A code map visualizes code and project relationships and can even be viewed in a tab next to the code editor inside of Visual Studio. This allows the developer to see where they are in the map and therefore in the hierarchy of the code while in the code itself.

A code map may be saved within the solution or even exported as an image to email or an XPS viewer. While inside Visual Studio, the code map is interactive:

  • Add or remove or hide components in map
  • Add or remove filters which control relationships (Class, Methods, Call, References, Calls, Returns, etc.)
  • Add comments to a component or relationship
  • Double-click component to be taken to that place in the code
  • etc.

While all versions of Visual Studio can access (read-only) a Code Map, only the following versions of Visual Studio can create a Code Map:

Visual Studio 2013 Ultimate Edition and Visual Studio 2015/2017 Enterprise Edition

Example

In this example, I want to better understand the A/R Payment Code’s business repository located in the A/R Business Repository project of the A/R solution. I want a visual graph which Visual Studio’s Code Maps feature can generate.

Let’s start by creating a map for the Payment Code Repository. Open the PaymentCodeRepository class and Right-Click on the name in the code window and select the Show on Code Map option:

Blog10Fig1

Figure 1: Generate code map for class

The code map for the class will be generated with a green chevron indicating where in the code the code window is:

Blog10Fig2

Figure 2: Generated code map for class

Hover over the code map and select the dropdown chevron to retrieve the components in this class:

Blog10Fig3

Figure 3: Retrieve components of class

The components (methods, properties, etc.) of the class are retrieved and added to the code map:

Blog10Fig4

Figure 4: Components in class

We can visually see all the methods and properties in the class. I’m interested in the GetAccessRights method, the methods that this routine invokes, and where they are located. Rick-Click on the GetAccessRights component in the code map and select the Show Methods This Calls option:

Blog10Fig5

Figure 5: Show methods

Note that the code map window is side by side with the code window.

Upon showing the methods that are called from this routine, you will notice that they are coming from an external assembly or assemblies:

Blog10Fig6

Figure 6: Method calls are in external assembly(s)

Hover over the External component and select the dropdown chevron to retrieve the components in this class:

Blog10Fig7

Figure 7: Retrieve and show assembly(s)

The external assembly is now shown:

Blog10Fig8

Figure 8: External methods are in the Common BusinessRepository assembly

Hover over the external assembly and select the dropdown chevron to show the methods:

Blog10Fig9

Figure 9: Retrieve and show methods

The methods are in a folder within the assembly (namespace):

Blog10Fig10

Figure 10: External methods are in the BusinessRepositoryBase namespace

Hover over the external assembly and select the dropdown chevron to show the methods:

Blog10Fig11

Figure 11: Retrieve and show methods

We are getting closer! We can see now that the methods are in two different classes:

Blog10Fig12

Figure 12: External methods are in the BaseRepository and FlatRepository classes

Hover over the two classes and select the dropdown chevrons to show the methods which results in our final display:

Blog10Fig13

Figure 13: PaymentCodeRepository showing external reference and methods

We wanted to see where the GetAccessRights and SecurityCheck methods were located and Code Maps provided a visual graph in just a few steps.

Blog10Fig14

Figure 14: GetAccessRights routine in the PaymentCodeRepository

Code Map Toolbar

Blog10Fig15

Figure 15: Code Map Toolbar

The Code Map Toolbar provides numerous options that can be undertaken on the code map:

  • Undo
    • Undo recent changes to the code map
  • Show Related
    • Context items for acting on the selected component, such as Find All References, Show Methods This Calls, etc.
  • Layout
    • Context items for how the code map is displayed, such as Top to Bottom, etc.
  • Find
    • Find feature
  • Call Stack
    • Automatically show debugger call stack on Code Map
  • Share
    • Collaboration options, such as Copy Image, Email as Image or Portable XPS (to be viewed in XPS viewer), Save as Portable XPS, Save as DGML, Move DGML (once saved) into a folder/project within the solution, etc.
  • Comment
    • Add comment to the code map
  • Zoom
    • Zoom to fit the code map window or enter a zoom percentage (mouse wheel also controls zooming in and out)
  • Legend
    • Toggle to display window of icons and icon descriptions of icons
  • Filters
    • Toggle to display window of filters available for selection and de-selection
  • Skip Build
    • Toggle to determine if code map should build solution before generation of code map
  • Include Parents
    • Toggle to determine if code map should include parents of components to be generated

Summary

The Sage 300 web screens represent a large and complex code base where understanding and viewing the components, relationships and references can be a daunting task.

Microsoft’s Code Maps, which is a core feature of Visual Studio 2013 Ultimate and Visual Studio 2015/2017 Enterprise Editions, is a tool that provides the ability to visualize relationships and dependencies in real time from within the Visual Studio IDE.

To create a Code Map you must be on either Visual Studio 2013 Ultimate Edition or Visual Studio 2015/2017 Enterprise Edition.

Developers can leverage this tool to graphically display relationships and dependencies for a project or projects, a class or method. A simple example was used to provide a graph of a class and its externally referenced method calls.

The graphs can be used at an elevated level to show project relationships or a detailed level to show code flow and dependencies. This visualization is a proven way to understand complex concepts, and understand and navigate complex code.

As a standard disclaimer, any topic in this article is subject to review and doesn’t represent a commitment as to when it will be available.

 

 

Advertisements