/*
         * public void StartDiscovery()
         * {
         *
         * }
         *
         * public void EndDiscovery()
         * {
         *
         * }
         *
         * public event EventHandler DeviceDiscoveryStarted;
         * public event EventHandler DeviceDiscoverEnded;
         * public event EventHandler<DeviceFoundEventArgs> DeviceDiscovered;
         */
        public async Task <List <IBluetoothDevice> > FindDevicesWithIdentifier(string identifier)
        {
            PeerFinder.AlternateIdentities["Bluetooth:SDP"] = identifier;

            var result = new List <IBluetoothDevice>();

            var pairedDevices = await PeerFinder.FindAllPeersAsync();

            if (pairedDevices.Count == 0)
            {
                Debug.WriteLine("No paired devices were found.");
            }
            else
            {
                foreach (var pairedDevice in pairedDevices)
                {
                    var device = new WP80BluetoothDevice()
                    {
                        Name = pairedDevice.DisplayName, Address = pairedDevice.HostName.CanonicalName
                    };

                    device.BluetoothDevice = pairedDevice;
                    var id = pairedDevice.GetPropertyValue <string>("Id");

                    if (!String.IsNullOrEmpty(id))
                    {
                        var guid = Guid.Parse(id);
                        device.UniqueIdentifiers.Add(guid);
                    }
                    result.Add(device);
                }
            }

            return(result);
        }
        public async Task <List <IBluetoothDevice> > GetPairedDevices()
        {
            var devices = new List <IBluetoothDevice>();

            PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";

            var pairedDevices = (await PeerFinder.FindAllPeersAsync()).ToList();

            if (pairedDevices.Count > 0)
            {
                foreach (var paireddevice in pairedDevices)
                {
                    var device = new WP80BluetoothDevice()
                    {
                        Name = paireddevice.DisplayName, Address = paireddevice.HostName.CanonicalName
                    };

                    device.BluetoothDevice = paireddevice;

                    var id = paireddevice.GetPropertyValue <string>("Id");

                    if (!String.IsNullOrEmpty(id))
                    {
                        var guid = Guid.Parse(id);
                        device.UniqueIdentifiers.Add(guid);
                    }


                    devices.Add(device);
                }
            }


            return(devices);
        }