Пример #1
0
 public ReceivingChoreographer(CommsContact opponent)
 {
     Opponent = opponent;
 }
Пример #2
0
        public void Connect(BTPeer peer)
        {
            // Make this a no-op if it's already connected, just in case.
            if (Clients.ContainsKey(peer.Device))
            {
                return;
            }
            // Maybe that's not working?
            if (Clients.Keys.Any(p => p.Address == peer.Device.Address))
            {
                return;
            }

            if (_progressDialog != null && _progressDialog.IsShowing)
            {
                _progressDialog.Dismiss();
            }
            bluetoothAdapter.CancelDiscovery();

            //_progressDialog = ProgressDialog.Show(this, $"Connecting to {_device.Name} ({_device.MACaddressOrRole})", "Press back to cancel", true, true);

            var newTeamMate = new CommsContact();

            newTeamMate.BtPeer    = peer;
            newTeamMate.Name      = peer.Device.Name;
            newTeamMate.IPaddress = peer.Device.Address;
            var client = new BluetoothClient(GlobalBluetoothDeactivator.Token);

            // Arrange for appropriate outcomes to success or failure of our connection attempt...
            client.OnConnectionSuccess += (o, e) =>
            {
                //newTeamMate.Client = client;
                //AddressBook.Add(newTeamMate);
                newTeamMate.Client = client;
                BluetoothMessageCenter.TemporaryAddressBook_SingleEntry = newTeamMate;
                Clients.Add(_device, client);
                KnownMACaddresses.Add(_device.MACaddressOrRole);
                Res.Storage.Put(KnownMACaddressesKey, KnownMACaddresses);
                _progressDialog?.Dismiss();
                RefreshDetails(true);
            };
            client.OnConnectionFailure += (o, e) =>
            {
                _progressDialog?.Dismiss();
                KnownMACaddresses.Remove(_device.MACaddressOrRole);
                Res.Storage.Put(KnownMACaddressesKey, KnownMACaddresses);
                client = null;
                RefreshDetails();
            };
            client.OnDisconnection += (o, e) =>
            {
                Clients.Remove(_device);
                RefreshDetails();
            };
            client.OnMessageReceived += (o, e) =>
            {
                RelayToast($"Client received ({e.Value.Type}) {e.Value.Content}");
            };

            //... then make the attempt itself.
            client?.Connect(newTeamMate.BtPeer);
        }
Пример #3
0
 public SendingChoreographer(CommsContact opponent, Dictionary <string, Classifier> classifiers, int millisecondsGapMean = 1000, int millisecondsGapSigma = 500)
 {
     Opponent    = opponent;
     Classifiers = classifiers;
     Generator   = new SimpleChoreographyGenerator(classifiers, millisecondsGapMean, millisecondsGapSigma);
 }