Example #1
0
        private void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
        {
            BLEAdvertisementInfo newBleAdvertisementInfo = new BLEAdvertisementInfo(eventArgs);

            BLEAdvertisementInfo oldBLEAdvertisementInfo = null;

            foreach (BLEAdvertisementInfo bLEAdvertisementInfo in DeviceCollection)
            {
                if (bLEAdvertisementInfo.BluetoothAddress == newBleAdvertisementInfo.BluetoothAddress)
                {
                    oldBLEAdvertisementInfo = bLEAdvertisementInfo;
                    break;
                }
            }

            if (oldBLEAdvertisementInfo == null)
            {
                DeviceCollection.Add(newBleAdvertisementInfo);
                Received?.Invoke(this, DeviceWatchEvent.Added, newBleAdvertisementInfo);
            }
            else
            {
                DeviceCollection.Remove(oldBLEAdvertisementInfo);
                DeviceCollection.Add(newBleAdvertisementInfo);
                Received?.Invoke(this, DeviceWatchEvent.Updated, newBleAdvertisementInfo);
            }
        }
Example #2
0
 public bool Equals(BLEAdvertisementInfo other)
 {
     if (other == null)
     {
         return(false);
     }
     return(BluetoothAddress == other.BluetoothAddress);
 }
Example #3
0
        public void RemoveDevice(string localBtAddress, string remove_deviceid)
        {
            BLEAdvertisementInfo toRemove = null;

            foreach (BLEAdvertisementInfo bLEAdvertisementInfo in DeviceCollection)
            {
                string deviceId = $"BluetoothLE#BluetoothLE{localBtAddress}-{bLEAdvertisementInfo.ToBtAddressString()}";

                if (remove_deviceid.Equals(deviceId))
                {
                    toRemove = bLEAdvertisementInfo;
                    break;
                }
            }

            if (toRemove != null)
            {
                DeviceCollection.Remove(toRemove);
                toRemove.Timestamp = DateTimeOffset.Now;
                Received?.Invoke(this, DeviceWatchEvent.Removed, toRemove);
            }
        }