// Test if no crashes are there there is only ever one state in several runs private string CreateCrashReportsFolder(CrashType type) { string crashReportPath = Path.Combine(TemporaryDirectory, type.GetDescription()); Directory.CreateDirectory(crashReportPath); return(crashReportPath); }
internal List <CrashReport> GetCrashReports(CrashType type, DateTime?from = null, DateTime?to = null, string filter = null) { if (from.HasValue) { from = NormalizeDateTime(from.Value); } if (to.HasValue) { to = NormalizeDateTime(to.Value); } var context = m_crashReportTypeContext.FirstOrDefault(f => f.Type == type); if (context.CrashReportFolderPath != null && context.CrashReportExntension != null) { var crashReportsFolder = context.CrashReportFolderPath; var crashReportExtension = context.CrashReportExntension; var filePattern = $"{type.GetDescription()}_*.{crashReportExtension}"; var crashReports = Directory.EnumerateFiles(crashReportsFolder, filePattern, SearchOption.AllDirectories); var reports = crashReports.Where(r => !r.Contains(ScrapedCrashReportFileNameSuffix)).Select(r => new CrashReport() { FileName = r, Type = type, CrashDate = ParseDateTimeFromFileName(Path.GetFileName(r)), Content = File.ReadAllText(r) }); reports = (from.HasValue || to.HasValue) ? reports.Where(report => { if (from.HasValue && to.HasValue) { return(report.CrashDate >= from.Value && report.CrashDate <= to.Value); } else if (!from.HasValue && to.HasValue) { return(report.CrashDate <= to.Value); } else { return(report.CrashDate >= from.Value); } }) : reports; return(string.IsNullOrEmpty(filter) ? reports.ToList() : reports.Where(report => report.Content.Contains(filter)).ToList()); } return(new List <CrashReport>()); }
private void CreateCrashReports(string crashReportPath, CrashType type, int count, DateTime date, string contents) { var extension = type == CrashType.Kernel ? "panic" : "crash"; for (int i = 0; i < count; i++) { var fileName = date.ToString(DateTimeFormatter); var suffix = i < 2 ? $"-{i + 1}" : ""; // Create some test files e.g. BuildXL_2018-11-16-102125-1_SomeHostName.crash var reportPath = Path.Combine(crashReportPath, $"{type.GetDescription()}_{fileName}{suffix}_SomeHostName.{extension}"); File.WriteAllText(reportPath, contents); date = date.AddMinutes(i); } }