1

I can't get Visual Studio to model/map orphaned/discrete VB function code.

I am working with a legacy application that is written in VB.Net. Most of the application code/executable is opaque to the end user, but it has user-space customization behind forms that can interact with the form fields and the data model. What I need to do is map this user-defined code to look for bad interactions, such as circular logic.

TL, DR (the question): The objective is to get some kind of Entity-Relationship or dependency graph. I could draw these in Viso or something, but to do it for all the code is rather daunting.

It seems to me that there should be a way to easily establish patterns for functions and their internals, and reads and writes. I have not found anything so far. No one should try doing this with Excel - it's too much. I'm familiar with regular expressions, but in my experience, it wasn't really meant for a problem like this.

Is there some way?

ignore below if uninterested in details

I've tried using VS code map, but it needs references into the compiled parts of the application, which I don't have. So in VS, this user code is basically dead, orphaned code that isn't recognized. It has no class context and is only executed at run-time. It seems pretty difficult to do this way. So VS Code can syntax highlight it, but Visual Studio can't do anything with it, and the add-on tools like code map and dmg (directed graphs) don't see it.

As all of the user code are simply functions, I was hoping to simply transform it somehow into DMGL to see how they reference each other in this limited context. I could possibly do this using Excel or Regex, but this must be a major endeavor into re-inventing the wheel. I've even tried Object-Role Modeling, but it must be entered manually and is too cumbersome.

I've also looked at Roslyn, but it's the same problem as for Visual Studio

It probably would not be nice to copy all my suspicious functions here, but one could see the entire context at: Most likely culprits

The key to understanding the code shown is that there is a parent/header form representing Time Cards. Fields in the Timecards table are prefixed lmp* -- and there is a child sub form representing detail lines, called TimecardLines the database table, whose fields are prefixed lml*.

Examples

These two functions can be invoked when certain fields of a timecard line is edited by the user. I am not showing the code, only the interfaces. Each can reference and update fields that are managed by other functions. So it can be a nightmare to visualize possible cascading effects in textual form.

Items labeled as dependencies are calls to the compiled part of the application for which I have only the interface footprint, and that can't be analyzed other than as entry/exit points. Since they are immutable to me, I can't fix them, only avoid them where they are unnecessary.:

M1.Ax.Erp.Forms.Production.Timecard.TimecardLineView

  • Child of +Timecard entry issue: M1.Ax.Erp.Forms.Production.TimecardView

  • Note: Disregarding _Delete() events for the time being.

Function lmlRoundedEndTime_ValueChanged(sender, e)

updates:

lmlLaborHours - implicitly calls: - lmlLaborHours_ValueChanged()

  • lmlActualEndTime
    • implicitly calls:
      • TimecardLines_UpdateCompleted

inputs:

lmlRoundedStartTime

  • lmlRoundedEndTime
  • lmlShiftID

dependency:

App.Ax("Shift").``CalculateHours``()

behavior setting:

xapLMUpdateActualWithRounded

implicitly calls:

lmpRoundedEndTime_ValueChanged()

Function lmlRoundedStartTime_ValueChanged(sender, e)

updates:

  • lmlRoundedEndTime
    • implicitly calls:
      • lmlRoundedEndTime_ValueChanged
    • TimecardLines_UpdateCompleted
      • lmlLaborHours
      • lmlActualStartTime

inputs:

lmlActualStartTime

  • lmlRoundedStartTime
  • lmlRoundedEndTime
  • lmlLaborHours
  • lmlShiftID

dependencies:

App.Ax("Shift").``CalculateEndTime``()

  • App.Ax("Shift").CalculateHours()

behavior settings:

xapLMCalculateEndTime

  • xapLMUpdateActualWithRounded

When these are edited, the parent header is then updated, so a number of related parent functions can badly interact:

M1.Ax.Erp.Forms.Production.Timecard.TimecardView

Parent of: +Timecard entry issue: M1.Ax.Erp.Forms.Production.TimecardLineView

The following functions may be called by: TimecardLines_UpdateCompleted

Function lmpRoundedStartTime_ValueChanged(sender, e)

updates:

lmpPayrollHours

inputs:

lmpRoundedStartTime

  • lmpRoundedEndTime
  • lmpShiftID

dependencies:

App.Ax("TimecardFunctions").CalculateHours()

behavior settings:

xapDCPayCalculationMethod

Function lmpRoundedEndTime_ValueChanged(sender, e)

updates:

lmpPayrollHours

inputs:

lmpRoundedStartTime

  • lmpRoundedEndTime
  • lmpShiftID

dependencies:

App.Ax("TimecardFunctions").CalculateHours()

behavior settings:

xapDCPayCalculationMethod

And so on.

PS: I don't have the Reputation score to create the tag dmgl - it should be. If someone could tag it, that would be super.

  • Hopefully this is now deemed a positive question. – Joseph Shirk Dec 06 '21 at 17:05
  • I believe this is really a question for xslt and dmgl geeks. I can't put the dmgl tag on it, though a number of dmgl questions exist. – Joseph Shirk Dec 06 '21 at 17:18
  • Reopened and added the tag. Good luck! – djv Dec 06 '21 at 18:39
  • In order to have a legitimate XSLT question, you need to have an input that XSLT can read and process. This is typically XML, although in later versions it could be JSON or some structured text format such as CSV. I am not aware of a method that would enable XSLT to read VB code and parse it into something meaningful that could be transformed into a graph. – michael.hor257k Dec 06 '21 at 18:47
  • You are right. I assumed that the use of xslt would imply first xml. I shall refine my question and tags. – Joseph Shirk Dec 06 '21 at 19:53
  • When XML and XPath were considered hot or important within Microsoft someone implemented various XPathNavigator types, including an AssemblyNavigator for .NET assemblieS, see https://learn.microsoft.com/en-us/archive/msdn-magazine/2001/september/xml-files-writing-xml-providers-for-microsoft-net for the description though I am not sure the code is available anywhere. So at some stage, at least if the VB.NET code were in an assembly, XPath and XSLT within .NET could process it. – Martin Honnen Dec 06 '21 at 20:09
  • I'm trying to figure this out myself, reading things such as https://www.codeproject.com/Articles/22824/A-Model-to-Represent-Directed-Acyclic-Graphs-DAG-o and https://stackoverflow.com/questions/192220/what-is-the-most-efficient-elegant-way-to-parse-a-flat-table-into-a-tree/192462#192462 But SQL is a clunky way to handle this problem. – Joseph Shirk Dec 06 '21 at 21:11
  • @MartinHonnen This is the crux of my problem. I don't have a project or access to the whole assembly. It's licensed, compiled, and probably obfuscated application executable that just has hooks for user-custom vb functions. As far as I can tell there's no hint of a way to just take the output of say, a VS Code-type syntax highlighter, and mapping that . If there is a way to use Visual Studio to spy into someone else's application, I don't know how. Would be nice! – Joseph Shirk Dec 06 '21 at 21:17
  • I think DeltaXML and VS Code Notebooks will be a good way to handle this. https://www.one-tab.com/page/Shy6HI9tTX-KtR5GE_q_Ow – Joseph Shirk Dec 06 '21 at 21:47

0 Answers0