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; }
private OpenFinProxy() { string unique = Guid.NewGuid().ToString(); _runtime = Runtime.GetRuntimeInstance(new RuntimeOptions { //Version = "19.89.60.5", Version = "18.87.55.19" //UUID = unique //ProcessHelper.IsOms ? EzeOMSUuid : NonEzeOMSUuid }); // get command line args, check to see if we’re running as the “server” string[] commandLine = Environment.GetCommandLineArgs(); bool isChannelProvider = bool.Parse(commandLine[1]); _runtime.Connect(async() => { Console.WriteLine("----------------------- Application connected to OpenFin -----------------------"); if (isChannelProvider) { _channelProvider = _runtime.InterApplicationBus.Channel.CreateProvider("1"); _channelProvider.RegisterTopic <string>("SayHello", (payload) => { return($"Hello {payload}!"); }); Console.WriteLine("----------------------- Channel 1 created -----------------------"); } else { // "may" be an issue //_channelClient = _runtime.InterApplicationBus.Channel.CreateClient(new ChannelConnectOptions("1") //{ // Wait = true //}); _channelClient = _runtime.InterApplicationBus.Channel.CreateClient("1"); await _channelClient.ConnectAsync(); // await here never finishes, and without connection, the sub/pub fails Debugger.Launch(); Console.WriteLine("----------------------- ChannelClient created -----------------------"); } IsConnected = true; }); }