top of page

ESAPI Essentials 1.1 and 2.0

A few months ago, I introduced ESAPI Essentials—a toolkit for working with ESAPI (available via NuGet). I've recently added one major feature: asynchronous access to ESAPI for binary plugin scripts. You can now use this feature for ESAPI 13.6 using EsapiEssentials 1.1.


In addition, ESAPI Essentials now supports ESAPI 15.6. To use it, you need to reference EsapiEssentials 2.0. All of the features in ESAPI Essentials are available for ESAPI 15.6.


Asynchronous ESAPI for Binary Plugin Scripts


This feature is largely based on my blog post Create ESAPI Scripts That Don’t Freeze the UI. It allows you to run ESAPI code on a different thread than the UI thread. This prevents your UI from freezing when the ESAPI code takes a long time to execute.


The best way to start is to create an EsapiService class that derives from EsapiServiceBase. This will give you access to a couple of RunAsync methods that run ESAPI code on the Eclipse thread.


The next step is to create a new thread for running all of your UI code. The UiRunner class does this for you. After instantiating your EsapiService, create an instance of UiRunner and call the Run method, passing in your start-up code for setting up and showing your main window.


Here's an example of a script that does this (available as a sample project in EsapiEssentials).


using EsapiEssentials.Plugin;
using EsapiEssentials.Samples.AsyncPlugin;

namespace VMS.TPS
{
    public class Script : ScriptBase
    {
        public override void Run(PluginScriptContext context)
        {
            var esapiService = new EsapiService(context);

            using (var ui = new UiRunner())
            {
                ui.Run(() =>
                {
                    var window = new MainWindow();
                    var dialogService = new DialogService(window);
                    var viewModel = new MainViewModel(esapiService, dialogService);
                    window.DataContext = viewModel;
                    window.ShowDialog();
                });
            }
        }
    }
}

The sample project uses the plugin runner, which is why it derives from ScriptBase. Also, it uses a dialog service to show a dialog box with a progress bar as the ESAPI code runs on a separate thread.

Related Posts

See All

Announcement: ESAPI Subreddit

A few months ago, Matt Schmidt started the ESAPI subreddit. It's another useful resource for finding and discussing ESAPI-related topics....

Dump All Patient Data from ESAPI

If, for whatever reason, you need to dump out all of the data for a patient from ESAPI, there's a quick and dirty way to do it. Well,...

Comments


bottom of page