示例#1
0
        void CheckAll()
        {
            // Make sure that issues are checked in correct order.
            var issues = IssueList.OrderBy(x => x.OrderId).ToArray();

            foreach (var issue in issues)
            {
                if (IsDisposing)
                {
                    return;
                }
                issue.Check();
                if (IsDisposing)
                {
                    return;
                }
                // If issue is critical then...
                if (issue.IsEnabled && issue.Severity.HasValue && issue.Severity.Value >= IssueSeverity.Critical)
                {
                    // Skip checking other issues.
                    break;
                }
            }
            // Assign result to property, because results will be read on a different i.e. main Thread.
            CriticalIssuesCount = IssueList.Count(x => x.IsEnabled && x.Severity.HasValue && x.Severity.Value >= IssueSeverity.Critical);
            ModerateIssuesCount = IssueList.Count(x => x.IsEnabled && x.Severity.HasValue && x.Severity.Value >= IssueSeverity.Moderate);
            var ev = CheckCompleted;

            if (ev != null)
            {
                CheckCompleted(this, new EventArgs());
            }
        }
示例#2
0
        private bool ConvertData(ref string fileContent, string path, AppSettings setting, int index)
        {
            Regex reg = setting.ReportFileStructureRegex;

            MatchCollection result = reg.Matches(fileContent);

            if (result.Count == 0)
            {
                Console.WriteLine("Can't parse file: {0}", path);
                return(false);
            }
            var type        = result[0].Groups["crashtype"].Value.Trim();
            var appcode     = result[0].Groups["appcode"].Value.Trim();
            var Datetime    = result[0].Groups["datetime"].Value.Trim().Split(',');
            var versioncode = result[0].Groups["versioncode"].Value.Trim();
            var versionname = result[0].Groups["versionname"].Value.Trim();
            var devicemodel = result[0].Groups["devicemodel"].Value.Trim();
            var devicename  = result[0].Groups["devicename"].Value.Trim();
            var devicebrand = result[0].Groups["devicebrand"].Value.Trim();
            var apilevel    = result[0].Groups["apilevel"].Value.Trim();
            var architec    = result[0].Groups["architecture"].Value.Trim();
            var lines       = result[0].Groups["stacktrace"].Value.Trim().Split('\n');
            var folderName  = Path.GetFileName(Path.GetDirectoryName(path));
            var datetime    = new DateTime();

            if (type != "NATIVE CRASH" && type != "JAVA CRASH")
            {
                Console.WriteLine("Not a report file: {0}", path);
                return(false);
            }
            //Parse DateTime
            if (Datetime.Length > 0)
            {
                string[] regexs      = { "dd-MM-yyyy", "MMM dd", "MMM d" };
                string   st_datetime = Datetime[0].Trim();
                foreach (var regex in regexs)
                {
                    if (DateTime.TryParseExact(st_datetime, regex, null, System.Globalization.DateTimeStyles.None, out datetime))
                    {
                        break;
                    }
                }

                if (Datetime.Length > 1)
                {
                    string[] regexs2      = { "hh:mm tt", "h:mm tt" };
                    string   st_datetime2 = Datetime[1].Trim();

                    foreach (var regex in regexs2)
                    {
                        if (DateTime.TryParseExact(st_datetime2, regex, null, System.Globalization.DateTimeStyles.None, out DateTime clocktime))
                        {
                            datetime = datetime.AddHours(clocktime.Hour);
                            datetime = datetime.AddMinutes(clocktime.Minute);
                            break;
                        }
                    }
                }
            }

            int.TryParse(apilevel, out int APIlevel);

            CrashData data = new CrashData(path)
            {
                CrashType = type == "NATIVE CRASH" ? CrashType.NATIVE : type == "JAVA CRASH" ? CrashType.JAVA : CrashType.NONE,

                AppCode     = appcode,
                DateTime    = datetime,
                VersionCode = versioncode,
                VersionName = versionname,
                DeviceModel = devicemodel,
                DeviceName  = devicename,
                DeviceBrand = devicebrand,
                APILevel    = APIlevel
            };

            switch (architec.Trim())
            {
            case "armeabi-v8":
                data.architecture = Architecture.arm64_v8a;
                break;

            case "armeabi-v7a":
                data.architecture = Architecture.armeabi_v7a;
                break;

            case "x86":
                data.architecture = Architecture.x86;
                break;

            case "x86_64":
                data.architecture = Architecture.x86_64;
                break;

            case "N/A":
            default:
                data.architecture = Architecture.Unknow;
                break;
            }
            if (data.CrashType == CrashType.NATIVE)
            {
                // Find where is backtrace?
                int backtraceBeginLineIndex = 0;
                foreach (string line in lines)
                {
                    if (line == "backtrace:" || line == "Stacktrace:") //Stacktrace is new version
                    {
                        break;
                    }
                    backtraceBeginLineIndex++;
                }
                // process backtrace:
                int numlineBacktrace = lines.Count() - backtraceBeginLineIndex - 1;

                string[] backtraceData = new string[numlineBacktrace];
                for (int i = 0; i < numlineBacktrace; i++)
                {
                    string currentLine = lines[i + backtraceBeginLineIndex + 1];
                    //string finalCurrentLine = currentLine;
                    //if (currentLine.Length > 0 && setting.IsRemoveSOPath) // Clear SO Path
                    //{

                    //     Regex regex = setting.SoPathRegex;
                    //     Match resultSoPathRegex = regex.Match(currentLine);

                    //     if (resultSoPathRegex != Match.Empty)
                    //     {
                    //         finalCurrentLine = currentLine.Remove(resultSoPathRegex.Index, resultSoPathRegex.Length);
                    //     }

                    //}
                    backtraceData[i] = currentLine;
                }
                //Check issue and add to list
                //Get AddressString
                string addressString = "";
                //Check is the line match with crash address
                //Regex rgx = new Regex(@"^  #\d|[0-999]  pc $");
                foreach (string line in backtraceData)
                {
                    string[] splitLine = line.Split(' ');
                    if (splitLine.Count() > 6 && splitLine[4].Equals("pc"))
                    {
                        addressString += splitLine[5];
                    }
                }
                int  hashCode   = addressString.GetHashCode();
                bool isNewIssue = true;

                foreach (var issue in IssueList)
                {
                    if (issue.AddressHashCode == hashCode && issue.FolderName == folderName)
                    {
                        data.IssueID = issue.ID;

                        issue.DeviceIndex.Add(index);

                        isNewIssue = false;
                        break;
                    }
                }
                if (isNewIssue)
                {
                    CrashReport issuedata = new CrashReport
                    {
                        AddressHashCode = hashCode,
                        ID         = IssueList.Count(),
                        FolderName = folderName,
                        CrashType  = CrashType.NATIVE
                    };
                    issuedata.DeviceIndex.Add(index);
                    issuedata.SetStackTraceLines(backtraceData);

                    foreach (var line in issuedata.Stacktracelines) // Get issue name
                    {
                        if (!String.IsNullOrEmpty(line.Function))
                        {
                            issuedata.Name = line.Function;
                            break;
                        }
                    }
                    if (String.IsNullOrEmpty(issuedata.Name))
                    {
                        foreach (var line in issuedata.Stacktracelines) // Get issue name
                        {
                            if (!String.IsNullOrEmpty(line.SOPath))
                            {
                                if (line.SOPath.Contains(".apk"))
                                {
                                    issuedata.Name = line.SOPath.Substring(line.SOPath.LastIndexOf('/') + 1);
                                    break;
                                }
                                else if (line.SOPath.Contains(".so"))
                                {
                                    issuedata.Name = line.SOPath.Substring(line.SOPath.LastIndexOf('/') + 1);
                                    break;
                                }
                            }
                        }
                    }
                    IssueList.Add(issuedata);
                    data.IssueID = issuedata.ID;
                }
            }    // end native crash
            else // Java Crash
            {
                int backtraceBeginLine = 0;

                foreach (var line in lines)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        backtraceBeginLine++;
                    }
                    else
                    {
                        break;
                    }
                }

                if (backtraceBeginLine >= lines.Count())
                {
                    Console.WriteLine("Not found backtrace in: {0}", path);
                    data.IssueID = -1;
                }
                else
                {
                    // process backtrace:
                    int      numlineBacktrace = lines.Count() - backtraceBeginLine - 1;
                    string[] backtraceData    = new string[numlineBacktrace];
                    for (int i = 0; i < numlineBacktrace; i++)
                    {
                        backtraceData[i] = lines[i + backtraceBeginLine];
                    }
                    //Check issue and add to list
                    //Get AddressString
                    string addressString = backtraceData[0] + backtraceData[1] + backtraceData[2] + backtraceData[numlineBacktrace - 1];
                    int    hashCode      = addressString.GetHashCode();
                    bool   isNewIssue    = true;

                    foreach (var issue in IssueList)
                    {
                        if (issue.AddressHashCode == hashCode && issue.FolderName == folderName)
                        {
                            data.IssueID = issue.ID;

                            issue.DeviceIndex.Add(index);

                            isNewIssue = false;
                            break;
                        }
                    }
                    if (isNewIssue)
                    {
                        CrashReport issuedata = new CrashReport
                        {
                            Name            = backtraceData[0],
                            AddressHashCode = hashCode,
                            ID         = IssueList.Count(),
                            FolderName = folderName,
                            CrashType  = CrashType.JAVA
                        };
                        issuedata.DeviceIndex.Add(index);
                        issuedata.SetStackTraceLines(backtraceData);
                        IssueList.Add(issuedata);
                        data.IssueID = issuedata.ID;
                    }
                }
            }
            ReportLoaded++;
            CrashDataRaw[index] = data;
            return(true);
        }