예제 #1
0
        private async void Watcher_DeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
        {
            // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
            await dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                // Watcher may have stopped while we were waiting for our chance to run.
                if (IsWatcherStarted(sender))
                {
                    // Find the corresponding DeviceInformation in the collection and remove it
                    foreach (DeviceInformationDisplay deviceInfoDisp in resultCollection)
                    {
                        if (deviceInfoDisp.Id == deviceInfoUpdate.Id)
                        {
                            resultCollection.Remove(deviceInfoDisp);
                            break;
                        }
                    }

                    RaiseDeviceChanged(sender, deviceInfoUpdate.Id);
                }
            });
        }
예제 #2
0
        private async void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate deviceInfo)
        {
            await Task.Run(() =>
            {
                lock (this)
                {
                    Console.WriteLine(string.Format("Removed {0}{1}", deviceInfo.Id, ""));

                    // Protect against race condition if the task runs after the app stopped the deviceWatcher.
                    if (sender == deviceWatcher)
                    {
                        // 更新
                        var blueDisp = FindBluetoothLEDeviceDisplay(deviceInfo.Id);
                        if (blueDisp != null)
                        {
                            Devices.Remove(blueDisp);
                            DevicesDisplay.Renew(Devices);
                        }
                    }
                }
            });
        }
예제 #3
0
        async void watcher_Updated(Windows.Devices.Enumeration.DeviceWatcher sender, DeviceInformationUpdate devUpdate)
        {
            int count2 = 0;

            foreach (DeviceInformation deviceInterface in interfaces)
            {
                if (count2 < count)
                {
                    if (interfaces[count2].Id == devUpdate.Id)
                    {
                        //Update the element.
                        interfaces[count2].Update(devUpdate);
                    }
                }
                count2 += 1;
            }
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                OutputText.Text = "Enumeration updated: Device added ";
                DisplayDeviceInterfaceArray();
            });
        }
예제 #4
0
        private void OnBleDeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate deviceInformationUpdate)
        {
            var ignoreContinuation = this.dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (sender == this.bleDeviceWatcher && this.allBleDevices.ContainsKey(deviceInformationUpdate.Id))
                {
                    bool removeDevice = true;

                    for (int i = 0; i < this.model.AllSupportedBleDevices.Count; ++i)
                    {
                        if (this.model.AllSupportedBleDevices[i].Id == deviceInformationUpdate.Id)
                        {
                            if (this.model.AllSupportedBleDevices[i].CanBeDeletedByWatcher)
                            {
                                if (this.model.WirelessLineSensorDeviceModel.Id == deviceInformationUpdate.Id)
                                {
                                    this.model.WirelessLineSensorDeviceModel.DisconnectCommand.Execute(this.model.WirelessLineSensorDeviceModel);
                                }
                                this.model.AllSupportedBleDevices.RemoveAt(i);
                                if (this.model.SelectedBleDevice == null || this.model.SelectedBleDevice.Id == deviceInformationUpdate.Id)
                                {
                                    this.model.SelectedBleDevice = this.model.AllSupportedBleDevices.Count <= 0 ? null : this.model.AllSupportedBleDevices[0];
                                }
                            }
                            else
                            {
                                removeDevice = false;
                            }
                            break;
                        }
                    }
                    if (removeDevice)
                    {
                        this.allBleDevices.Remove(deviceInformationUpdate.Id);
                    }
                }
            });
        }
예제 #5
0
        private async void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
        {
            await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
            {
                lock (this)
                {
                    if (sender == deviceWatcher)
                    {
                        BluetoothLEDeviceDisplay bleDeviceDisplay = FindBluetoothLEDeviceDisplay(deviceInfoUpdate.Id);
                        if (bleDeviceDisplay != null)
                        {
                            // Device is already being displayed - update UX.
                            bleDeviceDisplay.Update(deviceInfoUpdate);
                            return;
                        }

                        DeviceInformation deviceInfo = FindUnknownDevices(deviceInfoUpdate.Id);
                        if (deviceInfo != null)
                        {
                            deviceInfo.Update(deviceInfoUpdate);
                            // If device has been updated with a friendly name it's no longer unknown.
                            if (deviceInfo.Name != String.Empty)
                            {
                                dict.Add(deviceInfo.Name, deviceInfo);
                                DeviceList.Items.Add(new System.Windows.Controls.ListViewItem {
                                    Content = deviceInfo.Name
                                });
                                KnownDevices.Add(new BluetoothLEDeviceDisplay(deviceInfo));
                                deviceQueue.Enqueue(deviceInfo.Name);
                                UnknownDevices.Remove(deviceInfo);
                                ConnectDevice();
                            }
                        }
                        Update_DeviceList();
                    }
                }
            }));
        }
