// stream read/write ====================================================== internal void Read(BinaryReader br) { devices.Clear(); Int32 count = br.ReadInt32(); for (Int32 i = 0; i < count; ++i) { Device device = new Device(); device.Read(br); devices.Add(device); } }
// scanning ======================================================= protected void ScanDevices(ArrayList devices, String name, String[] properties) { String className = CommonStrings.WIN32_ + name; ManagementClass mc = new ManagementClass(className); ManagementObjectCollection objects = mc.GetInstances(); foreach (ManagementObject mo in objects) { Device device = new Device(); device.Name = name; ScanDevice(device, mo, properties); devices.Add(device); } }
protected bool IsDeviceEqual(Device d1, Device d2) { bool result = false; if (d1.Name == d2.Name) { result = true; foreach (DictionaryEntry de in d1.Properties) { Object name = de.Key; Object value = de.Value; if (!value.Equals(d2.Properties[name])) { result = false; break; } } } return result; }
protected void ScanDevice(Device device, ManagementObject mo, String[] properties) { for (int i = 0; i < properties.Length; ++i) { String name = properties[i]; String value = String.Empty; Object obj = mo[name]; if (obj != null) { value = obj.ToString(); } device.Properties[name] = value; } }
protected Device FindMatchingDevice(ArrayList devices, Device device) { Device same = null; foreach (Device d in devices) { if ( IsDeviceEqual(device, d) ) { same = d; break; } } return same; }