public MainWindow() { InitializeComponent(); var runtime = Runtime.GetRuntimeInstance(new RuntimeOptions { Version = "9.61.38.40" }); runtime.Connect(() => { //runtime.InterApplicationBus.subscribe("my-topic", (uuid, topic, message) => //{ // if (message != null) // { // Debug.WriteLine(message.ToString()); // } //}); // alternative InterApplicationBus.Subscription <string>(runtime, "my-topic").MessageReceived += (sender, msg) => { if (msg != null) { Debug.WriteLine(msg.Message); } }; }); }
public void LaunchOpenFinApp() { // Launch and Connect to the OpenFin Runtime // If already connected, callback executes immediately _runtime.Connect(() => { Console.WriteLine("Runtime object connected!"); RuntimeConnected?.Invoke(this, EventArgs.Empty); _openfinApp.isRunning(ack => { var isRunning = ack.getJsonObject().Value <bool>("data"); if (!isRunning) { _runtime.CreateApplication(_webAppOptions.StartupApplicationOptions); InterApplicationBus.Subscription <Order>(_openfinApp, ProcessOrderTopic).MessageReceived += ProcessOrder_MessageReceived; } // Run the OpenFin App // If already running, the callback executes immediately _openfinApp.Run(() => { Console.WriteLine("The application is now running!"); AppConnected?.Invoke(this, EventArgs.Empty); }); }); }); }
public void SubscribeToBroadcast(string topic, EventHandler <object> responseHandler) { if (_runtime.IsConnected) { InterApplicationBus.Subscription <object>(_runtime, topic).MessageReceived += (s, data) => responseHandler(null, data.Message); } }
public void onReady() { setConnectButtonState("Disconnect", true, true); interAppBus_ = controller_.getInterApplicationBus(); interAppBus_.addSubscribeListener((uuid, topic) => { bool exists = false; if (!subscriptionMap.TryGetValue(topic, out exists)) { subscriptionMap.Add(topic, true); if (subscriptionCallback != null) { subscriptionCallback(); } } }); Console.WriteLine("OnReady."); ApplicationOptions mainAppOptions = new ApplicationOptions(htmlDemoUuid_, htmlDemoUuid_, "https://developer.openf.in/htmlinterappcommdemo/1/index.html"); mainAppOptions.Version = "v1.0.0.0b"; mainAppOptions.IsAdmin = true; WindowOptions mainWindowOptions = mainAppOptions.MainWindowOptions; mainWindowOptions.AutoShow = true; mainWindowOptions.DefaultLeft = 100; mainWindowOptions.DefaultTop = 100; mainWindowOptions.DefaultWidth = 510; mainWindowOptions.DefaultHeight = 350; mainWindowOptions.Maximizable = false; mainWindowOptions.ShowTaskbarIcon = true; AckCallback afterAppCreation = (ack) => { Console.WriteLine("afterAppCreation"); Console.WriteLine(ack.getJsonObject().ToString()); AckCallback afterRun = (runAck) => { Console.WriteLine("afterRun"); Console.WriteLine(runAck.getJsonObject().ToString()); }; Console.WriteLine("app.run()"); // Using same callback for success and error in case app is already running htmlApplication_.run(afterRun, afterRun); }; // Using same callback for success and error in case app already exists Console.WriteLine("Creating App"); htmlApplication_ = new Application(mainAppOptions, controller_, afterAppCreation, afterAppCreation); htmlApplication_.addEventListener("closed", (ack) => { controller_.disconnect(); System.Windows.Forms.Application.ExitThread(); }); }
public void onReady() { setConnectButtonState("Disconnect", true, true); interAppBus_ = controller_.getInterApplicationBus(); interAppBus_.addSubscribeListener((uuid, topic) => { bool exists = false; if (!subscriptionMap.TryGetValue(topic, out exists)) { subscriptionMap.Add(topic, true); if (subscriptionCallback != null) subscriptionCallback(); } }); Console.WriteLine("OnReady."); ApplicationOptions mainAppOptions = new ApplicationOptions(htmlDemoUuid_, htmlDemoUuid_, "https://developer.openf.in/htmlinterappcommdemo/1/index.html"); mainAppOptions.Version = "v1.0.0.0b"; mainAppOptions.IsAdmin = true; WindowOptions mainWindowOptions = mainAppOptions.MainWindowOptions; mainWindowOptions.AutoShow = true; mainWindowOptions.DefaultLeft = 100; mainWindowOptions.DefaultTop = 100; mainWindowOptions.DefaultWidth = 510; mainWindowOptions.DefaultHeight = 350; mainWindowOptions.Maximizable = false; mainWindowOptions.ShowTaskbarIcon = true; AckCallback afterAppCreation = (ack) => { Console.WriteLine("afterAppCreation"); Console.WriteLine(ack.getJsonObject().ToString()); AckCallback afterRun = (runAck) => { Console.WriteLine("afterRun"); Console.WriteLine(runAck.getJsonObject().ToString()); }; Console.WriteLine("app.run()"); // Using same callback for success and error in case app is already running htmlApplication_.run(afterRun, afterRun); }; // Using same callback for success and error in case app already exists Console.WriteLine("Creating App"); htmlApplication_ = new Application(mainAppOptions, controller_, afterAppCreation, afterAppCreation); htmlApplication_.addEventListener("closed", (ack) => { controller_.disconnect(); System.Windows.Forms.Application.ExitThread(); }); }
static void Main(string[] args) { Console.WriteLine("Inter Application Bus Example"); var runtimeOptions = new RuntimeOptions { Version = "stable" }; var runtime = Runtime.GetRuntimeInstance(runtimeOptions); runtime.Connect(() => { /* * InterApplicationBus.Subscription<string>(runtime, "OpenFinTopic").MessageReceived += (s, e) => * { * Console.WriteLine(e.Message); * }; */ Console.WriteLine("The runtime has now connected."); var appOptions = new ApplicationOptions("application-name", "application-uuid", "about:blank"); appOptions.MainWindowOptions.AutoShow = false; appOptions.MainWindowOptions.Frame = true; appOptions.MainWindowOptions.Resizable = true; appOptions.MainWindowOptions.Name = "Test Window"; var application = runtime.CreateApplication(appOptions); application.run((a) => { Console.WriteLine("app started."); }, (n) => { }); }); string topic; string message; do { Console.WriteLine("Enter Topic:"); topic = Console.ReadLine(); Console.WriteLine("Enter Message:"); message = Console.ReadLine(); InterApplicationBus.Publish(runtime, topic, message); } while (!topic.Equals("quit")); }
private void SubscriberAddedHandler(string uuid, string topic) { if (RemoteUuid == uuid && Topic == topic) { RemoteSideConnected = true; while (_messageObjectQueue.Count > 0) { var queuedMessage = _messageObjectQueue.Dequeue(); InterApplicationBus.Send(RemoteUuid, Topic, queuedMessage); } } }
public MessageChannel(InterApplicationBus bus, string topic) { InterApplicationBus = bus; //RemoteUuid = remoteUuid; Topic = topic; // This initialization assumption requires that the MessageChannel be created before // the given application UUID / topic has not yet subscribed on the remote end RemoteSideConnected = true; InterApplicationBus.subscribe(topic, MessageReceivedHandler); InterApplicationBus.addSubscribeListener(SubscriberAddedHandler); InterApplicationBus.addUnsubscribeListener(SuscriberRemovedHander); }
public void SendData(object data) { //package the data and send it over the inter application bus var message = JObject.FromObject(new DataObject() { Data = data }); if (RemoteSideConnected) { InterApplicationBus.Send(RemoteUuid, Topic, message); } else { _messageObjectQueue.Enqueue(message); } }
public SerialPortProvider(Runtime runtime) { provider = runtime.InterApplicationBus.Channel.CreateProvider("SerialPort"); provider.RegisterTopic <string[]>("getPorts", OnGetPorts); provider.RegisterTopic <string>("sendKey", OnSendKey); provider.RegisterTopic <string>("openPort", OnOpenPort); provider.RegisterTopic <string>("closePort", OnClosePort); provider.ClientConnected += Provider_ClientConnected; /* TODO where is the ability to dispatch from the provider to a specific client? * https://cdn.openfin.co/docs/javascript/stable/Channel_ChannelProvider.html#dispatch * http://cdn.openfin.co/docs/csharp/latest/OpenfinDesktop/html/D9E92A51.htm * * Only the ChannelClient can DispatchAsync? * http://cdn.openfin.co/docs/csharp/latest/OpenfinDesktop/html/861D6A97.htm */ bus = runtime.InterApplicationBus; }
protected void ConnectOpenfin() { LogMessage("Configuration..."); var options = new RuntimeOptions { Version = RuntimeVersion, UUID = Uuid, }; LogMessage("Connection..."); Runtime = Runtime.GetRuntimeInstance(options); Runtime.OnIncommingMessage += (sender, e) => LogMessage(e.MessageContent); Runtime.OnOutgoingMessage += (sender, e) => LogMessage(e.MessageContent); Runtime.OnOutgoingMessage += (sender, e) => LogMessage(e.MessageContent); Runtime.Error += (sender, e) => LogMessage(e.ExceptionObject.ToString()); Runtime.Connect(() => { InterAppBus = Runtime.InterApplicationBus; LogMessage("Subscribers..."); InterAppBus.addSubscribeListener(SubscriptionListener); LogMessage("Unsubscribers..."); InterAppBus.addUnsubscribeListener(UnsubscriptionListener); var topics = ConfigurationManager.AppSettings .AllKeys .Where(key => key.StartsWith("openfin.topic")) .Select(key => ConfigurationManager.AppSettings[key]); foreach (var topic in topics) { LogMessage("Message Bus Subscribe..."); Subscriptions.Add(InterApplicationBus.Subscription <string>(Runtime, topic)); Subscriptions.Last().MessageReceived += (s, e) => LogMessage(e.Message); } }); }
private void submitButton_Click(object sender, RoutedEventArgs e) { InterApplicationBus.Publish(this.runtime, "messages", new { name = "WPF Demo", text = this.messageInput.Text }); }