Esempio n. 1
0
        public void RefreshChart([NotNull] IThreatModel model)
        {
            if (_chart.ChartPanel.ChartContainers[0] is PieChart pieChart)
            {
                pieChart.ChartSeries[0].SeriesPoints.Clear();
                var severities  = model.Severities?.ToArray();
                var threatTypes = model.ThreatTypes?.ToArray();

                if ((severities?.Any() ?? false) && (threatTypes?.Any() ?? false))
                {
                    var total = model.AssignedThreatTypes;
                    foreach (var severity in severities)
                    {
                        var count = model.CountThreatEventsByType(severity);

                        if (count > 0)
                        {
                            var slice = pieChart.ChartSeries[0].SeriesPoints
                                        .OfType <PieSeriesPoint>()
                                        .FirstOrDefault(x => string.CompareOrdinal(x.Name, severity.Name) == 0);
                            if (slice == null)
                            {
                                slice = new PieSeriesPoint()
                                {
                                    Name            = severity.Name,
                                    ValueX          = severity.Name,
                                    ValueY          = new object[] { (object)count },
                                    OuterSliceLabel =
                                        $"{count} ({((float) count * 100f / (float) total).ToString("F0")}%)",
                                    InnerSliceLabel = ""
                                };
                                slice.SliceVisualStyles.Default.Background.Color1 =
                                    Color.FromKnownColor(severity.BackColor);
                                slice.SliceVisualStyles.Default.SliceOuterLabelStyle.TextColor = Color.Black;
                                pieChart.ChartSeries[0].SeriesPoints.Add(slice);
                            }
                            else
                            {
                                slice.ValueY          = new object[] { (object)count };
                                slice.OuterSliceLabel =
                                    $"{count} ({((float) count * 100f / (float) total).ToString("F0")}%)";
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public IEnumerable <ChartItem> GetChart([NotNull] IThreatModel model)
        {
            IEnumerable <ChartItem> result = null;

            var severities = model.Severities?
                             .Where(x => x.Visible && x.Id > 0)
                             .OrderByDescending(x => x.Id).ToArray()
                             .ToArray();

            if (severities?.Any() ?? false)
            {
                var list = new List <ChartItem>();

                foreach (var severity in severities)
                {
                    list.Add(new ChartItem(severity.Name, model.CountThreatEventsByType(severity), severity.BackColor));
                }

                result = list;
            }

            return(result);
        }
Esempio n. 3
0
 public int GetCounter(IThreatModel model)
 {
     return(model.CountThreatEventsByType((int)DefaultSeverity.Info));
 }