public override TableDefinition Content(ReportData reportData, Dictionary <string, string> options) { string metricId = options.GetOption("METRIC"); bool firstLoop = true; var rowData = new List <string>(); int cntRow = 1; Application[] _allApps = reportData.Applications; foreach (Application _app in _allApps) { try { Snapshot _snapshot = _app.Snapshots.OrderByDescending(_ => _.Annotation.Date.DateSnapShot).First(); if (_snapshot == null) { continue; } SimpleResult res = MetricsUtility.GetMetricNameAndResult(reportData, _snapshot, metricId, null, null, false); if (res == null) { continue; } if (firstLoop) { rowData.Add(" "); rowData.Add(res.name); firstLoop = false; } cntRow++; rowData.Add(_app.Name); rowData.Add(res.result?.ToString()); } catch (Exception ex) { LogHelper.Instance.LogInfo(ex.Message); LogHelper.Instance.LogInfo(Labels.NoSnapshot); } } TableDefinition resultTable = new TableDefinition { HasRowHeaders = true, HasColumnHeaders = false, NbRows = cntRow, NbColumns = 2, Data = rowData, GraphOptions = null }; return(resultTable); }
public override TableDefinition Content(ReportData reportData, Dictionary <string, string> options) { List <string> rowData = new List <string>(); List <CellAttributes> cellProps = new List <CellAttributes>(); int cellidx = 0; // cellProps will contains the properties of the cell (background color) linked to the data by position in the list stored with cellidx. string ruleId = options.GetOption("ID", "7788"); const string bcId = "60017"; int nbLimitTop = options.GetIntOption("COUNT", 5); bool shortName = options.GetOption("NAME", "FULL") == "SHORT"; bool hasPreviousSnapshot = reportData.PreviousSnapshot != null; RuleDescription rule = reportData.RuleExplorer.GetSpecificRule(reportData.Application.DomainId, ruleId); string ruleName = rule.Name; rowData.Add(Labels.ObjectsInViolationForRule + " " + ruleName); cellidx++; IEnumerable <Violation> results = reportData.SnapshotExplorer.GetViolationsListIDbyBC(reportData.CurrentSnapshot.Href, ruleId, bcId, nbLimitTop, "$all"); if (results != null) { var _violations = results as Violation[] ?? results.ToArray(); if (_violations.Length != 0) { int violation_counter = 0; string domainId = reportData.CurrentSnapshot.DomainId; string snapshotId = reportData.CurrentSnapshot.Id.ToString(); MetricsUtility.PopulateViolationsBookmarks(reportData, _violations, violation_counter, rowData, cellidx, ruleName, cellProps, hasPreviousSnapshot, domainId, snapshotId, ruleId); } else { rowData.Add(Labels.NoItem); } } else { rowData.Add(Labels.NoItem); } var table = new TableDefinition { HasRowHeaders = false, HasColumnHeaders = true, NbRows = rowData.Count, NbColumns = 1, Data = rowData, CellsAttributes = cellProps }; return(table); }
public override TableDefinition Content(ReportData reportData, Dictionary <string, string> options) { string prop1 = options.GetOption("PROP1", "cyclomaticComplexity"); string prop2 = options.GetOption("PROP2", "cyclomaticComplexity"); string order1 = options.GetOption("ORDER1", "desc"); string order2 = options.GetOption("ORDER2", "desc"); int nbLimitTop = options.GetIntOption("COUNT", 50); if (!order1.ToLower().Equals("asc") && !order1.ToLower().Equals("desc")) { order1 = "desc"; } if (!order2.ToLower().Equals("asc") && !order2.ToLower().Equals("desc")) { order2 = "desc"; } if (nbLimitTop == -1) { nbLimitTop = 50; } List <string> rowData = new List <string> { Labels.ObjectName }; if (!VersionUtil.Is18Compatible(reportData.ServerVersion)) { LogHelper.Instance.LogError("Bad version of RestAPI. Should be 1.8 at least for component TOP_COMPONENTS_BY_PROPERTIES"); rowData.Add(Labels.NoData); return(new TableDefinition { HasRowHeaders = false, HasColumnHeaders = true, NbRows = 2, NbColumns = 1, Data = rowData }); } string _prop1Name = MetricsUtility.GetPropertyName(prop1); rowData.Add(_prop1Name); string _prop2Name = MetricsUtility.GetPropertyName(prop2); rowData.Add(_prop2Name); if (_prop1Name == string.Empty || _prop2Name == string.Empty) { rowData.AddRange(new List <string>() { Labels.PropertiesNotAvailable, string.Empty, string.Empty }); rowData.AddRange(new List <string>() { "codeLines", string.Empty, string.Empty, "commentedCodeLines", string.Empty, string.Empty, "commentLines", string.Empty, string.Empty, "coupling", string.Empty, string.Empty, "fanIn", string.Empty, string.Empty, "fanOut", string.Empty, string.Empty, "cyclomaticComplexity", string.Empty, string.Empty, "ratioCommentLinesCodeLines", string.Empty, string.Empty, "halsteadProgramLength", string.Empty, string.Empty, "halsteadProgramVocabulary", string.Empty, string.Empty, "halsteadVolume", string.Empty, string.Empty, "distinctOperators", string.Empty, string.Empty, "distinctOperands", string.Empty, string.Empty, "integrationComplexity", string.Empty, string.Empty, "essentialComplexity", string.Empty, string.Empty }); nbLimitTop = 16; } else { if (SnapshotUtility.IsLatestSnapshot(reportData.Application, reportData.CurrentSnapshot)) { List <ComponentWithProperties> components = reportData.SnapshotExplorer.GetComponentsByProperties(reportData.CurrentSnapshot.Href, 60017, prop1, prop2, order1, order2, nbLimitTop).ToList(); if (components.Count <= 0) { rowData.AddRange(new List <string> { Labels.NoData, string.Empty, string.Empty }); } else { foreach (ComponentWithProperties _component in components) { rowData.Add(_component.Name); rowData.Add(_component.GetPropertyValueString(prop1)); rowData.Add(_component.GetPropertyValueString(prop2)); } } } else { rowData.AddRange(new List <string> { Labels.SnapshotNotTheLatestOne, string.Empty, string.Empty }); } } var resultTable = new TableDefinition { HasRowHeaders = false, HasColumnHeaders = true, NbRows = nbLimitTop + 1, NbColumns = 3, Data = rowData }; return(resultTable); }
public override TableDefinition Content(ReportData reportData, Dictionary <string, string> options) { List <string> rowData = new List <string>(); List <CellAttributes> cellProps = new List <CellAttributes>(); int cellidx = 0; // cellProps will contains the properties of the cell (background color) linked to the data by position in the list stored with cellidx. List <string> metrics = options.GetOption("METRICS").Trim().Split('|').ToList(); bool critical; if (options == null || !options.ContainsKey("CRITICAL")) { critical = false; } else { critical = options.GetOption("CRITICAL").Equals("true"); } List <string> qualityRules = MetricsUtility.BuildRulesList(reportData, metrics, critical); rowData.Add(Labels.Violations); cellidx++; if (qualityRules.Count > 0) { const string bcId = "60017"; int nbLimitTop = options.GetIntOption("COUNT", 5); bool hasPreviousSnapshot = reportData.PreviousSnapshot != null; foreach (string _metric in qualityRules) { RuleDescription rule = reportData.RuleExplorer.GetSpecificRule(reportData.Application.DomainId, _metric); string ruleName = rule.Name; if (ruleName == null) { continue; } int metricId; if (!int.TryParse(_metric, out metricId)) { continue; } ViolStatMetricIdDTO violStats = RulesViolationUtility.GetViolStat(reportData.CurrentSnapshot, metricId); if (violStats == null) { continue; } // if no violations, do not display anything for this rule if (violStats.TotalViolations < 1) { continue; } rowData.Add(""); cellidx++; rowData.Add(Labels.ObjectsInViolationForRule + " " + ruleName); cellProps.Add(new CellAttributes(cellidx, Color.Gray, Color.White, "bold")); cellidx++; rowData.Add(Labels.ViolationsCount + ": " + violStats.TotalViolations); cellProps.Add(new CellAttributes(cellidx, Color.White)); cellidx++; if (!string.IsNullOrWhiteSpace(rule.Rationale)) { rowData.Add(Labels.Rationale + ": "); cellProps.Add(new CellAttributes(cellidx, Color.LightGray)); cellidx++; rowData.Add(rule.Rationale); cellProps.Add(new CellAttributes(cellidx, Color.White)); cellidx++; } rowData.Add(Labels.Description + ": "); cellProps.Add(new CellAttributes(cellidx, Color.LightGray)); cellidx++; rowData.Add(rule.Description); cellProps.Add(new CellAttributes(cellidx, Color.White)); cellidx++; if (!string.IsNullOrWhiteSpace(rule.Remediation)) { rowData.Add(Labels.Remediation + ": "); cellProps.Add(new CellAttributes(cellidx, Color.LightGray)); cellidx++; rowData.Add(rule.Remediation); cellProps.Add(new CellAttributes(cellidx, Color.White)); cellidx++; } IEnumerable <Violation> results = reportData.SnapshotExplorer.GetViolationsListIDbyBC(reportData.CurrentSnapshot.Href, _metric, bcId, nbLimitTop, "$all"); if (results == null) { continue; } var _violations = results as Violation[] ?? results.ToArray(); if (_violations.Length == 0) { continue; } int violation_counter = 0; string domainId = reportData.CurrentSnapshot.DomainId; string snapshotId = reportData.CurrentSnapshot.Id.ToString(); cellidx = MetricsUtility.PopulateViolationsBookmarks(reportData, _violations, violation_counter, rowData, cellidx, ruleName, cellProps, hasPreviousSnapshot, domainId, snapshotId, _metric); // Add empty lines for readability for (int i = 1; i < 5; i++) { rowData.Add(""); cellidx++; } } if (rowData.Count <= 1) { rowData.Add(Labels.NoViolation); } } else { rowData.Add(Labels.NoItem); } var table = new TableDefinition { HasRowHeaders = false, HasColumnHeaders = true, NbRows = rowData.Count, NbColumns = 1, Data = rowData, CellsAttributes = cellProps }; return(table); }
public override TableDefinition Content(ReportData reportData, Dictionary <string, string> options) { List <string> metrics = options.GetOption("METRICS").Trim().Split('|').ToList(); bool critical; if (options == null || !options.ContainsKey("CRITICAL")) { critical = false; } else { critical = options.GetOption("CRITICAL").Equals("true"); } bool displayCompliance = options.GetBoolOption("COMPLIANCE"); bool sortedByCompliance = displayCompliance && options.GetOption("SORTED", "TOTAL").Equals("COMPLIANCE"); bool vulnerability = options.GetOption("LBL", "vulnerabilities").ToLower().Equals("vulnerabilities"); string lbltotal = vulnerability ? Labels.TotalVulnerabilities : Labels.TotalViolations; string lbladded = vulnerability ? Labels.AddedVulnerabilities : Labels.AddedViolations; string lblremoved = vulnerability ? Labels.RemovedVulnerabilities : Labels.RemovedViolations; // cellProps will contains the properties of the cell (background color) linked to the data by position in the list stored with cellidx. List <CellAttributes> cellProps = new List <CellAttributes>(); int cellidx = 0; var headers = new HeaderDefinition(); headers.Append(Labels.CASTRules); cellidx++; headers.Append(lbltotal); cellidx++; headers.Append(lbladded); cellidx++; headers.Append(lblremoved); cellidx++; headers.Append(Labels.ComplianceScorePercent, displayCompliance); if (displayCompliance) { cellidx++; } var dataRow = headers.CreateDataRow(); var data = new List <string>(); List <string> qualityRules = MetricsUtility.BuildRulesList(reportData, metrics, critical); List <ApplicationResult> results = sortedByCompliance ? reportData.CurrentSnapshot?.QualityRulesResults.Where(_ => qualityRules.Contains(_.Reference.Key.ToString())).OrderBy(_ => _.DetailResult.ViolationRatio.Ratio).ToList() : reportData.CurrentSnapshot?.QualityRulesResults.Where(_ => qualityRules.Contains(_.Reference.Key.ToString())).OrderByDescending(_ => _.DetailResult.ViolationRatio.FailedChecks).ToList(); if (results?.Count > 0) { foreach (var result in results) { var detailResult = result.DetailResult; if (detailResult == null) { continue; } int nbViolations = detailResult.ViolationRatio.FailedChecks ?? 0; dataRow.Set(Labels.CASTRules, (result.Reference?.Name + " (" + result.Reference?.Key + ")").NAIfEmpty()); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; dataRow.Set(lbltotal, detailResult.ViolationRatio.FailedChecks.HasValue ? detailResult.ViolationRatio?.FailedChecks.Value.ToString("N0") : Constants.No_Value); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; dataRow.Set(lbladded, detailResult.EvolutionSummary?.AddedViolations.NAIfEmpty("N0")); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; dataRow.Set(lblremoved, detailResult.EvolutionSummary?.RemovedViolations.NAIfEmpty("N0")); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; if (displayCompliance) { dataRow.Set(Labels.ComplianceScorePercent, detailResult.ViolationRatio?.Ratio.FormatPercent(false)); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; } data.AddRange(dataRow); } } if (data.Count == 0) { dataRow.Reset(); dataRow.Set(0, Labels.NoRules); data.AddRange(dataRow); } data.InsertRange(0, headers.Labels); return(new TableDefinition { Data = data, HasColumnHeaders = true, HasRowHeaders = false, NbColumns = headers.Count, NbRows = data.Count / headers.Count, CellsAttributes = cellProps }); }