Example #1
0
        private static StringBuilder GenerateScript(ChartReportBlock block, string chartId, ReportQueryResult query)
        {
            var sb = new StringBuilder();

            sb.AppendLine($"var ctx = document.getElementById(\"{chartId}\").getContext(\"2d\");;");

            sb.AppendLine($"ctx.canvas.height = {block.HeightPx};");

            var chartType = GetChartType(block);

            sb.AppendLine($"var myChart = new Chart(ctx, {{type: '{chartType}', data: {{ labels: [");

            // ReSharper disable once LoopCanBePartlyConvertedToQuery
            foreach (var labelItem in query.Result.Items)
            {
                var property = labelItem.Value.GetType().GetProperty(block.Label.ColumnKey);

                if (property == null)
                {
                    throw new Exception($"Label property is not defined. Property='{block.Label.ColumnKey}'");
                }

                var labelValue = property.GetValue(labelItem.Value);

                sb.Append($"\"{labelValue}\",");
            }

            sb.AppendLine("], datasets: [");

            RenderGraph(block, query, sb);

            sb.AppendLine("]},");

            sb.AppendLine("options: { maintainAspectRatio: false, scales: { yAxes: [{ticks: {beginAtZero:true}}]}}});");

            return(sb);
        }
Example #2
0
        private static void RenderLineOrBar(ChartReportBlock block, StringBuilder sb, ReportQueryResult query)
        {
            var labels = new List <string>();

            foreach (var blockColumn in block.Columns)
            {
                var labelSb = new StringBuilder();

                var fill = blockColumn.Fill ? "true" : "false";

                labelSb.AppendLine($"{{ label: '{blockColumn.DisplayName}', fill: {fill},");

                labelSb.AppendLine($"borderWidth: {blockColumn.BorderWidth},");

                var backgroundColor = blockColumn.BackgroundColor.ToRgba();
                var lineColor       = blockColumn.LineColor.ToRgba();

                // just fixed colors
                labelSb.AppendLine($"backgroundColor: \"{backgroundColor}\",");
                labelSb.AppendLine($"borderColor: \"{lineColor}\",");

                labelSb.AppendLine($"hoverBackgroundColor: \"{backgroundColor}\",");
                labelSb.AppendLine($"hoverBorderColor: \"{lineColor}\",");

                labelSb.Append("data: [");

                // ReSharper disable once LoopCanBePartlyConvertedToQuery
                foreach (var columnItem in query.Result.Items)
                {
                    var property = columnItem.Value.GetType().GetProperty(blockColumn.ColumnKey);

                    if (property == null)
                    {
                        throw new Exception($"Property is not defined. Property='{blockColumn.ColumnKey}'");
                    }

                    var columnValue = property.GetValue(columnItem.Value);

                    labelSb.Append($"{columnValue},");
                }

                labelSb.AppendLine("]");

                labelSb.AppendLine("}");

                labels.Add(labelSb.ToString());
            }

            var labelString = string.Join(",", labels);

            sb.AppendLine(labelString);
        }
        private static List <ReportQueryItemResult> ConvertAllNodesToPathes(CxViewerAction.CxVSWebService.CxWSResultPath[] cxWSPathNode, int resultId, ReportQueryResult queryResult)
        {
            List <ReportQueryItemResult> list = new List <ReportQueryItemResult>();

            foreach (CxViewerAction.CxVSWebService.CxWSResultPath node in cxWSPathNode)
            {
                list.Add(new ReportQueryItemResult()
                {
                    Remark   = node.Comment,
                    FileName = node.Nodes[0].FileName,
                    Line     = node.Nodes[0].Line,
                    ResultId = resultId,
                    Query    = queryResult,
                });
            }
            return(list);
        }
        /// <summary>
        /// Execute 'Show Stored' command
        /// </summary>
        /// <param name="queries"></param>
        /// <param name="login"></param>
        /// <param name="scanId"></param>
        public static void ShowStored(CxWSQueryVulnerabilityData[] queries, LoginData login, long scanId)
        {
            Dictionary <ReportQuerySeverityType, List <CxWSQueryVulnerabilityData> > queriesGroups = new Dictionary <ReportQuerySeverityType, List <CxWSQueryVulnerabilityData> >();
            List <CxWSQueryVulnerabilityData> sev0 = new List <CxWSQueryVulnerabilityData>();
            List <CxWSQueryVulnerabilityData> sev1 = new List <CxWSQueryVulnerabilityData>();
            List <CxWSQueryVulnerabilityData> sev2 = new List <CxWSQueryVulnerabilityData>();
            List <CxWSQueryVulnerabilityData> sev3 = new List <CxWSQueryVulnerabilityData>();

            for (int i = 0; i < queries.Length; i++)
            {
                CxWSQueryVulnerabilityData cur = queries[i];
                switch (cur.Severity)
                {
                case 0:
                    sev0.Add(cur);
                    break;

                case 1:
                    sev1.Add(cur);
                    break;

                case 2:
                    sev2.Add(cur);
                    break;

                case 3:
                    sev3.Add(cur);
                    break;
                }
            }
            if (sev3.Count > 0)
            {
                queriesGroups.Add(ReportQuerySeverityType.High, sev3);
            }
            if (sev2.Count > 0)
            {
                queriesGroups.Add(ReportQuerySeverityType.Medium, sev2);
            }
            if (sev1.Count > 0)
            {
                queriesGroups.Add(ReportQuerySeverityType.Low, sev1);
            }
            if (sev0.Count > 0)
            {
                queriesGroups.Add(ReportQuerySeverityType.Information, sev0);
            }


            Dictionary <ReportQuerySeverityType, List <ReportQueryResult> > tree = new Dictionary <ReportQuerySeverityType, List <ReportQueryResult> >();

            foreach (var queryGroup in queriesGroups)
            {
                List <ReportQueryResult> list = new List <ReportQueryResult>();

                for (int i = 0; i < queryGroup.Value.Count; i++)
                {
                    CxWSQueryVulnerabilityData query = queryGroup.Value[i];

                    ReportQueryResult queryResult = new ReportQueryResult()
                    {
                        CweId            = (int)query.CWE,
                        Group            = query.GroupName,
                        Id               = (int)query.QueryId,
                        Name             = query.QueryName,
                        Paths            = null,
                        Report           = null,
                        Severity         = (ReportQuerySeverityType)query.Severity,
                        AmountOfResults  = query.AmountOfResults,
                        ScanId           = scanId,
                        QueryVersionCode = query.QueryVersionCode
                    };

                    list.Add(queryResult);
                }

                tree.Add(queryGroup.Key, list);
            }

            ReportResult report = new ReportResult();

            report.Tree = tree;

            var reportWinObject = CommonActionsInstance.getInstance().ReportPersepectiveView;

            reportWinObject.Report = report;

            reportWinObject.BindData();
        }
        public static List <ReportQueryItemPathResult> ConvertNodesToPathes(CxViewerAction.CxVSWebService.CxWSPathNode[] cxWSPathNode, ReportQueryResult queryResult, ReportQueryItemResult queryItemResult)
        {
            List <ReportQueryItemPathResult> list = new List <ReportQueryItemPathResult>();

            foreach (CxViewerAction.CxVSWebService.CxWSPathNode node in cxWSPathNode)
            {
                list.Add(new ReportQueryItemPathResult()
                {
                    Name      = node.Name,
                    FileName  = node.FileName,
                    Line      = node.Line,
                    NodeId    = node.PathNodeId,
                    Length    = node.Length,
                    Column    = node.Column,
                    Query     = queryResult,
                    QueryItem = queryItemResult
                });
            }
            return(list);
        }