Пример #1
0
        protected override async Task <ExitCode> InvokeInternal(ILogger logger)
        {
            var processManager  = new ProcessManager(mlaunchPath: _arguments.MlaunchPath);
            var deviceLoader    = new HardwareDeviceLoader(processManager);
            var simulatorLoader = new SimulatorLoader(processManager);
            var log             = new MemoryLog(); // do we really want to log this?

            var mlaunchLog = new MemoryLog {
                Timestamp = false
            };

            ProcessExecutionResult result;

            try
            {
                result = await processManager.ExecuteCommandAsync(new MlaunchArguments(new MlaunchVersionArgument()), new MemoryLog(), mlaunchLog, new MemoryLog(), TimeSpan.FromSeconds(10));
            }
            catch (Exception e)
            {
                logger.LogError($"Failed to get mlaunch version info:{Environment.NewLine}{e}");
                return(ExitCode.GENERAL_FAILURE);
            }

            if (!result.Succeeded)
            {
                logger.LogError($"Failed to get mlaunch version info:{Environment.NewLine}{mlaunchLog}");
                return(ExitCode.GENERAL_FAILURE);
            }

            // build the required data, then depending on the format print out
            var info = new SystemInfo(
                machineName: Environment.MachineName,
                oSName: "Mac OS X",
                oSVersion: Darwin.GetVersion() ?? "",
                oSPlatform: "Darwin",
                xcodePath: processManager.XcodeRoot,
                xcodeVersion: processManager.XcodeVersion.ToString(),
                mlaunchPath: processManager.MlaunchPath,
                mlaunchVersion: mlaunchLog.ToString().Trim());

            try
            {
                await simulatorLoader.LoadDevices(log);
            }
            catch (Exception e)
            {
                logger.LogError($"Failed to load simulators:{Environment.NewLine}{e}");
                logger.LogInformation($"Execution log:{Environment.NewLine}{log}");
                return(ExitCode.GENERAL_FAILURE);
            }

            foreach (var sim in simulatorLoader.AvailableDevices)
            {
                info.Simulators.Add(new DeviceInfo(
                                        name: sim.Name,
                                        uDID: sim.UDID,
                                        type: sim.SimDeviceType.Remove(0, SimulatorPrefix.Length).Replace('-', ' '),
                                        oSVersion: sim.OSVersion));
            }

            try
            {
                await deviceLoader.LoadDevices(log);
            }
            catch (Exception e)
            {
                logger.LogError($"Failed to load connected devices:{Environment.NewLine}{e}");
                logger.LogInformation($"Execution log:{Environment.NewLine}{log}");
                return(ExitCode.GENERAL_FAILURE);
            }

            foreach (var dev in deviceLoader.ConnectedDevices)
            {
                info.Devices.Add(new DeviceInfo(
                                     name: dev.Name,
                                     uDID: dev.DeviceIdentifier,
                                     type: $"{dev.DeviceClass} {dev.DevicePlatform}",
                                     oSVersion: dev.OSVersion));
            }

            if (_arguments.UseJson)
            {
                await AsJson(info);
            }
            else
            {
                AsText(info);
            }

            return(ExitCode.SUCCESS);
        }