Exemplo n.º 1
0
        private void BindDeviceTree(List <DeviceInfo> filtered)
        {
            var filteredWithParents = new List <DeviceInfo>();

            foreach (var item in filtered)
            {
                DeviceDetector.FillParents(item, allDevices, filteredWithParents);
            }
            // Fill icons.
            var classes = filteredWithParents.Select(x => x.ClassGuid).Distinct();

            // Suppress repainting the TreeView until all the objects have been created.
            DevicesTreeView.Nodes.Clear();
            TreeImageList.Images.Clear();
            foreach (var cl in classes)
            {
                var icon = DeviceDetector.GetClassIcon(cl, 16);
                if (icon != null)
                {
                    TreeImageList.Images.Add(cl.ToString(), icon.ToBitmap());
                }
            }
            DevicesTreeView.BeginUpdate();
            // Get top devices with no parent (only one device).
            var topNodes = filteredWithParents.Where(x => string.IsNullOrEmpty(x.ParentDeviceId)).ToArray();

            AddChildNodes(DevicesTreeView.Nodes, topNodes, filteredWithParents, System.Environment.MachineName);
            DevicesTreeView.EndUpdate();
            DevicesTreeView.ExpandAll();
            DeviceTreeTabPage.Text = string.Format("Device Tree [{0}]", filteredWithParents.Count);
        }
Exemplo n.º 2
0
        void UpdateGrid(bool updateDevices)
        {
            lock (updateGridLock)
            {
                if (updateDevices)
                {
                    devices    = DeviceDetector.GetDevices().ToList();
                    interfaces = DeviceDetector.GetInterfaces().ToList();
                    devices.AddRange(interfaces);
                }
                var filter = FilterTextBox.Text.Trim();
                var view   = devices;
                if (EnableFilterCheckBox.Checked && !string.IsNullOrEmpty(filter))
                {
                    view = devices.Where(x =>
                                         comp(x.ClassDescription, filter) ||
                                         comp(x.Description, filter) ||
                                         comp(x.Manufacturer, filter) ||
                                         comp(x.DeviceId, filter))
                           .ToList();
                }
                // WORKAROUND: Remove SelectionChanged event.
                DeviceDataGridView.SelectionChanged -= DeviceDataGridView_SelectionChanged;
                DeviceDataGridView.DataSource        = view;
                // WORKAROUND: Use BeginInvoke to prevent SelectionChanged firing multiple times.
                ControlsHelper.BeginInvoke(() =>
                {
                    DeviceDataGridView.SelectionChanged += DeviceDataGridView_SelectionChanged;
                    DeviceDataGridView_SelectionChanged(DeviceDataGridView, new EventArgs());
                });
                DeviceTabPage.Text = string.Format("{0} Devices on {1:yyyy-MM-dd HH:mm:ss}", view.Count, DateTime.Now);
                var dis     = devices.Where(x => string.IsNullOrEmpty(x.ParentDeviceId)).ToArray();
                var classes = devices.Select(x => x.ClassGuid).Distinct();

                // Suppress repainting the TreeView until all the objects have been created.
                DevicesTreeView.Nodes.Clear();
                TreeImageList.Images.Clear();
                foreach (var cl in classes)
                {
                    var icon = DeviceDetector.GetClassIcon(cl);
                    if (icon != null)
                    {
                        Image img = new Icon(icon, 16, 16).ToBitmap();
                        TreeImageList.Images.Add(cl.ToString(), img);
                    }
                }
                DevicesTreeView.BeginUpdate();
                foreach (DeviceInfo di in dis)
                {
                    var tn = new TreeNode(System.Environment.MachineName);
                    tn.Tag              = di;
                    tn.ImageKey         = di.ClassGuid.ToString();
                    tn.SelectedImageKey = di.ClassGuid.ToString();
                    DevicesTreeView.Nodes.Add(tn);
                    AddChildren(tn);
                }
                DevicesTreeView.EndUpdate();
                DevicesTreeView.ExpandAll();
            }
        }