Exemplo n.º 1
0
		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)
				);
			}
		}
Exemplo n.º 2
0
		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);
			}
		}
Exemplo n.º 3
0
        /// <summary>
        /// Enumerate the mounted filesystems on the given interface, returning a set of their
        /// mount points.
        /// </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)
            {
                Logger.Init();
                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)
                {
                    Logger.Init();
                    Logger.WriteEvent("Ignoring exception from DBus while scanning for {0} devices: {1}",
                                      onInterface, ex.Message);
                    continue;
                }
                if (iface == onInterface && isMounted)
                {
                    yield return(device);
                }
            }
        }
Exemplo n.º 4
0
		/// <summary>
		/// Enumerate the mounted filesystems on the given interface, returning a set of their
		/// mount points.
		/// </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)
			{
				Logger.Init();
				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)
				{
					Logger.Init();
					Logger.WriteEvent("Ignoring exception from DBus while scanning for {0} devices: {1}",
						onInterface, ex.Message);
					continue;
				}
				if (iface == onInterface && isMounted)
				{
					yield return device;
				}
			}
		}
Exemplo n.º 5
0
		public UsbDriveInfoUDisks(string device)
		{
			_device = new UDiskDevice(device);
		}
Exemplo n.º 6
0
 public UsbDriveInfoUDisks(string device)
 {
     _device = new UDiskDevice(device);
 }