Run and Test Plug-In Scripts from Visual Studio

Testing Plug-in Scripts

Testing plug-in scripts in Eclipse is annoying at best. For one, any time you make a change to the script you need to re-start Eclipse, or it’ll lock up your script DLL and won’t even let you compile.

Another problem with running your script in Eclipse is that you can’t use the debugger (easily). It would be nice if you could just press F5 in Visual Studio and run your script, set up breakpoints, or step through your code line by line.

PluginTester

To help with these problems, Eduardo Acosta (a former software developer at the University of Michigan, now at Varian) wrote PluginTester, available at the Varian Developers Forum.

PluginTester is a stand-alone app that creates an Eclipse Application object and calls your script’s main method. If you add the PluginTester project to your solution, you can run it from Visual Studio and step through the code, including yours.

PluginTester is a great tool for running and debugging your scripts, but it has one drawback: it requires that you edit its code to specify the method to call in your script. And you need to do this for every new script you write.

EclipsePlugInRunner

To address this drawback, I wrote a new tool based on PluginTester, which I’ve creatively called EclipsePlugInRunner. You don’t need to modify its code in order to run your script. Additionally, your script doesn’t need to know about EclipsePlugInRunner. In other words, neither library references the other. After all, the tool is there only for running it from Visual Studio and won’t be needed once your script is running in Eclipse.

I’ve made the source code available on GitHub: EclipsePlugInRunner. But the best way to start using it is through NuGet. First, open a plug-in script you’d like to run in Visual Studio. Add the following method to your Script class:

This method is now your “main” method, so any code that used to be in the Execute method should go here. Notice that there’s no ScriptContext anymore. EclipsePlugInRunner will call the Run method, but because it can’t create a ScriptContext object, it needs to pass the context members individually. This means that you’ll need to either (1) modify any code that uses the ScriptContext to use the member objects instead, or (2) create your own wrapper to contain the context members and use it instead.

The Execute method should now just call the Run method and pass the appropriate members:

Now, add a new WPF Application project to your solution. If your script’s project is named MyScript, you can call the WPF project something like MyScript.Runner. Remove the MainWindow.xaml file, which will also remove the associated MainWindow.xaml.cs file.

Right-click on the WPF project and select “Manage NuGet Packages…” Search for “esapi” and you should see the EclipsePlugInRunner package. Install it. (Update: If you’re using ESAPI 13.6, use version 1.0.0. If you’re using ESAPI 15.5, use version 2.0.0.)

Right-click on the WPF project again and select “Add Reference…” Choose the “Projects” item on the left bar, and check the project that contains the main Script class.

Open the App.xaml file and replace the StartupUri line with the following:

Open the App.xaml.cs file and add the following handler:

Make sure that you’ve added the correct using statements (in this case, EclipsePlugInRunner.Scripting and VMS.TPS). EclipsePlugInRunner uses the x64 ESAPI assemblies, so you’ll need to set the WPF project’s CPU to x64 as well. Also, set the project as the “Start Up” project. Finally, reference the Varian assemblies VMS.TPS.Common.Model.API and VMS.TPS.Common.Model.Types.

Running Your Script

When you start the application, you’ll be prompted for your username as password. These are the same you use to log in to Eclipse. A window will show up, which looks somewhat similar to PluginTester:

EclipsePlugInRunner

Enter the patient ID1, click Open, and choose the PlanSetup(s) or PlanSum(s) you’d like to be in scope. Then, choose the PlanSetup that you’d like to be active. Click on Run and your script will run with the context you’ve chosen (you can also double-click on the active PlanSetup in order to run your script).

Recent contexts will be displayed at the top, where you can double-click on one and quickly run your script with that context. If you click on Open for a recent context, you’ll be able to modify the context and run the script with that. Recent contexts are automatically saved in the bin\Debug or bin\Release directory of the WPF Application in your project.

When you’ve run your script and then closed it, you’ll go back to the Runner window. You may open another patient or context and run the script again. If you want the Runner window to automatically close when you close your script, choose the “Exit after plug-in script ends” option at the bottom.

Open Source

EclipsePlugInRunner is open source, so you can submit issues, fork it, or send pull requests. It’s not a finished product and can use many improvements. Feel free to contribute!

