private void DeviceAppeared (object o, DeviceArguments args) { Device device = new Device (args); Hyena.Log.DebugFormat ("device appeared: {0}, path: {1}", device.Uuid, args.DeviceProperties.GetStringValue ("DAVolumePath")); lock (this) { // only handle devices which have a VolumePath (=MountPoint) if (!args.DeviceProperties.HasKey ("DAVolumePath")) { return; } var protocol = args.DeviceProperties.GetStringValue ("DADeviceProtocol"); IDevice new_device = null; if (!string.IsNullOrEmpty (protocol) && protocol == "USB") { new_device = new UsbVolume (args); } else { new_device = new Volume (args, null); } // avoid adding a device twice - might happen since DeviceAppeared and DeviceChanged both fire var old_device = devices.Where (v => { return v.Uuid == new_device.Uuid; }).FirstOrDefault (); if (old_device != null) { return; } if (new_device != null) { devices.Add (new_device); // Notify that a device was added (i.e. to refresh device list) DeviceAdded (this, new DeviceAddedArgs ((IDevice) new_device)); } } }
private void OnDeviceChanged(object o, DeviceArguments args) { Device device = new Device (args); Hyena.Log.DebugFormat ("device changed: {0}, path: {1}", device.Uuid, args.DeviceProperties.GetStringValue ("DAVolumePath")); lock (this) { var old_device = devices.Where (d => d.Uuid == device.Uuid).FirstOrDefault (); if (old_device != null) { // a device that was currently attached has changed // remove the device and immediately re-add it devices.Remove (old_device); var remove_handler = DeviceRemoved; if (remove_handler != null) { remove_handler (old_device, new DeviceRemovedArgs (old_device.Uuid)); } } // do not add device without a VolumePath (=MountPoint) if (!args.DeviceProperties.HasKey ("DAVolumePath")) { return; } IDevice new_device = null; var protocol = args.DeviceProperties.GetStringValue ("DADeviceProtocol"); if (!string.IsNullOrEmpty (protocol) && protocol == "USB") { new_device = new UsbVolume (args); } else { new_device = new Volume (args); } devices.Add (new_device); var added_handler = DeviceAdded; if (added_handler != null) { added_handler (this, new DeviceAddedArgs ((IDevice)new_device)); } } }