Esempio n. 1
0
        public static bool IsDefinitionMatch(FilterDeviceDefinition filterDevice, ConnectedDeviceDefinition actualDevice)
        {
            if (actualDevice == null)
            {
                throw new ArgumentNullException(nameof(actualDevice));
            }

            if (filterDevice == null)
            {
                return(true);
            }

            var vendorIdPasses   = !filterDevice.VendorId.HasValue || filterDevice.VendorId == actualDevice.VendorId;
            var productIdPasses  = !filterDevice.ProductId.HasValue || filterDevice.ProductId == actualDevice.ProductId;
            var deviceTypePasses = !filterDevice.DeviceType.HasValue || filterDevice.DeviceType == actualDevice.DeviceType;
            var usagePagePasses  = !filterDevice.UsagePage.HasValue || filterDevice.UsagePage == actualDevice.UsagePage;

            var returnValue =
                vendorIdPasses &&
                productIdPasses &&
                deviceTypePasses &&
                usagePagePasses;

            return(returnValue);
        }
Esempio n. 2
0
 public static bool IsDefinitionMatch(FilterDeviceDefinition filterDevice, ConnectedDeviceDefinition actualDevice)
 {
     return
         ((!filterDevice.VendorId.HasValue || filterDevice.VendorId == actualDevice.VendorId) &&
          (!filterDevice.ProductId.HasValue || filterDevice.ProductId == actualDevice.ProductId) &&
          (!filterDevice.DeviceType.HasValue || filterDevice.DeviceType == actualDevice.DeviceType) &&
          (!filterDevice.UsagePage.HasValue || filterDevice.UsagePage == actualDevice.UsagePage));
 }
Esempio n. 3
0
        public Task <IDevice> GetDeviceAsync(ConnectedDeviceDefinition connectedDeviceDefinition, CancellationToken cancellationToken = default)
        {
            _logger.LogInformation("Getting device for connected device {deviceDefinition}", connectedDeviceDefinition);

            return(connectedDeviceDefinition == null ?
                   throw new ArgumentNullException(nameof(connectedDeviceDefinition)) :
                   _getDevice(connectedDeviceDefinition, cancellationToken));
        }
Esempio n. 4
0
        public IDevice GetDevice(ConnectedDeviceDefinition deviceDefinition)
        {
            if (!int.TryParse(deviceDefinition.DeviceId, out var deviceId))
            {
                throw new Exception($"The device Id '{deviceDefinition.DeviceId}' is not a valid integer");
            }

            return(new AndroidUsbDevice(UsbManager, Context, deviceId));
        }
Esempio n. 5
0
        //TODO: Duplicate code here...
        public IDevice GetDevice(ConnectedDeviceDefinition connectedDeviceDefinition)
        {
            foreach (var deviceFactory in DeviceFactories)
            {
                if (connectedDeviceDefinition.DeviceType.HasValue && (deviceFactory.DeviceType != connectedDeviceDefinition.DeviceType)) continue;
                return deviceFactory.GetDevice(connectedDeviceDefinition);
            }

            throw new System.Exception("Couldn't get a device");
        }
Esempio n. 6
0
        //TODO: Duplicate code here...
        public IDevice GetDevice(ConnectedDeviceDefinition connectedDeviceDefinition)
        {
            if (connectedDeviceDefinition == null)
            {
                throw new ArgumentNullException(nameof(connectedDeviceDefinition));
            }

            foreach (var deviceFactory in DeviceFactories.Where(deviceFactory => !connectedDeviceDefinition.DeviceType.HasValue || (deviceFactory.DeviceType == connectedDeviceDefinition.DeviceType)))
            {
                return(deviceFactory.GetDevice(connectedDeviceDefinition));
            }

            throw new DeviceException(Messages.ErrorMessageCouldntGetDevice);
        }
Esempio n. 7
0
        public static bool IsDefinitionMatch(FilterDeviceDefinition filterDevice, ConnectedDeviceDefinition actualDevice)
        {
            if (filterDevice == null) return true;

            var vendorIdPasses = !filterDevice.VendorId.HasValue || filterDevice.VendorId == actualDevice.VendorId;
            var productIdPasses = !filterDevice.ProductId.HasValue || filterDevice.ProductId == actualDevice.ProductId;
            var deviceTypePasses = !filterDevice.DeviceType.HasValue || filterDevice.DeviceType == actualDevice.DeviceType;
            var usagePagePasses = !filterDevice.UsagePage.HasValue || filterDevice.UsagePage == actualDevice.UsagePage;

            var returnValue = 
                vendorIdPasses &&
                productIdPasses &&
                deviceTypePasses &&
                usagePagePasses;

            return returnValue;
        }
Esempio n. 8
0
 public async Task <IDevice> GetDeviceAsync(ConnectedDeviceDefinition connectedDeviceDefinition, CancellationToken cancellationToken = default)
 => connectedDeviceDefinition == null ? throw new ArgumentNullException(nameof(connectedDeviceDefinition)) :
       await(await DeviceFactories.FirstOrDefaultAsync(f => f.SupportsDeviceAsync(connectedDeviceDefinition, cancellationToken), cancellationToken).ConfigureAwait(false)
Esempio n. 9
0
 public async Task <bool> SupportsDeviceAsync(ConnectedDeviceDefinition connectedDeviceDefinition, CancellationToken cancellationToken = default) => await DeviceFactories.FirstOrDefaultAsync(async d => await d.SupportsDeviceAsync(connectedDeviceDefinition, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false) != null;
Esempio n. 10
0
 public Task <bool> SupportsDeviceAsync(ConnectedDeviceDefinition connectedDeviceDefinition, CancellationToken cancellationToken = default)
 {
     _logger.LogInformation("Checking if the factory supports this connected device. Device Definition: {deviceDefinition}", connectedDeviceDefinition);
     return(_supportsDevice(connectedDeviceDefinition, cancellationToken));
 }