Example #1
0
        private void FillUsbHub(UsbDeviceViewModel hub)
        {
            hub.TreeViewItems.Clear();

            foreach (var subhub in this.UsbHubs)
            {
                if (subhub.ParentDeviceId.Equals(hub.DeviceId, StringComparison.CurrentCultureIgnoreCase))
                {
                    hub.TreeViewItems.Add(subhub);

                    FillUsbHub(subhub);
                }
            }

            foreach (var device in this.UsbDevices)
            {
                if (device.ParentDeviceId.Equals(hub.DeviceId, StringComparison.CurrentCultureIgnoreCase))
                {
                    hub.TreeViewItems.Add(device);
                }
            }
        }
Example #2
0
        private void RefreshTree()
        {
            this.UsbTreeItems.Clear();

            var root = new UsbDeviceViewModel();

            foreach (var controller in this.UsbHostControllers)
            {
                root.TreeViewItems.Add(controller);

                controller.TreeViewItems.Clear();
                foreach (var hub in this.UsbHubs)
                {
                    if (hub.ParentDeviceId.Equals(controller.DeviceId, StringComparison.CurrentCultureIgnoreCase))
                    {
                        controller.TreeViewItems.Add(hub);

                        FillUsbHub(hub);
                    }
                }
            }

            this.UsbTreeItems.Add(root);
        }
Example #3
0
        private void Refresh(String guid, ThreadSafeObservableCollection <UsbDeviceViewModel> deviceList, UsbDeviceViewModel selectedDevice, Action <UsbDeviceViewModel> setSelectedDevice, String deviceId = null, String devicePath = null)
        {
            if (String.IsNullOrEmpty(deviceId) && String.IsNullOrEmpty(devicePath))
            {
                if (selectedDevice != null)
                {
                    deviceId = selectedDevice.DeviceId;
                }
                else if (deviceList.Count > 0)
                {
                    deviceId = deviceList[0].DeviceId;
                }
            }

            deviceList.Clear();

            UsbDevice[] usbDevices = UsbDevice.GetDevices(new Guid(guid));

            List <UsbDeviceViewModel> usbDeviceViewModels = new List <UsbDeviceViewModel>();

            foreach (UsbDevice usbDevice in usbDevices)
            {
                usbDeviceViewModels.Add(new UsbDeviceViewModel(usbDevice));
            }

            deviceList.AddRange(usbDeviceViewModels);

            if (!String.IsNullOrEmpty(deviceId))
            {
                foreach (UsbDeviceViewModel usbDeviceViewModel in deviceList)
                {
                    if (usbDeviceViewModel.DeviceId.Equals(deviceId, StringComparison.CurrentCultureIgnoreCase))
                    {
                        setSelectedDevice(usbDeviceViewModel);
                        return;
                    }
                }
            }

            if (!String.IsNullOrEmpty(devicePath))
            {
                foreach (UsbDeviceViewModel usbDeviceViewModel in deviceList)
                {
                    if (usbDeviceViewModel.DevicePath.Equals(devicePath, StringComparison.CurrentCultureIgnoreCase))
                    {
                        setSelectedDevice(usbDeviceViewModel);
                        return;
                    }
                }
            }

            if (deviceList.Count > 0)
            {
                setSelectedDevice(deviceList[0]);
            }
        }
        private void RefreshTree()
        {
            this.UsbTreeItems.Clear();

            var root = new UsbDeviceViewModel();

            foreach (var controller in this.UsbHostControllers)
            {
                root.TreeViewItems.Add(controller);

                controller.TreeViewItems.Clear();
                foreach (var hub in this.UsbHubs)
                {
                    if (hub.ParentDeviceId.Equals(controller.DeviceId, StringComparison.CurrentCultureIgnoreCase))
                    {
                        controller.TreeViewItems.Add(hub);

                        FillUsbHub(hub);
                    }
                }
            }

            this.UsbTreeItems.Add(root);
        }
        private void Refresh(String guid, ThreadSafeObservableCollection<UsbDeviceViewModel> deviceList, UsbDeviceViewModel selectedDevice, Action<UsbDeviceViewModel> setSelectedDevice, String deviceId = null, String devicePath = null)
        {
            if (String.IsNullOrEmpty(deviceId) && String.IsNullOrEmpty(devicePath))
            {
                if (selectedDevice != null)
                {
                    deviceId = selectedDevice.DeviceId;
                }
                else if (deviceList.Count > 0)
                {
                    deviceId = deviceList[0].DeviceId;
                }
            }

            deviceList.Clear();

            UsbDevice[] usbDevices = UsbDevice.GetDevices(new Guid(guid));

            List<UsbDeviceViewModel> usbDeviceViewModels = new List<UsbDeviceViewModel>();
            foreach (UsbDevice usbDevice in usbDevices)
            {
                usbDeviceViewModels.Add(new UsbDeviceViewModel(usbDevice));
            }

            deviceList.AddRange(usbDeviceViewModels);

            if (!String.IsNullOrEmpty(deviceId))
            {
                foreach (UsbDeviceViewModel usbDeviceViewModel in deviceList)
                {
                    if (usbDeviceViewModel.DeviceId.Equals(deviceId, StringComparison.CurrentCultureIgnoreCase))
                    {
                        setSelectedDevice(usbDeviceViewModel);
                        return;
                    }
                }
            }

            if (!String.IsNullOrEmpty(devicePath))
            {
                foreach (UsbDeviceViewModel usbDeviceViewModel in deviceList)
                {
                    if (usbDeviceViewModel.DevicePath.Equals(devicePath, StringComparison.CurrentCultureIgnoreCase))
                    {
                        setSelectedDevice(usbDeviceViewModel);
                        return;
                    }
                }
            }

            if (deviceList.Count > 0)
            {
                setSelectedDevice(deviceList[0]);
            }
        }
        private void FillUsbHub(UsbDeviceViewModel hub)
        {
            hub.TreeViewItems.Clear();

            foreach (var subhub in this.UsbHubs)
            {
                if (subhub.ParentDeviceId.Equals(hub.DeviceId, StringComparison.CurrentCultureIgnoreCase))
                {
                    hub.TreeViewItems.Add(subhub);

                    FillUsbHub(subhub);
                }
            }

            foreach (var device in this.UsbDevices)
            {
                if (device.ParentDeviceId.Equals(hub.DeviceId, StringComparison.CurrentCultureIgnoreCase))
                {
                    hub.TreeViewItems.Add(device);
                }
            }
        }