Exemplo n.º 1
0
 private void OnRemoved(RomeRemoteSystem obj)
 {
     _dispatcherService.Invoke(() =>
     {
         RemoteSystems.Remove(obj);
         RaisePropertyChanged(nameof(HasAtLeastOneRemoteSystem));
     });
 }
Exemplo n.º 2
0
        internal async Task <bool> ConnectAsync(RomeRemoteSystem selectedRemoteSystem)
        {
            //_socketService.StopBroadcasting();
            _connectedRemoteSystem = selectedRemoteSystem;
            return(await _bluetoothService.ConnectAsync(selectedRemoteSystem));

            //Command(RemoteCommands.MiriotConnect);
        }
Exemplo n.º 3
0
        public async Task <bool> ConnectAsync(RomeRemoteSystem system)
        {
            _tsc = new TaskCompletionSource <bool>();

            _manager.StopScan();
            myDel.Connected = (s) =>
            {
                _tsc.TrySetResult(true);
            };
            _manager.ConnectPeripheral((CBPeripheral)system.NativeObject);

            return(await _tsc.Task);
        }
Exemplo n.º 4
0
 public Task <bool> ConnectAsync(RomeRemoteSystem system)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
        private async Task <string> OnCommandReceivedAsync(RemoteParameter parameter)
        {
            switch (parameter.Command)
            {
            case RemoteCommands.MiriotConfiguring:
                _dispatcherService.Invoke(() =>
                {
                    _vm.HasNoConfiguration = false;
                    _vm.IsConfiguring      = true;
                });
                return(string.Empty);

            case RemoteCommands.LoadUser:
                _dispatcherService.Invoke(async() =>
                {
                    await _vm.LoadUser(_vm.User);
                });
                return(string.Empty);

            case RemoteCommands.GetUser:
                _dispatcherService.Invoke(() =>
                {
                    _vm.HasNoConfiguration = false;
                    _vm.IsConfiguring      = true;
                });
                return(_vm.User.Id.ToString());

            case RemoteCommands.GraphService_Initialize:
                Messenger.Default.Send(new GraphServiceMessage(false));
                return(null);

            case RemoteCommands.GraphService_GetUser:
                Messenger.Default.Send(new GraphServiceMessage(true));

                var _graphService = SimpleIoc.Default.GetInstance <IGraphService>();

                await _graphService.LoginAsync();

                var graphUser = await _graphService.GetUserAsync();

                return(JsonConvert.SerializeObject(graphUser));

            case RemoteCommands.GoToCameraPage:
                SimpleIoc.Default.GetInstance <INavigationService>().NavigateTo(PageKeys.CameraSettings);
                return(null);

            case RemoteCommands.MiriotConnect:
                //_socketService.ListenTcp();
                return(null);

            case RemoteCommands.MiriotDiscovery:
            default:
                // Reply back
                var id  = _platformService.GetSystemIdentifier();
                var sys = new RomeRemoteSystem(null)
                {
                    Id          = id,
                    DisplayName = Environment.MachineName
                };
                return(JsonConvert.SerializeObject(sys));
            }
        }
