public async Task LocalServer(DBusDaemonProtocol protocol) { if (!File.Exists("dbus-daemon")) { throw new SkipTestException("dbus-daemon not present"); } string service = "any.service"; string listenAddress = null; switch (protocol) { case DBusDaemonProtocol.Tcp: listenAddress = "tcp:host=localhost"; break; case DBusDaemonProtocol.Unix: listenAddress = $"unix:path={Path.GetTempPath()}/{Path.GetRandomFileName()}"; break; case DBusDaemonProtocol.UnixAbstract: listenAddress = $"unix:abstract={Guid.NewGuid()}"; break; } throw new NotImplementedException(); #if false // server var server = new ServerConnectionOptions(); using (var connection = new Connection(server)) { await connection.RegisterObjectAsync(new PingPong()); var boundAddress = await server.StartAsync(listenAddress); for (int i = 0; i < 2; i++) { // client using (var client = new Connection(boundAddress)) { // method await client.ConnectAsync(); var proxy = client.CreateProxy <IPingPong>(service, PingPong.Path); var echoed = await proxy.EchoAsync("test"); Assert.Equal("test", echoed); // signal var tcs = new TaskCompletionSource <string>(); await proxy.WatchPongAsync(message => tcs.SetResult(message)); await proxy.PingAsync("hello world"); var reply = await tcs.Task; Assert.Equal("hello world", reply); } } } #endif }
public static async Task Setup() { var server = new ServerConnectionOptions(); using var connection = new Connection(server); await connection.RegisterObjectAsync(new InstanceActivator()); try { var boundAddress = await server.StartAsync(TcpAddress); Log.Information($"SingleInstanceWatcher: Server listening at {boundAddress}"); return; } catch (Exception e) { Log.Information($"SingleInstanceWatcher: Unable to register server: {e.Message}. Attempting to connect to existing instance..."); } var clientOptions = new ClientConnectionOptions(TcpAddress); using var client = new Connection(clientOptions); try { await client.ConnectAsync(); } catch (Exception e) { Log.Warning($"SingleInstanceWatcher: Unable to connect to interface: {e.Message}"); Log.Warning($"SingleInstanceWatcher: Continuing without any instance restrictions. This can cause Bluetooth issues since only one app can interact with the earbuds at a time."); return; } Log.Information("SingleInstanceWatcher: Client connected to active instance"); try { var proxy = client.CreateProxy <IInstanceActivator>("any.service", InstanceActivator.Path); await proxy.ActivateAsync(); Log.Information( "SingleInstanceWatcher: Activation request to other instance sent. Shutting down now."); Environment.Exit(0); return; } catch (Exception e) { Log.Warning($"SingleInstanceWatcher: Unable to invoke activation method via proxy: {e.Message}"); Log.Warning($"SingleInstanceWatcher: Continuing without any instance restrictions. This can cause Bluetooth issues since only one app can interact with the earbuds at a time."); return; } }