예제 #6
0
 private async void Watcher_DeviceUpdated(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
 {
     // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
     await dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
     {
         // Watcher may have stopped while we were waiting for our chance to run.
         if (IsWatcherStarted(sender))
         {
             // Find the corresponding updated DeviceInformation in the collection and pass the update object
             // to the Update method of the existing DeviceInformation. This automatically updates the object
             // for us.
             foreach (DeviceInformationDisplay deviceInfoDisp in resultCollection)
             {
                 if (deviceInfoDisp.Id == deviceInfoUpdate.Id)
                 {
                     deviceInfoDisp.Update(deviceInfoUpdate);
                     RaiseDeviceChanged(sender, deviceInfoUpdate.Id);
                     break;
                 }
             }
         }
     });
 }
예제 #7
0
 private async void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate deviceInfo)
 {
     if (!deviceInfo.Properties.ContainsKey("System.Devices.Aep.SignalStrength") || deviceInfo.Properties["System.Devices.Aep.SignalStrength"] == null)
     {
         return;
     }
     // We must update the collection on the UI thread because the collection is databound to a UI element.
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (this)
         {
             int rssi = Math.Abs((int)deviceInfo.Properties["System.Devices.Aep.SignalStrength"]);
             if (deviceInfo.Id == DeviceIdToTrack3)
             {
                 Track3(deviceInfo.Id, rssi);
             }
             if (deviceInfo.Id == DeviceIdToTrack5)
             {
                 Track5(deviceInfo.Id, rssi);
             }
         }
     });
 }
        private async void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
        {
            // Collections bound to the UI are updated in the UI thread.
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // Find the device for the given id and remove it from the list.
                foreach (DeviceInformation device in this.devices)
                {
                    if (device.Id == deviceInfoUpdate.Id)
                    {
                        this.devices.Remove(device);
                        break;
                    }
                }

                if (audioPlaybackConnections.ContainsKey(deviceInfoUpdate.Id))
                {
                    AudioPlaybackConnection connectionToRemove = audioPlaybackConnections[deviceInfoUpdate.Id];
                    connectionToRemove.Dispose();
                    this.audioPlaybackConnections.Remove(deviceInfoUpdate.Id);
                }
            });
        }
예제 #9
0
        private void OnDeviceUpdated(DeviceWatcher sender, DeviceInformationUpdate update)
        {
            object value;

            if (!update.Properties.TryGetValue("System.Devices.InterfaceEnabled", out value))
            {
                return;
            }

            lock (this.devices)
            {
                if ((bool)value)
                {
                    this.devices.Add(update.Id);
                }
                else
                {
                    this.devices.Remove(update.Id);
                }

                this.isCameraAvailable = this.devices.Count > 0;
            }
        }
예제 #10
0
        /// <summary>Fired when the device is changed</summary>
        /// <param name="sender"></param>
        /// <param name="updateInfo"></param>
        private void DevWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate updateInfo)
        {
            this.log.Info("DevWatcher_Updated", "------------------------------ START -----------------------------------------------------");
            this.log.Info("DevWatcher_Updated", () => string.Format("***** {0}", updateInfo.Id));
            WrapErr.ToErrReport(9999, () => {
                BLE_PropertiesUpdateDataModel dm = updateInfo.CreatePropertiesUpdateData();
                this.DeviceUpdated?.Invoke(this, dm);

                //this.devic

                //if (updateInfo.Properties != null) {
                //    foreach (var p in updateInfo.Properties) {
                //        string value = "Unhandled";
                //        switch (p.Key) {
                //            case "System.Devices.Aep.ContainerId":
                //            case "Id":
                //            case "System.ItemNameDisplay": // *
                //            case "System.Devices.Icon":
                //            case "System.Devices.GlyphIcon":
                //                value = (string)p.Value;
                //                break;
                //            case "System.Devices.Aep.IsPaired": // *
                //            case "System.Devices.Aep.IsConnected":
                //            case "System.Devices.Aep.IsConnectable":
                //            case "System.Devices.Aep.CanPair": // *
                //                value = string.Format("{0}", (bool)p.Value);
                //                break;
                //                // "System.Devices.Icon"
                //                // "System.Devices.GlyphIcon"

                //        }
                //        this.log.Info("DevWatcher_Updated", () => string.Format("    Property:{0}  Value:{1}", p.Key, value));
                //    }
                //}
            });
            this.log.Info("DevWatcher_Updated", "------------------------------ END -----------------------------------------------------");
        }
