public IThreatEventMitigation AddMitigation(IMitigation mitigation, IStrength strength, MitigationStatus status = MitigationStatus.Proposed, string directives = null) { if (!(IsInitialized?.Get() ?? false)) { return(null); } if (mitigation == null) { throw new ArgumentNullException(nameof(mitigation)); } IThreatEventMitigation result = null; if (GetMitigation(mitigation.Id) == null) { result = new ThreatEventMitigation(MySelf?.Get(), mitigation, strength); result.Status = status; result.Directives = directives; if (_mitigations == null) { _mitigations = new List <IThreatEventMitigation>(); } _mitigations.Add(result); Dirty.IsDirty = true; _threatEventMitigationAdded?.Invoke(MitigationsContainer?.Get(), result); } return(result); }
private void AddGridRow([NotNull] IThreatEventMitigation mitigation, [NotNull] GridPanel panel) { GridRow row = new GridRow( mitigation.ThreatEvent?.Name ?? string.Empty, mitigation.ThreatEvent?.Parent?.Name ?? string.Empty, mitigation.ThreatEvent?.Severity, mitigation.Strength, mitigation.Status.ToString()) { Tag = mitigation }; UpdateMitigationLevel(mitigation.ThreatEvent, row); if (mitigation.ThreatEvent?.Parent != null) { row.Cells[1].CellStyles.Default.Image = mitigation.ThreatEvent.Parent.GetImage(ImageSize.Small); ((INotifyPropertyChanged)mitigation.ThreatEvent.Parent).PropertyChanged += OnThreatEventMitigationParentPropertyChanged; if (mitigation.ThreatEvent.Parent is IEntity entity) { entity.ImageChanged += OnImageChanged; } AddSuperTooltipProvider(mitigation.ThreatEvent.Parent, row.Cells[1]); } for (int i = 0; i < row.Cells.Count; i++) { row.Cells[i].PropertyChanged += OnThreatEventMitigationCellChanged; } panel.Rows.Add(row); ((INotifyPropertyChanged)mitigation).PropertyChanged += OnThreatEventMitigationPropertyChanged; mitigation.ThreatEvent.ThreatEventMitigationAdded += OnThreatEventMitigationAdded; mitigation.ThreatEvent.ThreatEventMitigationRemoved += OnThreatEventMitigationRemoved; }
private void AddGridRow([NotNull] IThreatEventMitigation mitigation) { GridRow row = new GridRow( mitigation.ThreatEvent?.Name ?? string.Empty, mitigation.ThreatEvent?.Parent?.Name ?? string.Empty, mitigation.ThreatEvent?.Severity.ToString(), mitigation.Strength.ToString(), mitigation.Status.ToString()) { Tag = mitigation }; switch (mitigation.ThreatEvent.GetMitigationLevel()) { case MitigationLevel.NotMitigated: row.Cells[0].CellStyles.Default.Image = Resources.threat_circle_small; break; case MitigationLevel.Partial: row.Cells[0].CellStyles.Default.Image = Resources.threat_circle_orange_small; break; case MitigationLevel.Complete: row.Cells[0].CellStyles.Default.Image = Resources.threat_circle_green_small; break; } if (mitigation.ThreatEvent?.Parent != null) { row.Cells[1].CellStyles.Default.Image = mitigation.ThreatEvent.Parent.GetImage(ImageSize.Small); AddSuperTooltipProvider(mitigation.ThreatEvent.Parent, row.Cells[1]); } _grid.PrimaryGrid.Rows.Add(row); }
private GridRow GetRow([NotNull] IThreatEventMitigation mitigation) { GridRow result = null; var rows = _grid.PrimaryGrid.Rows.OfType <GridRow>().ToArray(); foreach (var row in rows) { var panel = row.Rows.OfType <GridPanel>() .FirstOrDefault(x => string.CompareOrdinal("ThreatEventMitigations", x.Name) == 0); if (panel != null) { result = panel.Rows.OfType <GridRow>().FirstOrDefault(x => (x.Tag is IThreatEventMitigation threatEventMitigation) && threatEventMitigation.MitigationId == mitigation.MitigationId && threatEventMitigation.ThreatEvent.Id == mitigation.ThreatEvent.Id); if (result != null) { break; } } } return(result); }
public IThreatEventMitigation AddMitigation(IMitigation mitigation, IStrength strength, MitigationStatus status = MitigationStatus.Proposed, string directives = null) { if (mitigation == null) { throw new ArgumentNullException(nameof(mitigation)); } IThreatEventMitigation result = null; if (GetMitigation(mitigation.Id) == null && Instance is IThreatEvent threatEvent) { result = new ThreatEventMitigation(threatEvent, mitigation, strength) { Status = status, Directives = directives }; if (_mitigations == null) { _mitigations = new List <IThreatEventMitigation>(); } _mitigations.Add(result); if (Instance is IDirty dirtyObject) { dirtyObject.SetDirty(); } _threatEventMitigationAdded?.Invoke(threatEvent, result); } return(result); }
public bool Execute(IThreatEventMitigation mitigation) { bool result = false; if (mitigation is IPropertiesContainer container) { result = Execute(container); } return(result); }
public bool Execute(IThreatEventMitigation teMitigation) { bool result = false; if (teMitigation != null) { using (var dialog = new ItemEditorDialog()) { dialog.SetExecutionMode(_executionMode); dialog.Item = teMitigation.Mitigation; dialog.ShowDialog(Form.ActiveForm); } result = true; } return(result); }
private void _ok_Click(object sender, EventArgs e) { if (_strength.SelectedItem is IStrength strength && Enum.TryParse <MitigationStatus>(_status.SelectedItem.ToString(), out var status)) { if (_associateStandard.Checked) { if (_standardMitigation.SelectedItem is IThreatTypeMitigation threatTypeMitigation) { _mitigation = _threatEvent.AddMitigation(threatTypeMitigation.Mitigation, strength, status, _directives.Text); } } else if (_associateNonstandard.Checked) { if (_nonStandardMitigation.SelectedItem is IMitigation mitigation) { if (_associateToStandard.Checked) { _threatEvent.ThreatType.AddMitigation(mitigation, strength); } _mitigation = _threatEvent.AddMitigation(mitigation, strength, status, _directives.Text); } } else if (_createNew.Checked) { if (Enum.TryParse <SecurityControlType>((string)_controlType.SelectedItem, out var controlType)) { var newMitigation = _threatEvent.Model.AddMitigation(_name.Text); newMitigation.Description = _description.Text; newMitigation.ControlType = controlType; if (_newToStandard.Checked) { _threatEvent.ThreatType.AddMitigation(newMitigation, strength); } _mitigation = _threatEvent.AddMitigation(newMitigation, strength, status, _directives.Text); } } } }
public void Add(IThreatEventMitigation mitigation) { if (mitigation == null) { throw new ArgumentNullException(nameof(mitigation)); } if (mitigation.ThreatEvent != Instance || (mitigation.Mitigation is IThreatModelChild child && child.Model != (Instance as IThreatModelChild)?.Model)) { throw new ArgumentException(); } if (_mitigations == null) { _mitigations = new List <IThreatEventMitigation>(); } _mitigations.Add(mitigation); }
private void AddGridRow([NotNull] IThreatEventMitigation mitigation, [NotNull] GridPanel panel) { GridRow row = new GridRow( mitigation.Mitigation.Name, mitigation.Mitigation.ControlType.ToString(), mitigation.Strength, mitigation.Status.ToString()) { Tag = mitigation }; row.Cells[0].CellStyles.Default.Image = mitigation.Mitigation.GetImage(ImageSize.Small); for (int i = 0; i < row.Cells.Count; i++) { row.Cells[i].PropertyChanged += OnMitigationCellChanged; } panel.Rows.Add(row); ((INotifyPropertyChanged)mitigation).PropertyChanged += OnThreatEventMitigationPropertyChanged; ((INotifyPropertyChanged)mitigation.Mitigation).PropertyChanged += OnMitigationPropertyChanged; }
public bool Execute(IThreatEventMitigation mitigation) { bool result = false; if (MessageBox.Show(Form.ActiveForm, $"You are about to remove mitigation '{mitigation.Mitigation.Name}' from the current Threat Event. Are you sure?", "Remove Mitigation association", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (mitigation.ThreatEvent.RemoveMitigation(mitigation.MitigationId)) { result = true; ShowMessage?.Invoke("Mitigation disassociated successfully."); } else { ShowWarning?.Invoke("The Mitigation association cannot be removed."); } } return(result); }
public void Add(IThreatEventMitigation mitigation) { if (!(IsInitialized?.Get() ?? false)) { return; } if (mitigation == null) { throw new ArgumentNullException(nameof(mitigation)); } if (mitigation.Mitigation is IThreatModelChild child && child.Model != Model?.Get()) { throw new ArgumentException(); } if (_mitigations == null) { _mitigations = new List <IThreatEventMitigation>(); } _mitigations.Add(mitigation); }
private GridRow GetRow([NotNull] IThreatEventMitigation mitigation) { GridRow result = null; var parentRow = GetRow(mitigation.ThreatEvent); if (parentRow != null) { var panels = parentRow.Rows.OfType <GridPanel>().ToArray(); if (panels.Any()) { foreach (var panel in panels) { result = panel.Rows.OfType <GridRow>().FirstOrDefault(x => x.Tag == mitigation); if (result != null) { break; } } } } return(result); }
private void Update(IThreatEventMitigationsContainer container, IThreatEventMitigation mitigation) { UpdateInfo?.Invoke(this.GetExtensionId(), CurrentStatus); }
public bool Execute(IThreatEventMitigation identity) { throw new NotImplementedException(); }
private void OnThreatEventMitigationRemoved([NotNull] IThreatEventMitigationsContainer container, [NotNull] IThreatEventMitigation mitigation) { if (!_loading) { try { _loading = true; var row = GetRow(mitigation); if (row != null) { row.GridPanel.Rows.Remove(row); } } finally { _loading = false; } } }
private void OnThreatEventMitigationAdded([NotNull] IThreatEventMitigationsContainer container, [NotNull] IThreatEventMitigation mitigation) { if (!_loading) { try { _loading = true; var row = GetRow(mitigation.Mitigation); if (row != null) { var panel = row.Rows.OfType <GridPanel>().FirstOrDefault(); if (panel != null) { AddGridRow(mitigation, panel); } } } finally { _loading = false; } } }
private void OnThreatEventMitigationRemoved(IThreatEventMitigationsContainer container, IThreatEventMitigation mitigation) { if (container is IThreatEvent threatEvent) { var row = GetRow(threatEvent); var panel = row?.Rows.OfType <GridPanel>().FirstOrDefault(x => string.CompareOrdinal(x.Name, "Mitigations") == 0); var mitigationRow = panel?.Rows.OfType <GridRow>() .FirstOrDefault(x => (x.Tag is IThreatEventMitigation eventMitigation) && eventMitigation.MitigationId == mitigation.MitigationId); if (mitigationRow != null) { panel.Rows.Remove(mitigationRow); if (panel.Rows.Count == 0) { row.Rows.Remove(panel); } } UpdateMitigationLevel(threatEvent, row); } }
private void OnThreatEventMitigationAdded(IThreatEventMitigationsContainer container, IThreatEventMitigation mitigation) { if (container is IThreatEvent threatEvent) { if (IsSelected(threatEvent, _filter.Text)) { var row = GetRow(threatEvent); if (row == null) { var typeRow = GetRow(threatEvent.ThreatType); if (typeRow == null) { typeRow = AddGridRow(threatEvent.ThreatType, new IThreatEvent[] { threatEvent }, _grid.PrimaryGrid); } var panel = typeRow.Rows.OfType <GridPanel>() .FirstOrDefault(x => string.CompareOrdinal(x.Name, "Mitigations") == 0); if (panel != null) { row = AddGridRow(threatEvent, panel); } else { // We should not come here. panel = CreateThreatEventsPanel(threatEvent.ThreatType, new IThreatEvent[] { threatEvent }); if (panel != null) { typeRow.Rows.Add(panel); row = panel.Rows.OfType <GridRow>().FirstOrDefault(); } } } else { var mitigationPanel = row.Rows.OfType <GridPanel>().FirstOrDefault(x => string.CompareOrdinal(x.Name, "Mitigations") == 0); if (mitigationPanel != null) { AddGridRow(mitigation, mitigationPanel); } else { mitigationPanel = CreateThreatEventMitigationsPanel(threatEvent); if (mitigationPanel != null) { row.Rows.Add(mitigationPanel); } } } if (row != null) { UpdateMitigationLevel(threatEvent, row); } } } }