IRunicConnections interface

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

public interface IRunicConnections

The page connections of the Window whose DI scope resolved the service, and the connection whose request runs now. Take it in a ViewModel's constructor, for example to show who else is viewing a multi-client CS-WebUI window.

Remarks

RunicWindowServiceCollectionExtensions.AddRunicWindowService registers it per scope. OpenWindowAsync binds it to the Window it opens when the Window's Bridge attaches, on Runic Desktop and CS-WebUI; RunicWindowTestHost.Create binds it to the test window. Resolved anywhere else, for example in a WPF RunicViewHost, which creates no Window scope, it lists no connections and raises no events.

A connection is listed once its page completed the Views protocol hello, and removed when the transport reports it closed. IRunicConnections.Current changes and the events are raised in a turn of the Window's model context, as a command body runs, so a handler may change bound state. The turn runs in no invocation: a handler has no IRunicConnections.Caller, whatever reported the change. A connection the window already had when the service was bound is reported with IRunicConnections.Connected too. A connection that closes before its IRunicConnections.Connected turn runs is never reported. Once the Window's model context takes no more turns, because the Window is closing, IRunicConnections.Current still follows its connections but no event is raised; closing the Window raises no IRunicConnections.Disconnected.

A CS-WebUI window with WebUI's MultiClient configuration can have several connections; Runic Desktop's window has one page connection, a new one after each reload. Only the page decides who connects; see the CS-WebUI package's security notes before letting several clients share a window.

Properties

Caller

RunicConnection? Caller { get; }

The connection whose command, operation or in-page menu click of this Window runs on the current asynchronous flow, or null outside one, such as in a timer, the window scope or another Window's command.

Remarks

It reads RunicInteractionInvocation.Current, which only the Bridge runtime enters, with the identity the transport authenticated for the request. Application code cannot set it. It stays the same through the command's awaits, also after the connection closed, until the command ends: a timer, Task.Run or loop that the command started and that runs on after it reads null. Long-lived work of the Window enters RunicInteractionInvocation.EnterWindow. A connection key is never reused within a Window, so a command whose connection closed never matches a later page, also when the transport reused its key.

Current

IReadOnlyList<RunicConnection> Current { get; }

The Window's open connections, in the order they connected. Each read returns a snapshot.

Events

Connected

event EventHandler<RunicConnectionEventArgs>? Connected

Raised in a model turn when a page connection completes its hello.

Disconnected

event EventHandler<RunicConnectionEventArgs>? Disconnected

Raised in a model turn when a connection that IRunicConnections.Connected reported closes.