Exemplo n.º 6
0
        private async void StartUnpairedDeviceWatcher()
        {
            // Request additional properties
            string[] requestedProperties = new string[] { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" };

            _deviceWatcher = DeviceInformation.CreateWatcher(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false),
                                                             requestedProperties,
                                                             DeviceInformationKind.AssociationEndpoint);

            // Hook up handlers for the watcher events before starting the watcher
            _deviceWatcher.Added += new TypedEventHandler <DeviceWatcher, DeviceInformation>(async(watcher, deviceInfo) =>
            {
                // Make sure device name isn't blank
                if (deviceInfo.Name != "")
                {
                    try
                    {
                        var service = await GattDeviceService.FromIdAsync(deviceInfo.Id);
                        if (service != null)
                        {
                        }
                    }
                    catch (Exception)
                    {
                    }
                    //if (service != null)
                    //{
                    //    var rfcommServices = await service?.GetRfcommServicesForIdAsync(
                    //RfcommServiceId.FromUuid(Constants.SERVICE_UUID), BluetoothCacheMode.Uncached);

                    //    if (rfcommServices?.Services.Count > 0)
                    //    {
                    //if (service.Uuid == Constants.SERVICE_UUID)
                    Discovered?.Invoke(new RomeRemoteSystem(deviceInfo)
                    {
                        Id          = deviceInfo.Id,
                        DisplayName = deviceInfo.Name,
                    });
                    //    }
                    //}
                }
            });

            _deviceWatcher.Updated += new TypedEventHandler <DeviceWatcher, DeviceInformationUpdate>(async(watcher, deviceInfoUpdate) =>
            {
                var temp = _devices.ToList();
                foreach (var device in temp)
                {
                    if (device.Id == deviceInfoUpdate.Id)
                    {
                        (device.NativeObject as DeviceInformation).Update(deviceInfoUpdate);

                        var d = _devices.Single(df => df.Id == device.Id);
                        d     = new RomeRemoteSystem(device);

                        Updated?.Invoke(d);
                        break;
                    }
                }
            });

            _deviceWatcher.EnumerationCompleted += new TypedEventHandler <DeviceWatcher, Object>(async(watcher, obj) =>
            {
            });

            _deviceWatcher.Removed += new TypedEventHandler <DeviceWatcher, DeviceInformationUpdate>(async(watcher, deviceInfoUpdate) =>
            {
                Removed?.Invoke(deviceInfoUpdate.Id);
            });

            _deviceWatcher.Stopped += new TypedEventHandler <DeviceWatcher, Object>(async(watcher, obj) =>
            {
            });

            _deviceWatcher.Start();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Invoked once the user has selected the device to connect to.
        /// Once the user has selected the device,
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async Task <bool> ConnectAsync(RomeRemoteSystem system)
        {
            // Make sure user has selected a device first
            if (system != null)
            {
                Debug.WriteLine("Connecting to remote device. Please wait...");
            }
            else
            {
                Debug.WriteLine("Please select an item to connect to");
                return(false);
            }

            // Perform device access checks before trying to get the device.
            // First, we check if consent has been explicitly denied by the user.
            DeviceAccessStatus accessStatus = DeviceAccessInformation.CreateFromId(system.Id).CurrentStatus;

            if (accessStatus == DeviceAccessStatus.DeniedByUser)
            {
                Debug.WriteLine("This app does not have access to connect to the remote device (please grant access in Settings > Privacy > Other Devices");
                return(false);
            }

            // If not, try to get the Bluetooth device
            try
            {
                _bluetoothDevice = await BluetoothDevice.FromIdAsync(system.Id);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                StopWatcher();
                return(false);
            }

            // If we were unable to get a valid Bluetooth device object,
            // it's most likely because the user has specified that all unpaired devices
            // should not be interacted with.
            if (_bluetoothDevice == null)
            {
                Debug.WriteLine("Bluetooth Device returned null. Access Status = " + accessStatus.ToString());
            }

            if (_bluetoothDevice == null)
            {
                return(false);
            }

            // This should return a list of uncached Bluetooth services (so if the server was not active when paired, it will still be detected by this call
            var rfcommServices = await _bluetoothDevice?.GetRfcommServicesForIdAsync(
                RfcommServiceId.FromUuid(Constants.SERVICE_UUID), BluetoothCacheMode.Uncached);

            if (rfcommServices?.Services.Count > 0)
            {
                _chatService = rfcommServices.Services[0];
            }
            else
            {
                Debug.WriteLine("Could not discover the chat service on the remote device");
                StopWatcher();
                return(false);
            }

            // Do various checks of the SDP record to make sure you are talking to a device that actually supports the Bluetooth Rfcomm Chat Service
            var attributes = await _chatService.GetSdpRawAttributesAsync();

            if (!attributes.ContainsKey(Constants.SERVICE_ATTRIBUTE_ID))
            {
                Debug.WriteLine(
                    "The Chat service is not advertising the Service Name attribute (attribute id=0x100). " +
                    "Please verify that you are running the BluetoothRfcommChat server.");
                StopWatcher();
                return(false);
            }
            var attributeReader = DataReader.FromBuffer(attributes[Constants.SERVICE_ATTRIBUTE_ID]);
            var attributeType   = attributeReader.ReadByte();

            if (attributeType != Constants.SERVICE_ATTRIBUTE_TYPE)
            {
                Debug.WriteLine(
                    "The Chat service is using an unexpected format for the Service Name attribute. " +
                    "Please verify that you are running the BluetoothRfcommChat server.");
                StopWatcher();
                return(false);
            }

            var serviceNameLength = attributeReader.ReadByte();

            // The Service Name attribute requires UTF-8 encoding.
            attributeReader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;

            StopWatcher();

            lock (this)
            {
                _chatSocket = new StreamSocket();
            }
            try
            {
                await _chatSocket.ConnectAsync(_chatService.ConnectionHostName, _chatService.ConnectionServiceName);

                Debug.WriteLine("Connected to : " + attributeReader.ReadString(serviceNameLength) + _bluetoothDevice.Name);
                _chatWriter = new DataWriter(_chatSocket.OutputStream);

                DataReader chatReader = new DataReader(_chatSocket.InputStream);
                ReceiveStringLoop(chatReader);

                return(true);
            }
            catch (Exception ex) when((uint)ex.HResult == 0x80070490)  // ERROR_ELEMENT_NOT_FOUND
            {
                Debug.WriteLine("Please verify that you are running the BluetoothRfcommChat server.");
                StopWatcher();
            }
            catch (Exception ex) when((uint)ex.HResult == 0x80072740)  // WSAEADDRINUSE
            {
                Debug.WriteLine("Please verify that there is no other RFCOMM connection to the same device.");
                StopWatcher();
            }

            return(false);
        }
        public async Task <bool> ConnectAsync(RomeRemoteSystem system)
        {
            await ConnectTo((CBPeripheral)system.NativeObject);

            return(true);
        }
Exemplo n.º 9
0
 private void OnSelect(RomeRemoteSystem sys)
 {
     SelectedRemoteSystem = sys;
 }