Example #1
0
    public int?DetectExitCode(AppBundleInformation appBundleInfo, IReadableLog log)
    {
        StreamReader reader;

        try
        {
            reader = log.GetReader();
        }
        catch (FileNotFoundException e)
        {
            throw new Exception("Failed to detect application's exit code. The log file was empty / not found at " + e.FileName);
        }

        using (reader)
            while (!reader.EndOfStream)
            {
                if (reader.ReadLine() is string line &&
                    IsSignalLine(appBundleInfo, line) is Match match && match.Success &&
                    int.TryParse(match.Groups["exitCode"].Value, out var exitCode))
                {
                    return(exitCode);
                }
            }

        return(null);
    }
Example #2
0
        private async Task <int> GetPidFromRunLog()
        {
            int pid = -1;

            using var reader = _runLog.GetReader(); // diposed at the end of the method, which is what we want
            if (reader.Peek() == -1)
            {
                // Empty file! If the app never connected to our listener, it probably never launched
                if (!_listener.ConnectedTask.IsCompleted || !_listener.ConnectedTask.Result)
                {
                    _launchFailure = true;
                }
            }
            else
            {
                while (!reader.EndOfStream)
                {
                    var line = await reader.ReadLineAsync();

                    if (line == null)
                    {
                        continue;
                    }

                    if (line.StartsWith("Application launched. PID = ", StringComparison.Ordinal))
                    {
                        var pidstr = line.Substring("Application launched. PID = ".Length);
                        if (!int.TryParse(pidstr, out pid))
                        {
                            _mainLog.WriteLine("Could not parse pid: {0}", pidstr);
                        }
                    }
                    else if (line.Contains("Xamarin.Hosting: Launched ") && line.Contains(" with pid "))
                    {
                        var pidstr = line.Substring(line.LastIndexOf(' '));
                        if (!int.TryParse(pidstr, out pid))
                        {
                            _mainLog.WriteLine("Could not parse pid: {0}", pidstr);
                        }
                    }
                    else if (line.Contains("error MT1008"))
                    {
                        _launchFailure = true;
                    }
                }
            }

            return(pid);
        }
Example #3
0
        private void GetCrashReason(int pid, IReadableLog crashLog, out string?crashReason)
        {
            crashReason           = null;
            using var crashReader = crashLog.GetReader(); // dispose when we leave the method
            var text = crashReader.ReadToEnd();

            var reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(text), new XmlDictionaryReaderQuotas());
            var doc    = new XmlDocument();

            doc.Load(reader);
            foreach (XmlNode?node in doc.SelectNodes($"/root/processes/item[pid = '" + pid + "']"))
            {
                Console.WriteLine(node?.InnerXml);
                Console.WriteLine(node?.SelectSingleNode("reason")?.InnerText);
                crashReason = node?.SelectSingleNode("reason")?.InnerText;
            }
        }
Example #4
0
        private async Task <(int pid, bool launchFailure)> GetPidFromRunLog()
        {
            (int pid, bool launchFailure)pidData = (-1, true);
            using var reader = _runLog.GetReader(); // diposed at the end of the method, which is what we want
            if (reader.Peek() == -1)
            {
                // empty file! we definetly had a launch error in this case
                pidData.launchFailure = true;
            }
            else
            {
                while (!reader.EndOfStream)
                {
                    var line = await reader.ReadLineAsync();

                    if (line == null)
                    {
                        continue;
                    }

                    if (line.StartsWith("Application launched. PID = ", StringComparison.Ordinal))
                    {
                        var pidstr = line.Substring("Application launched. PID = ".Length);
                        if (!int.TryParse(pidstr, out pidData.pid))
                        {
                            _mainLog.WriteLine("Could not parse pid: {0}", pidstr);
                        }
                    }
                    else if (line.Contains("Xamarin.Hosting: Launched ") && line.Contains(" with pid "))
                    {
                        var pidstr = line.Substring(line.LastIndexOf(' '));
                        if (!int.TryParse(pidstr, out pidData.pid))
                        {
                            _mainLog.WriteLine("Could not parse pid: {0}", pidstr);
                        }
                    }
                    else if (line.Contains("error MT1008"))
                    {
                        pidData.launchFailure = true;
                    }
                }
            }
            return(pidData);
        }
Example #5
0
        public int DetectExitCode(AppBundleInformation appBundleInfo, IReadableLog systemLog)
        {
            using var reader = systemLog.GetReader();
            while (!reader.EndOfStream)
            {
                var line = reader.ReadLine();

                if (IsSignalLine(appBundleInfo, line))
                {
                    var match = ExitCodeRegex.Match(line);

                    if (match.Success && int.TryParse(match.Captures.First().Value, out var exitCode))
                    {
                        return(exitCode);
                    }
                }
            }

            return(0);
        }
Example #6
0
        public int DetectExitCode(AppBundleInformation appBundleInfo, IReadableLog systemLog)
        {
            using var reader = systemLog.GetReader();
            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();

                // This will be improved when we find out it differes for new iOS versions
                if (line.Contains("UIKitApplication:") && line.Contains(appBundleInfo.AppName) && line.Contains("Service exited with abnormal code"))
                {
                    var regex = new Regex(" (\\-?[0-9]+)$");
                    var match = regex.Match(line);

                    if (match.Success && int.TryParse(match.Captures.First().Value, out var exitCode))
                    {
                        return(exitCode);
                    }
                }
            }

            return(0);
        }