private void AddSeverity([NotNull] WTableCell cell, [Required] string severityName, KnownColor textColor, KnownColor backColor) { var table = cell.AddTable(); table.ResetCells(1, 1); table.ApplyStyleForBandedColumns = false; table.ApplyStyleForBandedRows = false; table.ApplyStyleForFirstColumn = false; table.ApplyStyleForHeaderRow = false; table.ApplyStyleForLastColumn = false; table.ApplyStyleForLastRow = false; table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; table[0, 0].CellFormat.BackColor = Color.FromKnownColor(backColor); table[0, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; table[0, 0].Width = 75; var paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; var range = paragraph.AppendText(severityName); range.CharacterFormat.TextColor = Color.FromKnownColor(textColor); range.CharacterFormat.Bold = true; }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IThreatType threatType) { var threatEvents = GetAssociatedThreatEvents(threatType)? .Where(x => x.HasProperty(PropertyType) && !string.IsNullOrWhiteSpace(x.GetProperty(PropertyType)?.StringValue)) .ToArray(); if (threatEvents?.Any() ?? false) { var table = cell.AddTable(); int count = threatEvents.Length; table.ResetCells(count + 1, 2); table.ApplyStyleForBandedColumns = false; table.ApplyStyleForBandedRows = false; table.ApplyStyleForFirstColumn = false; table.ApplyStyleForHeaderRow = true; table.ApplyStyleForLastColumn = false; table.ApplyStyleForLastRow = false; table.TableFormat.IsAutoResized = true; var header = table.Rows[0]; header.Cells[0].AddParagraph().AppendText("Object"); header.Cells[0].Width = 150; header.Cells[1].AddParagraph().AppendText("Value"); header.Cells[1].Width = 350; for (int i = 0; i < count; i++) { var row = table.Rows[i + 1]; var te = threatEvents[i]; var parent = te.Parent; row.Cells[0].AddParagraph().AppendText($"[{te.Model.GetIdentityTypeInitial(parent)}] {parent.Name}"); row.Cells[0].Width = 150; var property = te.GetProperty(PropertyType); row.Cells[1].AddParagraph().AppendText(property?.StringValue ?? "N/A"); row.Cells[1].Width = 350; } } else { cell.AddParagraph().AppendText("N/A"); } } }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IMitigation mitigation) { var tems = GetAssociatedThreatEvents(mitigation)?.Where(x => !string.IsNullOrWhiteSpace(x.Directives)).ToArray(); if (tems?.Any() ?? false) { var sorted = tems.OrderByDescending(x => x.Strength, new StrengthComparer()).ToArray(); var table = cell.AddTable(); int count = sorted.Length; table.ResetCells(count + 1, 2); table.ApplyStyleForBandedColumns = false; table.ApplyStyleForBandedRows = false; table.ApplyStyleForFirstColumn = false; table.ApplyStyleForHeaderRow = true; table.ApplyStyleForLastColumn = false; table.ApplyStyleForLastRow = false; table.TableFormat.IsAutoResized = true; var header = table.Rows[0]; header.Cells[0].AddParagraph().AppendText("Object"); header.Cells[0].Width = 150; header.Cells[1].AddParagraph().AppendText("Directives"); header.Cells[1].Width = 350; for (int i = 0; i < count; i++) { var row = table.Rows[i + 1]; var tem = sorted[i]; var parent = tem.ThreatEvent.Parent; row.Cells[0].AddParagraph() .AppendText($"[{mitigation.Model.GetIdentityTypeInitial(parent)}] {parent.Name}"); row.Cells[0].Width = 150; row.Cells[1].Width = 350; row.Cells[1].AddParagraph().AppendText(tem.Directives); } } else { cell.AddParagraph().AppendText("N/A"); } } }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IMitigation mitigation) { var tems = GetAssociatedThreatEvents(mitigation)?.ToArray(); if (tems?.Any() ?? false) { var sorted = tems.OrderBy(x => x.ThreatEvent.Parent.Name).ToArray(); var table = cell.AddTable(); int count = sorted.Length; table.ResetCells(count + 1, 4); table.ApplyStyleForBandedColumns = false; table.ApplyStyleForBandedRows = false; table.ApplyStyleForFirstColumn = false; table.ApplyStyleForHeaderRow = true; table.ApplyStyleForLastColumn = false; table.ApplyStyleForLastRow = false; table.TableFormat.IsAutoResized = true; var header = table.Rows[0]; header.Cells[0].AddParagraph().AppendText("Object"); header.Cells[0].Width = 150; header.Cells[1].AddParagraph().AppendText("Threat"); header.Cells[1].Width = 150; header.Cells[2].AddParagraph().AppendText("Strength"); header.Cells[2].Width = 100; header.Cells[3].AddParagraph().AppendText("Status"); header.Cells[3].Width = 100; for (int i = 0; i < count; i++) { var row = table.Rows[i + 1]; var tem = sorted[i]; var parent = tem.ThreatEvent.Parent; row.Cells[0].AddParagraph() .AppendText($"[{mitigation.Model.GetIdentityTypeInitial(parent)}] {parent.Name}"); row.Cells[0].Width = 150; var bookmarkTe = cell.Document.Bookmarks.FindByName(tem.ThreatEvent.Id.ToString("N")); if (bookmarkTe != null) { row.Cells[1].AddParagraph() .AppendCrossReference(ReferenceType.Bookmark, ReferenceKind.ContentText, bookmarkTe.BookmarkStart, true, false, false, null); } else { var bookmarkTt = cell.Document.Bookmarks.FindByName(tem.ThreatEvent.ThreatType.Id.ToString("N")); if (bookmarkTt != null) { row.Cells[1].AddParagraph() .AppendCrossReference(ReferenceType.Bookmark, ReferenceKind.ContentText, bookmarkTt.BookmarkStart, true, false, false, null); } else { row.Cells[1].AddParagraph().AppendText(tem.ThreatEvent.Name); } } row.Cells[1].Width = 150; row.Cells[2].AddParagraph().AppendText(tem.Strength?.Name ?? "N/A"); row.Cells[2].Width = 100; row.Cells[3].AddParagraph().AppendText(tem.Status.GetEnumLabel()); row.Cells[3].Width = 100; } } else { cell.AddParagraph().AppendText("N/A"); } } }