Exemple #1
0
 public void CloseAll()
 {
     foreach (ICameraDevice connectedDevice in ConnectedDevices.Where(connectedDevice => connectedDevice.IsConnected))
     {
         connectedDevice.Close();
     }
 }
        public Device FindCompanionDevice(Log log, Device device)
        {
            var companion = ConnectedDevices.Where((v) => v.DeviceIdentifier == device.CompanionIdentifier);

            if (companion.Count() == 0)
            {
                throw new Exception($"Could not find the companion device for '{device.Name}'");
            }

            if (companion.Count() > 1)
            {
                log.WriteLine("Found {0} companion devices for {1}?!?", companion.Count(), device.Name);
            }

            return(companion.First());
        }
        public async Task <IHardwareDevice> FindCompanionDevice(ILog log, IHardwareDevice device)
        {
            await LoadDevices(log, false, false);

            var companion = ConnectedDevices.Where((v) => v.DeviceIdentifier == device.CompanionIdentifier);

            if (companion.Count() == 0)
            {
                throw new Exception($"Could not find the companion device for '{device.Name}'");
            }

            if (companion.Count() > 1)
            {
                log.WriteLine("Found {0} companion devices for {1}?!?", companion.Count(), device.Name);
            }

            return(companion.First());
        }
        public async Task <IHardwareDevice> FindDevice(RunMode runMode, ILog log, bool includeLocked, bool force)
        {
            DeviceClass [] deviceClasses = runMode switch
            {
                RunMode.iOS => new [] { DeviceClass.iPhone, DeviceClass.iPad, DeviceClass.iPod },
                RunMode.WatchOS => new [] { DeviceClass.Watch },
                RunMode.TvOS => new [] { DeviceClass.AppleTV },                // Untested
                _ => throw new ArgumentException(nameof(runMode)),
            };

            await LoadDevices(log, false, false);

            IEnumerable <IHardwareDevice> compatibleDevices = ConnectedDevices.Where(v => deviceClasses.Contains(v.DeviceClass) && v.IsUsableForDebugging != false);
            IHardwareDevice device;

            if (compatibleDevices.Count() == 0)
            {
                throw new NoDeviceFoundException($"Could not find any applicable devices with device class(es): {string.Join (", ", deviceClasses)}");
            }
            else if (compatibleDevices.Count() > 1)
            {
                device = compatibleDevices
                         .OrderBy(dev => Version.TryParse(dev.ProductVersion, out Version v) ? v : new Version())
                         .First();

                log.WriteLine("Found {0} devices for device class(es) '{1}': '{2}'. Selected: '{3}' (because it has the lowest version).",
                              compatibleDevices.Count(),
                              string.Join("', '", deviceClasses),
                              string.Join("', '", compatibleDevices.Select((v) => v.Name).ToArray()),
                              device.Name);
            }
            else
            {
                device = compatibleDevices.First();
            }

            return(device);
        }