예제 #11
0
 private async void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
 {
     await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
     {
         lock (this)
         {
             if (sender == deviceWatcher)
             {
                 // Find the corresponding DeviceInformation in the collection and remove it.
                 BluetoothLEDeviceDisplay bleDeviceDisplay = FindBluetoothLEDeviceDisplay(deviceInfoUpdate.Id);
                 DeviceInformation deviceInfo = FindUnknownDevices(deviceInfoUpdate.Id);
                 if (bleDeviceDisplay != null)
                 {
                     KnownDevices.Remove(bleDeviceDisplay);
                     dict.Remove(bleDeviceDisplay.Name);
                     if (deviceQueue.Count > 0)
                     {
                         while (deviceQueue.Contains(bleDeviceDisplay.Name))
                         {
                             var ck = deviceQueue.Dequeue();
                             if (!ck.Equals(bleDeviceDisplay.Name))
                             {
                                 deviceQueue.Enqueue(ck);
                             }
                         }
                     }
                 }
                 if (deviceInfo != null)
                 {
                     UnknownDevices.Remove(deviceInfo);
                 }
                 Update_DeviceList();
             }
         }
     }));
 }
예제 #12
0
 private async void BluetoothWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (Locker)
         {
             try
             {
                 if (BluetoothDeviceCollection != null)
                 {
                     foreach (var Bluetooth in from BluetoothList Bluetooth in BluetoothDeviceCollection
                              where Bluetooth.Id == args.Id
                              select Bluetooth)
                     {
                         Bluetooth.Update(args);
                     }
                 }
             }
             catch (Exception)
             {
             }
         }
     });
 }
예제 #13
0
        private async void Watcher_Updated(DeviceWatcher sender, DeviceInformationUpdate args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                //If enumeration completes, update UI and transition watcher to the stopped state
                rootPage.NotifyUser("Watcher received an update for a listed device", NotifyType.StatusMessage);

                //Go through our list of device until you find the DeviceInformation object that is updated.
                DeviceInformation updateDevice = null;
                foreach (DeviceInformation currentDevice in this.castingDevicesList.Items)
                {
                    if (currentDevice.Id == args.Id)
                    {
                        updateDevice = currentDevice;
                        break;
                    }
                }
                //Update the DeviceInformation object.
                if (updateDevice != null)
                {
                    updateDevice.Update(args);
                }
            });
        }
예제 #14
0
        private void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
        {
            if (sender != deviceWatcher)
            {
                return;
            }

            DeviceInformation di_torem = null;

            foreach (DeviceInformation di in devices)
            {
                if (di.Id == deviceInfoUpdate.Id)
                {
                    di_torem = di;
                    break;
                }
            }

            if (di_torem != null)
            {
                devices.Remove(di_torem);
            }
            VerboseDebug("Lost device " + deviceInfoUpdate.Id);
        }
예제 #15
0
 private void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
 {
     if (sender == deviceWatcher)
     {
         this.Dispatcher.Invoke(async() =>
         {
             BluetoothLEDeviceDisplay bleDeviceDisplay = FindBluetoothLEDeviceDisplay(deviceInfoUpdate.Id);
             if (bleDeviceDisplay != null)
             {
                 bleDeviceDisplay.Update(deviceInfoUpdate);
                 return;
             }
             else
             {
                 var deviceInfo = await DeviceInformation.CreateFromIdAsync(deviceInfoUpdate.Id);
                 if ((bool)deviceInfo.Properties["System.Devices.Aep.Bluetooth.Le.IsConnectable"])
                 {
                     bleDeviceDisplay = new BluetoothLEDeviceDisplay(deviceInfo);
                     KnownDevices.Add(bleDeviceDisplay);
                 }
             }
         });
     }
 }