17 thoughts on “Run and Test Plug-In Scripts from Visual Studio

    1. Carlos Anderson Post author

      Hi Albert,
      EclipsePlugInRunner uses the Window object that’s obtained via the Execute method. This Window object is a WPF class, so I don’t believe you can use it with WinForms. However, feel free modify EclipsePlugInRunner so that it optionally uses the Execute method without the Window object. This would allow you to create your own WinForms windows.
      — Carlos

      Reply
  1. Matt Schmidt

    Hi Carlos,

    I just started using this. It is working like a charm and very easy to debug my script. One note, I did have to add the ESAPI libraries to the plugin runner script to get it to work. I’m not sure if I overlooked that in your explanation or not, but the debug messages were pretty easy to follow.

    Best Regards,

    Reply
  2. RACHID BOUCENNA

    Hi carlos,

    I get this issue Cannot locate resource ‘app_onstartup’.
    not clear for me what is the problem, do you have an idea ?
    Thank you for your feedback
    Rachid

    Reply
  3. Scott

    Hi Carlos

    I have followed the instructions to install the script runner but I am getting the error Cannot locate required assembly VMS.TPS.Common.Model.dll. It is complaining in the detail about the VMS.TPS.Common.Model.API.pdb not being located. Any idea how I can correct this?

    Cheers
    Scott

    Reply
    1. Carlos Anderson Post author

      Hi Scott,

      In the WPF Application project that you created, what is the location of the Varian assemblies that you referenced? Also, which version of Eclipse are you using?

      Reply
      1. Scott

        Hi Carlos

        the paths are as follows:

        C:\Program Files (x86)\Varian\Vision\13.6\Bin64\VMS.TPS.Common.Model.API.dll
        C:\Program Files (x86)\Varian\Vision\13.6\Bin64\esapi\VMS.TPS.Common.Model.Types.dll

        Have also tried C:\Program Files (x86)\Varian\Vision\13.6\Bin64\esapi\VMS.TPS.Common.Model.API.dll but this did not work either.

        Eclipse version is 13.6

        Cheers
        Scott

        Reply
          1. Scott

            Sorry for the delays in replying. It wouldn’t let me paste a picture.

            It is:
            Application has terminated unexpectedly.
            Error Message:
            Cannot locate required assembly VMS.TPS.Common.Model.dll

            It pops up as a messagebox over the window at the end of the build process and hence won’t allow the application past that point.

          2. Carlos Anderson Post author

            If you don’t mind, send me your VS solution and I can take a look at it (carlosjanderson at gmail). Otherwise, I’m thinking it could be a version incompatibility between the ESAPI I used in the EclipsePlugInRunner and the ESAPI you have on your machine. They’re both 13.6, but perhaps not the exact same version.

  4. Colin

    Hi Carlos,

    Thanks for sharing the code. I have an issue running the EclipsePlugInRunner. The Eclipse Plug-in Runner window was showing up without asking me for the user name and password. When I tried to type in the patient ID, it crashed. Does it need to be run on a Eclipse workstation?

    Thanks,

    Reply
    1. Carlos Anderson Post author

      Hi Colin,
      The EclipsePlugInRunner is meant to be run on a machine that has the full installation of ESAPI. If you can’t run a stand-alone ESAPI app on your machine, then the EclipsePlugInRunner won’t work.

      Reply
  5. Colin

    Thanks Carlos, I can run a stand-alone ESAPI app on my computer. I am trying to understand that which part of your code calls the Aria-login pop up window. In the stand alone code, VMSAPI.Application.CreateApplication(user, password) is launching the login window but I do not see similar code in the EclipsePlugInRunner.

    By the way, you mentioned above “you’ll need to either (1) modify any code that uses the ScriptContext to use the member objects instead, or (2) create your own wrapper to contain the context members and use it instead.”. What objects do you refer to when mentioning member objects.

    Thanks,

    Colin

    Reply
    1. Carlos Anderson Post author

      In the EclipsePlugInRunner, the MainViewModel creates the Application (see https://github.com/redcurry/EclipsePlugInRunner/blob/293f784b0c46b0517d372f02282789f62ed14b76/src/EclipsePlugInRunner/ViewModels/MainViewModel.cs#L110).
      By member objects, I mean the Patient, PlanSetup, etc. that are in the ScriptContext object. Since the Run method doesn’t take in a ScriptContext as a parameter, you’ll need to adapt your code so that it doesn’t use a ScriptContext object but instead uses the individual parts (Patient, PlanSetup, etc.). I hope that clarified what I meant to say.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *