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); } }
public bool Equals(BLEAdvertisementInfo other) { if (other == null) { return(false); } return(BluetoothAddress == other.BluetoothAddress); }
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); } }