예제 #1
0
        private async void onQRCodeConnectClicked(object sender, EventArgs e)
        {
            var scanner    = new ZXing.Mobile.MobileBarcodeScanner();
            var scanResult = await scanner.Scan();

            if (scanResult != null && scanResult.Text != "")
            {
                var              connectInfo     = Connection.DecodeBluetoothConnection(scanResult.Text);
                Guid             guid            = connectInfo.Guid;
                IBluetoothDevice bluetoothDevice = DependencyService.Get <IBluetoothManager>().GetBluetoothDevice(connectInfo.DeviceAddress);


                IConnectionManager       connectionManager = DependencyService.Get <IConnectionManager>();
                IClientConnection        currentConnection = connectionManager.ControllerConnection as IClientConnection;
                ConnectionEstablishState connectState      = ConnectionEstablishState.Failed;
                IClientConnection        connection        = DependencyService.Get <IBluetoothManager>().CreateRfcommClientConnection(bluetoothDevice, guid);
                if (connectionManager.ControllerConnection != null)
                {
                    bool result = await DisplayAlert("Connect", "Stop Current Connection ?", "Yes", "No");

                    if (result)
                    {
                        if (currentConnection.ConnectionEstablishState == ConnectionEstablishState.Connecting)
                        {
                            currentConnection.AbortConnecting();
                        }
                    }
                }
                connectionManager.ControllerConnection = connection;
                connectState = await connection.ConnectAsync();
            }
        }
예제 #2
0
        public void ConnectionLimitRestartListening()
        {
            IServerConnection connection = null;

            provider.ConnectionMade += (sender, e) =>
            {
                if (connection == null)
                {
                    connection = e.Connection;
                }
            };

            ConnectionLimit();

            Assert.IsNotNull(connection);

            connection.DisconnectAsync();

            AsyncTest test = new AsyncTest();

            provider.ConnectionMade += test.PassHandler;

            IClientConnection client = GetNewClientConnection();

            client.Disconnected += test.FailHandler;
            client.ConnectAsync(Target, MessageTypes);

            test.Assert(10000);
        }
        private async void onConnectClicked(object sender, EventArgs e)
        {
            if (_SelectedGuid == null)
            {
                Debug.WriteLine("NO UUID SELECTED");
                return;
            }
            IConnectionManager       connectionManager = DependencyService.Get <IConnectionManager>();
            IClientConnection        currentConnection = connectionManager.ControllerConnection as IClientConnection;
            ConnectionEstablishState connectState      = ConnectionEstablishState.Failed;
            IClientConnection        connection        = DependencyService.Get <IManagerManager>().BluetoothManager.CreateRfcommClientConnection(_BluetoothDevice, (Guid)_SelectedGuid);

            if (connectionManager.ControllerConnection != null)
            {
                bool result = await DisplayAlert("Connect", "Stop Current Connection ?", "Yes", "No");

                if (result)
                {
                    if (currentConnection.ConnectionEstablishState == ConnectionEstablishState.Connecting)
                    {
                        currentConnection.AbortConnecting();
                    }
                }
            }
            connectionManager.ControllerConnection = connection;
            connectState = await connection.ConnectAsync();

            if (connectState == ConnectionEstablishState.Succeeded)
            {
            }
        }
 private async void _OnConnectButtonClicked(object sender, EventArgs e)
 {
     if (_SelectedDevice != null)
     {
         IClientConnection connection = _WifiDirectManager.CreateClientConnection(_SelectedDevice);
         await connection.ConnectAsync();
     }
 }