Glue42 Enterprise is now io.Connect Desktop! The new documentation site for all interop.io products is located at docs.interop.io.

Intents

Overview

Available since Glue42 Enterprise 3.12

The Intents API is accessible through glue.Intents.

Finding Intents

To find all registered Intents, use the GetIntents() method:

var intents = await glue.Intents.GetIntents();

To find a specific Intent, use the AwaitIntent() method:

var intent = await glue.Intents.AwaitIntent("ShowChart");

Raising Intents

To raise an Intent, use the Raise() method. It accepts an Intent name (or Intent object) and an Intent request builder as arguments:

await glue.Intents.Raise("ShowChart",
    builder => builder.WithContext("instrument", new {id = new {ticker = "msft"}}));

Targeting Intent Handlers

When raising an Intent, optionally target one or more Intent handlers using the Intent request builder to specify a handler:

var intent = await glue.Intents.AwaitIntent("ShowChart");
var handler = intent.Handlers[0];

await glue.Intents.Raise(intent,
    // Pass the desired Intent handler.
    builder => builder.WithHandler(handler));

Or:

await glue.Intents.Raise("ShowChart",
    builder =>
        // Target a specific Intent handler.
        builder.WithTargetSelector(handler =>
            handler.ApplicationName.Contains("InstrumentChart")));

Context

To pass initial context to the Intent handler:

await glue.Intents.Raise("ShowChart",
    builder => builder.WithContext("instrument", new {id = new {ticker = "msft"}}));

To handle the context in the Intent handler, use the AddIntentListener() method (see Registering Intents at Runtime):

glue.Intents.AddIntentListener("ShowChart",
    intent => intent.WithDisplayName("Intrument Chart"),
    context =>
    {
        Dispatcher.BeginInvoke((Action) (() =>
        {
            var wnd = new Window
            {
                // Handle the passed context.
                Content = new TextBox { Text = context.Data.AsString }
            };
            wnd.Show();
        }));
    });

To pass app starting context to the Intent handler:

// Create app context.
var context = AppManagerContext.CreateNew();
context.Set("instrument", "msft");

await glue.Intents.Raise("ShowChart",
    builder => builder.WithAppStartContext(context));

Registering Intents at Runtime

To register an Intent at runtime, use the AddIntentListener() method. It accepts an Intent name, an Intent builder and an Intent context handler as arguments:

// Register an Intent at runtime.
glue.Intents.AddIntentListener("ShowChart",
    // Build the Intent.
    intent => intent.WithDisplayName("Intrument Chart"),
    // Specify how to handle the passed context.
    context =>
    {
        Dispatcher.BeginInvoke((Action) (() =>
        {
            var wnd = new Window
            {
                // Use the context.
                Content = new TextBox { Text = context.Data.AsString }
            };
            wnd.Show();
        }));
    });

Note that when you register an Intent only at runtime (the Intent isn't defined in the app configuration file), your app must be running in order to handle the Intent. If your app isn't running when this Intent is raised, it won't be available as a possible Intent handler.