.NET Adapter
The .NET API provides much of the same functionality as the JavaScript API. For example, creating, wrapping and/or controlling applications/windows. It can listen/react to changes/events via addEventListener
and also send/receive messages over the InterApplicationBus.
OpenFin Licensing
Please include your
licenseKey
inRuntimeOptions.LicenseKey
when launching apps from the .NET Adapter. If interested in an Enterprise license, please visit Licensing.
Overview
All classes are defined in the Openfin.Desktop
namespace.
The Runtime class encapsulates the OpenFin Runtime and is responsible for connecting and communicating to a specific version of the OpenFin Runtime, it will be a singleton Object for each version and you can obtain an instance via the GetRuntimneInstance
method.
Requirement
This first code example is required in order for the consecutive code examples to run.
Examples
//These are the OpenFin Runtime Options.
var runtimeOptions = new RuntimeOptions {
Version = "alpha"
};
//Get an instance of the OpenFin Runtime
var runtime = Runtime.GetRuntimeInstance(runtimeOptions);
You will need to connect to the OpenFin Runtime before using it, you can either pass an Action to the Connect method that will be called either immediately if the runtime instance is connected or upon connecting, or you can use the Connected event for the same purpose.
//Connect to the OpenFin Runtime
runtime.Connect(() =>
{
Console.WriteLine("Runtime object connected!");
}
//Or subscribe to the connected event
runtime.Connected += (sender, e) => {
Console.WriteLine("Runtime object connected!");
};
The Runtime Object will grant you access to the DeskTopConnection
and the InterApplication Bus
runtime.Connect(() =>
{
// Subscribing to the InterApplicationBus
InterApplicationBus.Subscription<string>(runtime, "hello:of:sub").MessageReceived += (s, e) =>
{
Console.WriteLine(e.Message);
};
//Creating an App
var appOptions = new ApplicationOptions("MyApp", "MyApp-UUID", "https://www.openfin.co");
var app = runtime.CreateApplication(appOptions);
app.Run(() =>
{
Console.WriteLine("The application is now running!");
});
}
Have questions? Get in touch with us at [email protected].
Updated over 1 year ago