public ClientOutboundConnectionFactory(
     IOptions <ConnectionOptions> connectionOptions,
     IOptions <ClientConnectionOptions> clientConnectionOptions,
     ConnectionCommon connectionShared)
     : base(connectionShared.ServiceProvider.GetRequiredServiceByKey <object, IConnectionFactory>(ServicesKey), connectionShared.ServiceProvider, connectionOptions)
 {
     this.connectionShared        = connectionShared;
     this.clientConnectionOptions = clientConnectionOptions.Value;
 }
Пример #2
0
        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;
            }
        }
Пример #3
0
 public ClientOutboundConnectionFactory(
     IServiceProvider serviceProvider,
     IOptions <ConnectionOptions> connectionOptions,
     IOptions <ClientConnectionOptions> clientConnectionOptions,
     MessageFactory messageFactory,
     INetworkingTrace trace)
     : base(serviceProvider.GetRequiredServiceByKey <object, IConnectionFactory>(ServicesKey), serviceProvider, connectionOptions)
 {
     this.serviceProvider         = serviceProvider;
     this.clientConnectionOptions = clientConnectionOptions.Value;
     this.messageFactory          = messageFactory;
     this.trace = trace;
 }