private void LoadItems([NotNull] IEnumerable<IThreatEvent> threatEvents) { _threatEvents.PrimaryGrid.Rows.Clear(); _fieldsThreatEvents.Items.Clear(); if (threatEvents.Any()) { var selectedProperties = GetSelectedProperties(); foreach (var threatEvent in threatEvents) { var row = new GridRow( threatEvent.Name, threatEvent.Description, threatEvent.Parent != null ? _model.GetIdentityTypeName(threatEvent.Parent) : string.Empty, threatEvent.Parent?.Name ?? string.Empty, threatEvent.Severity) { Checked = true, Tag = threatEvent }; row.Cells[3].CellStyles.Default.Image = threatEvent.Parent.GetImage(ImageSize.Small); _threatEvents.PrimaryGrid.Rows.Add(row); var properties = threatEvent.Properties? .Where(x => x.PropertyType != null && x.PropertyType.Visible && (_model.GetSchema(x.PropertyType.SchemaId)?.Visible ?? false)).ToArray(); if (properties?.Any() ?? false) { foreach (var property in properties) { var propertyType = property.PropertyType; if (!_fieldsThreatEvents.Items.Contains(propertyType)) _fieldsThreatEvents.Items.Add(propertyType, selectedProperties?.Contains(propertyType.Id.ToString()) ?? false); } } } } }
public void SetObject([NotNull] IThreatModel model, [NotNull] object obj) { if (obj is IIdentity identity) { _objectContainer.Text = model.GetIdentityTypeName(identity); _objectName.Text = " " + identity.Name; _objectName.Image = identity.GetImage(ImageSize.Small); } else if (obj is IThreatEventMitigation threatEventMitigation) { _objectContainer.Text = "Threat Event Mitigation"; _objectName.Text = " " + $"Mitigation '{threatEventMitigation.Mitigation.Name}' for '{threatEventMitigation.ThreatEvent.Name}' on '{threatEventMitigation.ThreatEvent.Parent.Name}"; _objectName.Image = Icons.Resources.mitigations_small; } else if (obj is IThreatTypeMitigation threatTypeMitigation) { _objectContainer.Text = "Threat Type Mitigation"; _objectName.Text = " " + $"Mitigation '{threatTypeMitigation.Mitigation.Name}' for '{threatTypeMitigation.ThreatType.Name}'"; _objectName.Image = Icons.Resources.standard_mitigations_small; } }
public double Analyze(IThreatModel model, Func <IQualityAnalyzer, IPropertiesContainer, bool> isFalsePositive, out IEnumerable <object> instances) { double result = 0.0; instances = null; var found = new List <IIdentity>(); var entities = model.Entities?.Where(x => !isFalsePositive(this, x)).ToArray(); if (entities?.Any() ?? false) { Regex eiRegex = null; Regex pRegex = null; Regex dsRegex = null; Regex regex = null; foreach (var entity in entities) { if (entity is IExternalInteractor) { if (eiRegex == null) { eiRegex = new Regex($"{model.GetIdentityTypeName(entity)} [0-9]*"); } regex = eiRegex; } else if (entity is IProcess) { if (pRegex == null) { pRegex = new Regex($"{model.GetIdentityTypeName(entity)} [0-9]*"); } regex = pRegex; } if (entity is IDataStore) { if (dsRegex == null) { dsRegex = new Regex($"{model.GetIdentityTypeName(entity)} [0-9]*"); } regex = dsRegex; } if (!string.IsNullOrWhiteSpace(entity.Name) && (regex?.Match(entity.Name).Success ?? false)) { found.Add(entity); } } } var flows = model.DataFlows?.Where(x => !isFalsePositive(this, x)).ToArray(); if (flows?.Any() ?? false) { foreach (var flow in flows) { if (string.CompareOrdinal(flow.Name, "Flow") == 0) { found.Add(flow); } } } var groups = model.Groups?.Where(x => !isFalsePositive(this, x)).ToArray(); if (groups?.Any() ?? false) { Regex tbRegex = null; foreach (var group in groups) { if (tbRegex == null) { tbRegex = new Regex($"{model.GetIdentityTypeName(group)} [0-9]*"); } if (!string.IsNullOrWhiteSpace(group.Name) && (tbRegex?.Match(group.Name).Success ?? false)) { found.Add(group); } } } result = found.Count; instances = found; return(result); }