Exemplo n.º 1
0
        public Task LoadAsync(Log log, bool extra_data = false, bool removed_locked = false)
        {
            if (loaded)
            {
                return(Task.FromResult(true));
            }
            loaded = true;

            Task.Run(async() =>
            {
                var tmpfile = Path.GetTempFileName();
                try {
                    using (var process = new Process()) {
                        process.StartInfo.FileName  = Harness.MlaunchPath;
                        process.StartInfo.Arguments = string.Format("--sdkroot {0} --listdev={1} {2} --output-format=xml", Harness.XcodeRoot, tmpfile, extra_data ? "--list-extra-data" : string.Empty);
                        log.WriteLine("Launching {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
                        var rv = await process.RunAsync(log, false);
                        if (!rv.Succeeded)
                        {
                            throw new Exception("Failed to list devices.");
                        }
                        log.WriteLine("Result:");
                        log.WriteLine(File.ReadAllText(tmpfile));

                        var doc = new XmlDocument();
                        doc.LoadWithoutNetworkAccess(tmpfile);

                        foreach (XmlNode dev in doc.SelectNodes("/MTouch/Device"))
                        {
                            Device d = new Device
                            {
                                DeviceIdentifier    = dev.SelectSingleNode("DeviceIdentifier")?.InnerText,
                                DeviceClass         = dev.SelectSingleNode("DeviceClass")?.InnerText,
                                CompanionIdentifier = dev.SelectSingleNode("CompanionIdentifier")?.InnerText,
                                Name           = dev.SelectSingleNode("Name")?.InnerText,
                                BuildVersion   = dev.SelectSingleNode("BuildVersion")?.InnerText,
                                ProductVersion = dev.SelectSingleNode("ProductVersion")?.InnerText,
                                ProductType    = dev.SelectSingleNode("ProductType")?.InnerText,
                            };
                            bool.TryParse(dev.SelectSingleNode("IsLocked")?.InnerText, out d.IsLocked);
                            if (removed_locked && d.IsLocked)
                            {
                                continue;
                            }
                            connected_devices.Add(d);
                        }
                    }
                } finally {
                    connected_devices.SetCompleted();
                    File.Delete(tmpfile);
                }
            });

            return(Task.FromResult(true));
        }
Exemplo n.º 2
0
        public async Task LoadAsync(Log log, bool extra_data = false, bool removed_locked = false, bool force = false)
        {
            if (loaded)
            {
                if (!force)
                {
                    return;
                }
                connected_devices.Reset();
            }

            loaded = true;

            await Task.Run(async() =>
            {
                var tmpfile = Path.GetTempFileName();
                try {
                    using (var process = new Process()) {
                        process.StartInfo.FileName  = Harness.MlaunchPath;
                        process.StartInfo.Arguments = string.Format("--sdkroot {0} --listdev={1} {2} --output-format=xml", Harness.XcodeRoot, tmpfile, extra_data ? "--list-extra-data" : string.Empty);
                        log.WriteLine("Launching {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
                        var rv = await process.RunAsync(log, false, timeout: TimeSpan.FromSeconds(120));
                        if (!rv.Succeeded)
                        {
                            throw new Exception("Failed to list devices.");
                        }
                        log.WriteLine("Result:");
                        log.WriteLine(File.ReadAllText(tmpfile));

                        var doc = new XmlDocument();
                        doc.LoadWithoutNetworkAccess(tmpfile);

                        foreach (XmlNode dev in doc.SelectNodes("/MTouch/Device"))
                        {
                            var usable = dev.SelectSingleNode("IsUsableForDebugging")?.InnerText;
                            Device d   = new Device
                            {
                                DeviceIdentifier    = dev.SelectSingleNode("DeviceIdentifier")?.InnerText,
                                DeviceClass         = dev.SelectSingleNode("DeviceClass")?.InnerText,
                                CompanionIdentifier = dev.SelectSingleNode("CompanionIdentifier")?.InnerText,
                                Name                 = dev.SelectSingleNode("Name")?.InnerText,
                                BuildVersion         = dev.SelectSingleNode("BuildVersion")?.InnerText,
                                ProductVersion       = dev.SelectSingleNode("ProductVersion")?.InnerText,
                                ProductType          = dev.SelectSingleNode("ProductType")?.InnerText,
                                InterfaceType        = dev.SelectSingleNode("InterfaceType")?.InnerText,
                                IsUsableForDebugging = usable == null ? (bool?)null : ((bool?)(usable == "True")),
                            };
                            bool.TryParse(dev.SelectSingleNode("IsLocked")?.InnerText, out d.IsLocked);
                            if (removed_locked && d.IsLocked)
                            {
                                log.WriteLine($"Skipping device {d.Name} ({d.DeviceIdentifier}) because it's locked.");
                                continue;
                            }
                            if (d.IsUsableForDebugging.HasValue && !d.IsUsableForDebugging.Value)
                            {
                                log.WriteLine($"Skipping device {d.Name} ({d.DeviceIdentifier}) because it's not usable for debugging.");
                                continue;
                            }
                            connected_devices.Add(d);
                        }
                    }
                } finally {
                    connected_devices.SetCompleted();
                    File.Delete(tmpfile);
                }
            });
        }