예제 #16
0
        private async void BluetoothDeviceWatcher_UpdatedAsync(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
        {
            // We must update the collection on the UI thread because the collection is databound to a UI element.
            // use Microsoft.Toolkit.Uwp.Helpers extensions
            await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
            {
                // Protect against race condition if the task runs after the app stopped the deviceWatcher.
                if (sender == bluetoothDeviceWatcher)
                {
                    var bluetoothDevice = FindKnownBluetoothDevice(deviceInfoUpdate.Id);
                    if (bluetoothDevice != null)
                    {
                        // Device is already being displayed - update UI.
                        bluetoothDevice.Update(deviceInfoUpdate);
                        if (!FilterBluetoothDevice(bluetoothDevice.DeviceInformation))
                        {
                            KnownBluetoothDevices.Remove(bluetoothDevice);
                            UnknownBluetoothDevices.Add(bluetoothDevice.DeviceInformation);
                        }
                        return;
                    }

                    DeviceInformation deviceInfo = FindUnknownBluetoothDevice(deviceInfoUpdate.Id);
                    if (deviceInfo != null)
                    {
                        deviceInfo.Update(deviceInfoUpdate);
                        // If device has been updated
                        if (FilterBluetoothDevice(deviceInfo))
                        {
                            KnownBluetoothDevices.Add(new BluetoothDeviceItem(deviceInfo));
                            UnknownBluetoothDevices.Remove(deviceInfo);
                        }
                    }
                }
            });
        }
예제 #17
0
        private async void HIDDeviceUpdated(DeviceWatcher sender, DeviceInformationUpdate args)
        {
            DeviceInformation device_info = await DeviceInformation.CreateFromIdAsync(args.Id);

            // Do not let the background task starve, check if we are paired then connect to the keyboard
            if (device_info.Name.Contains("ANNE"))
            {
                if (device_info.IsEnabled)
                {
                    FindKeyboard();
                }
                else
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                    {
                        KeyboardDeviceInformation        = null;
                        connectionStatusLabel.Text       = "Not Connected";
                        connectionStatusLabel.Foreground = new SolidColorBrush(Colors.Red);
                        LightSyncButton.IsEnabled        = false;
                        LayoutSyncButton.IsEnabled       = false;
                    });
                }
            }
        }
