示例#1
0
        async Task <bool> FindSimulatorAsync()
        {
            if (simulators != null)
            {
                return(true);
            }

            var sims = new Simulators()
            {
                Harness = Harness,
            };
            await sims.LoadAsync(Logs.Create("simulator-list.log", "Simulator list"));

            simulators = await sims.FindAsync(Target, main_log);

            return(simulators != null);
        }
示例#2
0
        void FindSimulator()
        {
            if (simulators != null)
            {
                return;
            }

            string [] simulator_devicetypes;
            string    simulator_runtime;

            switch (Target)
            {
            case "ios-simulator-32":
                simulator_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.iPhone-5" };
                simulator_runtime     = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-');
                break;

            case "ios-simulator-64":
                simulator_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.iPhone-5s" };
                simulator_runtime     = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-');
                break;

            case "ios-simulator":
                simulator_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.iPhone-5" };
                simulator_runtime     = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-');
                break;

            case "tvos-simulator":
                simulator_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p" };
                simulator_runtime     = "com.apple.CoreSimulator.SimRuntime.tvOS-" + Xamarin.SdkVersions.TVOS.Replace('.', '-');
                break;

            case "watchos-simulator":
                simulator_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm", "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-2-38mm" };
                simulator_runtime     = "com.apple.CoreSimulator.SimRuntime.watchOS-" + Xamarin.SdkVersions.WatchOS.Replace('.', '-');
                break;

            default:
                throw new Exception(string.Format("Unknown simulator target: {0}", Harness.Target));
            }

            var sims = new Simulators()
            {
                Harness = Harness,
            };

            Task.Run(async() =>
            {
                await sims.LoadAsync(Logs.CreateStream(LogDirectory, "simulator-list.log", "Simulator list"));
            }).Wait();

            var       devices   = sims.AvailableDevices.Where((SimDevice v) => v.SimRuntime == simulator_runtime && simulator_devicetypes.Contains(v.SimDeviceType));
            SimDevice candidate = null;

            simulators = null;
            foreach (var device in devices)
            {
                var data           = device;
                var secondaryData  = (SimDevice)null;
                var nodeCompanions = sims.AvailableDevicePairs.Where((SimDevicePair v) => v.Companion == device.UDID);
                var nodeGizmos     = sims.AvailableDevicePairs.Where((SimDevicePair v) => v.Gizmo == device.UDID);

                if (nodeCompanions.Any())
                {
                    var gizmo_udid = nodeCompanions.First().Gizmo;
                    var node       = sims.AvailableDevices.Where((SimDevice v) => v.UDID == gizmo_udid);
                    secondaryData = node.First();
                }
                else if (nodeGizmos.Any())
                {
                    var companion_udid = nodeGizmos.First().Companion;
                    var node           = sims.AvailableDevices.Where((SimDevice v) => v.UDID == companion_udid);
                    secondaryData = node.First();
                }
                if (secondaryData != null)
                {
                    simulators = new SimDevice [] { data, secondaryData };
                    break;
                }
                else
                {
                    candidate = data;
                }
            }
            if (simulators == null)
            {
                if (candidate == null)
                {
                    throw new Exception($"Could not find simulator for runtime={simulator_runtime} and device type={string.Join (";", simulator_devicetypes)}.");
                }
                simulators = new SimDevice [] { candidate };
            }

            if (simulators == null)
            {
                throw new Exception("Could not find simulator");
            }

            main_log.WriteLine("Found simulator: {0} {1}", simulators [0].Name, simulators [0].UDID);
            if (simulators.Length > 1)
            {
                main_log.WriteLine("Found companion simulator: {0} {1}", simulators [1].Name, simulators [1].UDID);
            }
        }