Beispiel #1
0
 public DeviceEvent(Int32 eventType, Win32UsbControllerDevice win32UsbControllerDevice)
 {
     this.Time = DateTime.Now;
     this.EventType = eventType;
     this.Vid = win32UsbControllerDevice.Vid;
     this.Pid = win32UsbControllerDevice.Pid;
     this.HubAndPort = Helpers.MakeHubAndPort(win32UsbControllerDevice.Hub, win32UsbControllerDevice.Port);
     this.DeviceId = win32UsbControllerDevice.DeviceId;
     this.ControllerId = win32UsbControllerDevice.ControllerId;
 }
 public Win32UsbControllerDeviceEventArgs(Win32UsbControllerDevice win32UsbControllerDevice)
 {
     this.Device = win32UsbControllerDevice;
 }
        private Win32UsbControllerDevice GetDevice(ManagementBaseObject managementObject)
        {
            try
            {
                Win32UsbControllerDevice win32UsbControllerDevice = new Win32UsbControllerDevice();

                try
                {
                    String dependent = managementObject.GetPropertyValue("Dependent").ToString();
                    win32UsbControllerDevice.DeviceId = this.ExtractSeviceId(dependent);
                }
                catch (Exception ex)
                {
                }

                try
                {
                    String antecedent = managementObject.GetPropertyValue("Antecedent").ToString();
                    win32UsbControllerDevice.ControllerId = this.ExtractSeviceId(antecedent);
                }
                catch (Exception ex)
                {
                }

                try
                {
                    String locationInformation = this.GetLocationInformation(win32UsbControllerDevice.DeviceId);

                    Int32 hubIndex = locationInformation.IndexOf("HUB_#", StringComparison.OrdinalIgnoreCase);
                    Int32 portIndex = locationInformation.IndexOf("PORT_#", StringComparison.OrdinalIgnoreCase);

                    if ((hubIndex < 0) || (portIndex < 0))
                    {
                        throw new Exception("Wrong location information format");
                    }

                    win32UsbControllerDevice.Hub = locationInformation.Substring(hubIndex + 5, 4);
                    win32UsbControllerDevice.Port = locationInformation.Substring(portIndex + 6, 4);
                }
                catch (Exception ex)
                {
                }

                try
                {
                    Int32 vidIndex = win32UsbControllerDevice.DeviceId.IndexOf("VID", StringComparison.OrdinalIgnoreCase);
                    Int32 pidIndex = win32UsbControllerDevice.DeviceId.IndexOf("PID", StringComparison.OrdinalIgnoreCase);

                    if ((vidIndex < 0) || (pidIndex < 0))
                    {
                        throw new Exception("Wrong device ID format");
                    }

                    win32UsbControllerDevice.Vid = win32UsbControllerDevice.DeviceId.Substring(vidIndex + 4, 4);
                    win32UsbControllerDevice.Pid = win32UsbControllerDevice.DeviceId.Substring(pidIndex + 4, 4);
                }
                catch (Exception ex)
                {
                }

                return win32UsbControllerDevice;
            }
            catch (Exception ex)
            {
            }

            return null;
        }
 private void RefreshOnWmiEvent(Win32UsbControllerDevice win32UsbControllerDevice)
 {
     if (this.RefreshListOnWmiEvents && !String.IsNullOrEmpty(win32UsbControllerDevice.DeviceId) && (win32UsbControllerDevice.DeviceId.IndexOf("&MI_", StringComparison.CurrentCultureIgnoreCase) < 0))
     {
         this.Refresh(this.SelectConnectedDevice ? win32UsbControllerDevice.DeviceId : null);
     }
 }