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); }
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)); }
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; }
public Task <IEnumerable <ConnectedDeviceDefinition> > GetConnectedDeviceDefinitionsAsync(FilterDeviceDefinition deviceDefinition) { return(Task.Run <IEnumerable <ConnectedDeviceDefinition> >(() => { //TODO: Get more details about the device. return UsbManager.DeviceList.Select(kvp => kvp.Value).Where(d => deviceDefinition.VendorId == d.VendorId && deviceDefinition.ProductId == d.ProductId).Select(GetAndroidDeviceDefinition).ToList(); })); }
public async Task <IEnumerable <ConnectedDeviceDefinition> > GetConnectedDeviceDefinitionsAsync(FilterDeviceDefinition deviceDefinition) { if (DeviceFactories.Count == 0) { throw new DeviceFactoriesNotRegisteredException(); } var retVal = new List <ConnectedDeviceDefinition>(); foreach (var deviceFactory in DeviceFactories) { var connectedDeviceDefinitions = await deviceFactory.GetConnectedDeviceDefinitionsAsync(deviceDefinition); foreach (var connectedDeviceDefinition in connectedDeviceDefinitions) { //Don't add the same device twice //Note: this probably won't cause issues where there is no DeviceId, but funny behaviour is probably going on when there isn't anyway... if (retVal.Select(d => d.DeviceId).Contains(connectedDeviceDefinition.DeviceId)) { continue; } retVal.Add(connectedDeviceDefinition); } } return(retVal); }
public async Task <IEnumerable <ConnectedDeviceDefinition> > GetConnectedDeviceDefinitionsAsync(FilterDeviceDefinition deviceDefinition) { var retVal = new List <ConnectedDeviceDefinition>(); foreach (var deviceFactory in DeviceFactories) { retVal.AddRange(await deviceFactory.GetConnectedDeviceDefinitionsAsync(deviceDefinition)); } return(retVal); }