public CodeCoverageTable LoadCoverage() { var report = GetTestReports() .First() .GetFiles() .FirstOrDefault(x => x.FullName.ToLower().EndsWith("annotation.axml")); var table = PluginAnnotationTable.Load(report.FullName); var annotationTable = table.Items.First(); var calculator = new CodeCoverageCalculator(annotationTable); return(calculator.CalculateCoverage(false)); }
public void OpenFile(string SourceFile) { SelectedTab = -1; if (SourceFile == null) { var dialog = new OpenFileDialog() { Filter = "Report Files (*.rxml Files)|*.rxml|Vuln Files (*.pxml)|*.pxml|All|*.*" }; if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } SourceFile = dialog.FileName; } var info = new FileInfo(SourceFile); ReportDir = info.Directory.FullName; if (info.Extension == ".rxml") { var reportFiles = ReportFile.Load(SourceFile); Func <string, string> getFilePath = x => info.DirectoryName + "\\" + new FileInfo(x).Name; var staticAnalysisReport = reportFiles .SingleOrDefault(x => x.Name == "Static analysis"); if (staticAnalysisReport != null) { var alerts = StaticAnalysisFileAlertCollection .Load(getFilePath(staticAnalysisReport.Filename)) .SelectMany(x => x.Alerts.Select(y => new { x.Filename, Alert = y, })) .OrderBy(x => x.Alert.Name); if (alerts.Any()) { StaticAnalysisVisibility = Visibility.Visible; StaticAnalysisAlerts = alerts; } } var vulnReport = reportFiles .SingleOrDefault(x => new FileInfo(x.Filename).Extension == ".pxml"); if (vulnReport != null) { VulnerabilityTabVisibility = Visibility.Visible; SelectedTab = 0; var alerts = ScanAlertCollection.Load(getFilePath(vulnReport.Filename)); if (alerts == null) { return; } CreateAlertViewModels(alerts); } else { VulnerabilityTabVisibility = Visibility.Collapsed; } var inputMap = reportFiles .SingleOrDefault(x => x.Name == "Input Map Report"); if (inputMap != null) { var inputMapFile = inputMap.Filename; InputTable = ApplicationMap .FromXml(getFilePath(inputMapFile)).Pages .ToDictionary( x => string.Format( "{0} ({1})", x.Page, x.SuperglobalNameCollectionTable.Sum(y => y.Value.Count())), x => new Dictionary <string, List <object> >() { { "GET", x.Get.Select(y => (object)(new { Key = y })).ToList() }, { "POST", x.Post.Select(y => (object)(new { Key = y })).ToList() }, { "REQUEST", x.Request.Select(y => (object)(new { Key = y })).ToList() }, { "Files", x.Files.Select(y => (object)(new { Key = y })).ToList() }, { "Cookies", x.Cookie.Select(y => (object)(new { Key = y })).ToList() } } .Where(y => y.Value.Any()) .ToDictionary( y => string.Format("{0} ({1})", y.Key, y.Value.Count()), y => y.Value)); InputMapVisibility = Visibility.Visible; if (SelectedTab == -1) { SelectedTab = 1; } } var coverageReport = reportFiles .SingleOrDefault(x => x.Name == "Annotation"); if (coverageReport != null) { CoverageVisibility = Visibility.Visible; if (SelectedTab == -1) { SelectedTab = 2; } var annotationFile = Path.Combine(info.DirectoryName, coverageReport.Filename); var pluginTable = PluginAnnotationTable.Load(annotationFile); CoverageTables = pluginTable.Items .Select(x => new CodeCoverageCalculator(x).CalculateCoverage(false)) .ToArray(); } else { CoverageVisibility = Visibility.Collapsed; } if (SelectedTab != -1) { DynamicAnalysisVisibility = Visibility.Visible; SelectedRootTab = 0; } else { SelectedRootTab = 1; } } else { var alerts = ScanAlertCollection.Load(SourceFile); if (alerts == null) { return; } DynamicAnalysisVisibility = Visibility.Visible; SelectedRootTab = 0; VulnerabilityTabVisibility = Visibility.Visible; InputMapVisibility = Visibility.Collapsed; CoverageVisibility = Visibility.Collapsed; SelectedTab = 0; CreateAlertViewModels(alerts); } }