Monitor the behavior of Data Standard and identify malfunctions so you can correct the code.
There are two methods that help you review and debug your code. The first method is the log file which is generated in the c:\temp folder (dataStandard<app>log.txt). The second method is logging within the code via the $dsDiag object.
Under c:\temp there are up to 3 log files: dataStandardVaultlog.txt, dataStandardInventorlog.txt, dataStandardAutoCADlog.txt. Each log file corresponds to the according application where Data Standard runs.
One issue that sometimes happens with Data Standard, is that after a change is made to the XAML file, the dialog does not show up, or in case of CAD, the standard application save dialog appears instead of the Data Standard dialog. This usually is a symptom of a typo in the XAML file. In such cases you'll find in the respective log file an error message like 'System.Windows.Markup.XamlParseException'.
The XamlParseException error is typical when there is mistake in the code that causes load or interpretation failure. Usually this error is accompanied by the line and the position of where the interpretation of the file failed, like this:
"System.Windows.Markup.XamlParseException: ......... Line 14, position 9. --->"
Usually the error is not exactly at that position but somewhat before. However, if you see this message, check your XAML syntax around the given line and position.
When encountering an error, always check the log file.
Within your PowerShell code, you can add logging information that might be useful for debugging your code in case of errors. For this purpose, the object $dsDiag provides methods like ShowLog() for opening a log window and Trace("hello") for writing something into the log window.
Additionally, it's possible to stop the code at a certain position and show up a little dialog that shows all the variables available and set at that time. This is done via Inspect().
To view the log window, open it with the InitializeWindow function, which is called right before the dialog shows up. Add these lines to the InitializeWindow function:
$dsDiag.ShowLog()
$dsDiag.Clear()
This will open the log window and clear the content.
Later you can add $dsDiag.Trace("my comments") in your code at different locations with according messages, so that you can follow in the log window how far your function comes. It's a good practice to add a "function start" and "function end" trace message at the beginning and end of each function, so that it becomes easy to follow the procedure call in the log window. Like this:
function myFunc { $dsDiag.Trace(">> myFunc") ... here comes your code ... $dsDiag.Trace("<< myFunc") }
Whether you use the >> and << as a symbol to entering and exiting a function, or you just write start-end, it's up to you.
If you want to know the exact state of the art of the variables at a given time, just add the $dsDiag.Inspect(). The code will hold at that time of execution, and in the dialog that shows up, the variables available with the given value are displayed. As the dialog usually shows up at the left side of the screen, make sure your Data Standard dialog is placec to the right, so that it does not overlap the inspector dialog.
Opening the inspector dialog within event handlers is a bit risky, so use logging in these cases.