RunicInteractionInvocation class

Namespace Runic.Application.Views in Runic.Application.Views 0.23.0

public sealed class RunicInteractionInvocation

The trusted origin of work which may ask a browser to handle an interaction or a view request. The bridge runtime establishes a command invocation around a generated command or operation, with the browser identity its transport authenticated. The window scope has no browser identity: a RunicWindow enters it around its close decision, a menu-bar command runs in it, and application code enters it with RunicInteractionInvocation.EnterWindow for other work of a window, such as a timer or a notification's activation. Application code reads the scope through RunicInteractionInvocation.Current but cannot enter a command invocation, so it cannot claim a client or connection identity.

Properties

CancellationToken

public CancellationToken CancellationToken { get; }

Cancels interactions requested by this invocation.

ClientKey

public string? ClientKey { get; }

The trusted browser client identity, if the invocation came from one.

Remarks

The key the window's transport authenticated for the request, never a value in its JSON. A Window's IRunicConnections.Caller reads it.

CommandName

public string? CommandName { get; }

The generated command that started the invocation, if any.

ConnectionKey

public string? ConnectionKey { get; }

The trusted transport connection identity, if the invocation came from one.

Remarks

The key the window's transport authenticated for the request, never a value in its JSON. A Window's IRunicConnections.Caller reads it. The window gives each connection a key that is unique for its lifetime: the transport's key with a #n suffix from a counter that never repeats, or the transport's key itself for a transport whose keys never repeat (Runic Desktop). A command that runs on after its connection closed therefore never reaches the connection that reused its transport key.

Current

public static RunicInteractionInvocation? Current { get; }

The invocation scope on the current asynchronous flow, or null.

Remarks

An invocation with a connection identity ends with the work that entered it: a bridged command or operation when its task completes, a synchronous command when Execute returns, and an in-page menu click when its command's task completes for a CommunityToolkit IAsyncRelayCommand, or when Execute returns otherwise. An ended invocation is no invocation: work it started and that runs on, such as a timer, Task.Run or a background loop, reads null here, so its interactions and view requests follow the rules outside a scope and IRunicConnections.Caller is null. A navigation that an invocation starts runs its guards in an invocation with the same identity until the navigation ends. The window scope (a native menu-bar command, the window's close decision, RunicInteractionInvocation.EnterWindow) names no page and does not end. Long-lived work of a window enters RunicInteractionInvocation.EnterWindow itself.

Route

public string Route { get; }

The bridge route whose browser client may handle interactions, __runicWindowClose while the window decides a close, or __runicWindow in the window scope.

Session

public WindowContentSession Session { get; }

The window content session that owns the invocation.

Methods

EnterWindow

public static IDisposable EnterWindow(object viewModel, CancellationToken cancellationToken = default)

Enters the window scope of the one window that presents viewModel, until the returned scope is disposed, for work of that window that no page started, such as a timer or a notification's activation.

Parameters

viewModel

A ViewModel that a route of the window presents.

cancellationToken

Ends the interactions asked in the scope.

Returns

The scope; dispose it to restore the previous one. It does nothing when no scope was entered.

Exceptions

ArgumentNullException

viewModel is null.

Remarks

In the scope, a ReactiveUI interaction or a ViewQuestion asks the one presentation of the window that handles it, as during the window's close decision, and a ViewRequest goes to the one presentation of the window that handles it. With none or several, the interaction uses its .NET fallback and the request follows its ViewRequestDelivery.

It enters no scope, and the current one stays, when no window or several present the ViewModel, and inside a command that a page of that window invoked: that command already reaches its own page, and the window scope would widen it to another page. RunicInteractionInvocation.TryEnterWindow tells which happened. The scope has no client or connection identity, so it never reaches one page's presentation on behalf of another.

using (RunicInteractionInvocation.EnterWindow(this))
    if (await ConfirmReload.Handle(path)) await ReloadAsync();

TryEnterWindow

public static bool TryEnterWindow(object viewModel, out IDisposable scope, CancellationToken cancellationToken = default)

Enters the window scope of the one window that presents viewModel, as RunicInteractionInvocation.EnterWindow does, and returns whether it entered it.

Parameters

viewModel

A ViewModel that a route of the window presents.

scope

The scope to dispose; it does nothing when the method returns false.

cancellationToken

Ends the interactions asked in the scope.

Returns

true when it entered the window scope; false when no window or several present the ViewModel, or a command that a page of that window invoked is current and stays.

Exceptions

ArgumentNullException

viewModel is null.