public void EnumerateUSB_HasOnlyUSBDevices() { var disks = new UDisks(); var devices = disks.EnumerateDeviceOnInterface("usb"); Assert.Greater(devices.Count(), 0); // Check that the devices don't exist on any interface other than usb foreach (var device in devices) { var uDiskDevice = new UDiskDevice(device); string iface = uDiskDevice.GetProperty("DriveConnectionInterface"); Assert.AreEqual("usb", iface); } }
public void EnumerateUSB_HasOnlyPartitions() { var disks = new UDisks(); var devices = disks.EnumerateDeviceOnInterface("usb"); Assert.Greater(devices.Count(), 0); foreach (var device in devices) { var uDiskDevice = new UDiskDevice(device); Assert.AreEqual("True", uDiskDevice.GetProperty("DeviceIsPartition"), String.Format("Device {0} does not have a partition", device) ); } }
public IEnumerable<string> EnumerateDeviceOnInterface(string onInterface) { var devices = Interface.EnumerateDevices(); foreach (var device in devices) { var uDiskDevice = new UDiskDevice(device); string iface = uDiskDevice.GetProperty("DriveConnectionInterface"); string partition = uDiskDevice.GetProperty("DeviceIsPartition"); if (iface == onInterface && uDiskDevice.IsMounted) { yield return device; } } }
public IEnumerable <string> EnumerateDeviceOnInterface(string onInterface) { var devices = Interface.EnumerateDevices(); foreach (var device in devices) { var uDiskDevice = new UDiskDevice(device); string iface = uDiskDevice.GetProperty("DriveConnectionInterface"); string partition = uDiskDevice.GetProperty("DeviceIsPartition"); if (iface == onInterface && uDiskDevice.IsMounted) { yield return(device); } } }
/// <summary> /// Enumerate the devices on the given interface. /// </summary> /// <remarks> /// DBus is a bit flakey and subject to random timing problems. We need to /// ignore any exceptions that it might throw. This method is typically /// called on a timer loop so that any information we lose will probably /// be available in a few seconds. (See https://jira.sil.org/browse/WS-226 /// and a number of other JIRA issues that record exceptions at this /// point in the code.) /// Note that yield cannot appear in a try body of a try-catch expression. /// </remarks> public IEnumerable <string> EnumerateDeviceOnInterface(string onInterface) { IEnumerable <string> devices; try { devices = Interface.EnumerateDevices(); } catch (Exception ex) { Palaso.Reporting.Logger.Init(); Palaso.Reporting.Logger.WriteEvent("Ignoring exception from DBus while enumerating devices: {0}", ex.Message); devices = new List <string>(); } foreach (var device in devices) { string iface = null; bool isMounted = false; try { var uDiskDevice = new UDiskDevice(device); iface = uDiskDevice.GetProperty("DriveConnectionInterface"); isMounted = uDiskDevice.IsMounted; } catch (Exception ex) { Palaso.Reporting.Logger.Init(); Palaso.Reporting.Logger.WriteEvent("Ignoring exception from DBus while scanning for {0} devices: {1}", onInterface, ex.Message); continue; } if (iface == onInterface && isMounted) { yield return(device); } } }
/// <summary> /// Enumerate the devices on the given interface. /// </summary> /// <remarks> /// DBus is a bit flakey and subject to random timing problems. We need to /// ignore any exceptions that it might throw. This method is typically /// called on a timer loop so that any information we lose will probably /// be available in a few seconds. (See https://jira.sil.org/browse/WS-226 /// and a number of other JIRA issues that record exceptions at this /// point in the code.) /// Note that yield cannot appear in a try body of a try-catch expression. /// </remarks> public IEnumerable<string> EnumerateDeviceOnInterface(string onInterface) { IEnumerable<string> devices; try { devices = Interface.EnumerateDevices(); } catch (Exception ex) { Palaso.Reporting.Logger.Init(); Palaso.Reporting.Logger.WriteEvent("Ignoring exception from DBus while enumerating devices: {0}", ex.Message); devices = new List<string>(); } foreach (var device in devices) { string iface = null; bool isMounted = false; try { var uDiskDevice = new UDiskDevice(device); iface = uDiskDevice.GetProperty("DriveConnectionInterface"); isMounted = uDiskDevice.IsMounted; } catch (Exception ex) { Palaso.Reporting.Logger.Init(); Palaso.Reporting.Logger.WriteEvent("Ignoring exception from DBus while scanning for {0} devices: {1}", onInterface, ex.Message); continue; } if (iface == onInterface && isMounted) { yield return device; } } }
public UsbDriveInfoUDisks(string device) { _device = new UDiskDevice(device); }