예제 #18
0
        private void Watcher_DeviceUpdated(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
        {
            // Watcher may have stopped while we were waiting for our chance to run.
            if (IsWatcherStarted(sender))
            {
                // Find the corresponding updated DeviceInformation in the collection and pass the update object
                // to the Update method of the existing DeviceInformation. This automatically updates the object
                // for us.
                foreach (DeviceInformation deviceInfo in resultCollection)
                {
                    if (deviceInfo.Id.Equals(deviceInfoUpdate.Id))
                    {
                        bool oldIsPaired = deviceInfo.Pairing.IsPaired;
                        deviceInfo.Update(deviceInfoUpdate);
                        bool newIsPaired = deviceInfo.Pairing.IsPaired;

                        if (IsPairedOnly && (oldIsPaired != newIsPaired))
                        {
                            if (newIsPaired)
                            {
                                RaiseDeviceChanged(sender, DeviceWatchEvent.Added, deviceInfo);
                            }
                            else
                            {
                                RaiseDeviceChanged(sender, DeviceWatchEvent.Removed, deviceInfo);
                            }
                        }
                        else
                        {
                            RaiseDeviceChanged(sender, DeviceWatchEvent.Updated, deviceInfo);
                        }
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Executes when a device is updated
        /// </summary>
        /// <param name="sender">The device watcher.</param>
        /// <param name="deviceInfoUpdate">The update device information.</param>
        private async void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
        {
            if (sender == _deviceWatcher)
            {
                ObservableBluetoothLEDevice device = null;

                device = BluetoothLeDevices.FirstOrDefault(i => i.DeviceInfo.Id == deviceInfoUpdate.Id);

                if (device != null)
                {
                    await device.UpdateAsync(deviceInfoUpdate);
                }

                if (device == null)
                {
                    if (_readerWriterLockSlim.TryEnterWriteLock(TimeSpan.FromSeconds(2)))
                    {
                        var unusedDevice = _unusedDevices.FirstOrDefault(i => i.Id == deviceInfoUpdate.Id);

                        if (unusedDevice != null)
                        {
                            _unusedDevices.Remove(unusedDevice);
                            unusedDevice.Update(deviceInfoUpdate);
                        }

                        _readerWriterLockSlim.ExitWriteLock();

                        // The update to the unknown device means we should move it to the Bluetooth LE Device collection.
                        if (unusedDevice != null)
                        {
                            await AddDeviceToList(unusedDevice);
                        }
                    }
                }
            }
        }
예제 #20
0
        /// <summary>
        /// Called when a BLE device is removed from the system.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="deviceInfoUpdate"></param>
        private void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
        {
            lock (this)
            {
                Console.WriteLine(System.String.Format("Removed {0}, {1}", deviceInfoUpdate.Id, ""));

                //Making sure that we are processing device from the current device watcher.
                if (sender == deviceWatcher)
                {
                    //Find the corresponding DeviceInformation in the collection and remove it.
                    LogitowDevice logitowDevice = GetDiscoveredLogitowDevice(deviceInfoUpdate.Id);
                    if (logitowDevice != null)
                    {
                        discoveredDevices.Remove(logitowDevice);
                        eventListener.OnDeviceLost(logitowDevice.deviceInfo.Id);
                    }
                    DeviceInformation unknownDevice = GetUnknownDevice(deviceInfoUpdate.Id);
                    if (unknownDevice != null)
                    {
                        unknownDevices.Remove(unknownDevice);
                    }
                }
            }
        }
예제 #21
0
        private async void DeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
        {
            var drives = DriveInfo.GetDrives().Select(x => x.Name);

            foreach (var drive in Drives)
            {
                if (drive.Type == DriveType.VirtualDrive || drives.Contains(drive.tag))
                {
                    continue;
                }

                // Update the collection on the ui-thread.
                try
                {
                    CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Drives.Remove(drive); });
                }
                catch (Exception e)
                {
                    // Ui-Thread not yet created.
                    Drives.Remove(drive);
                }
                return;
            }
        }
예제 #22
0
        private async void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
        {
            // We must update the collection on the UI thread because the collection is databound to a UI element.
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                lock (this)
                {
                    // log(String.Format("Updated {0}{1}", deviceInfoUpdate.Id, ""));

                    // Protect against race condition if the task runs after the app stopped the deviceWatcher.
                    if (sender == deviceWatcher)
                    {
                        foreach (BLEDevice b in KnownDevices)
                        {
                            if (b.id == deviceInfoUpdate.Id)
                            {
                                b.di.Update(deviceInfoUpdate);
                                b.Name = b.di.Name;
                            }
                        }
                    }
                }
            });
        }
예제 #23
0
 private async void BluetoothWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (SyncRootProvider.SyncRoot)
         {
             try
             {
                 if (BluetoothDeviceCollection != null)
                 {
                     for (int i = 0; i < BluetoothDeviceCollection.Count; i++)
                     {
                         if (BluetoothDeviceCollection[i].Id == args.Id)
                         {
                             BluetoothDeviceCollection.RemoveAt(i);
                             i--;
                         }
                     }
                 }
             }
             catch (Exception) { }
         }
     });
 }
예제 #24
0
 private void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate args)
 {
 }
 private void Watcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     //throw new NotImplementedException();
 }
예제 #26
0
 private void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     Removed?.Invoke(sender, args);
 }
 private void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     System.Diagnostics.Debug.WriteLine("Update:" + args.Id);
 }
예제 #28
0
 private void Watcher_Removed(DeviceWatcher sender, DeviceInformationUpdate info)
 {
     Log("Removed: " + info.Id);
 }
 public void Update(DeviceInformationUpdate deviceInfoUpdate)
 {
     deviceInfo.Update(deviceInfoUpdate);
     UpdateGlyphBitmapImage();
 }
예제 #30
0
 private void DeviceUpdated(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     Debug.WriteLine("Devices updated");
 }