Beispiel #1
0
        public override TableDefinition Content(ReportData reportData, Dictionary <string, string> options)
        {
            int  param;
            bool showPrevious = false;

            if (reportData.PreviousSnapshot != null && null != options && options.ContainsKey("SHOW_PREVIOUS") && int.TryParse(options["SHOW_PREVIOUS"], out param))
            {
                showPrevious = (param != 0);
            }

            List <string> rowData = new List <string>();

            int nbRows = 0;

            rowData.AddRange(new[] {
                " ",
                Labels.TQI,
                Labels.Robu,
                Labels.Efcy,
                Labels.Secu,
                Labels.Trans,
                Labels.Chang
            });
            nbRows++;

            var busCrit = new[] {
                Constants.BusinessCriteria.TechnicalQualityIndex,
                Constants.BusinessCriteria.Robustness,
                Constants.BusinessCriteria.Performance,
                Constants.BusinessCriteria.Security,
                Constants.BusinessCriteria.Transferability,
                Constants.BusinessCriteria.Changeability
            };
            var curVersion = new int[busCrit.Length];
            var added      = new int[busCrit.Length];
            var removed    = new int[busCrit.Length];

            for (int i = 0; i < busCrit.Length; i++)
            {
                var resbc = RulesViolationUtility.GetViolStat(reportData.CurrentSnapshot, busCrit[i].GetHashCode());
                if (resbc.TotalCriticalViolations != null)
                {
                    curVersion[i] = resbc.TotalCriticalViolations.Value;
                }
                if (resbc.AddedCriticalViolations != null)
                {
                    added[i] = resbc.AddedCriticalViolations.Value;
                }
                if (resbc.RemovedCriticalViolations != null)
                {
                    removed[i] = resbc.RemovedCriticalViolations.Value;
                }
            }

            rowData.Add(Labels.VersionCurrent);
            rowData.AddRange(curVersion.Select(curValue => curValue.ToString("N0")));
            nbRows++;

            rowData.Add("   " + Labels.ViolationsAdded);
            rowData.AddRange(added.Select(addValue => FormatEvolution(addValue)));
            nbRows++;

            rowData.Add("   " + Labels.ViolationsRemoved);
            rowData.AddRange(removed.Select(remValue => FormatEvolution(-remValue)));
            nbRows++;

            if (showPrevious)
            {
                var prevVersion = new int[busCrit.Length];
                for (int i = 0; i < busCrit.Length; i++)
                {
                    var resbc = RulesViolationUtility.GetViolStat(reportData.PreviousSnapshot, busCrit[i].GetHashCode());
                    if (resbc.TotalCriticalViolations != null)
                    {
                        prevVersion[i] = resbc.TotalCriticalViolations.Value;
                    }
                }
                rowData.Add(Labels.VersionPrevious);
                rowData.AddRange(prevVersion.Select(prevValue => prevValue.ToString()));
                nbRows++;
            }

            var resultTable = new TableDefinition {
                HasRowHeaders    = false,
                HasColumnHeaders = true,
                NbRows           = nbRows,
                NbColumns        = busCrit.Length + 1,
                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);
        }