public bool Execute(IPropertiesContainer container) { bool result = false; if (container != null) { var dialog = new ApplySchemaDialog(); dialog.Initialize(container); if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK) { var schema = dialog.SelectedSchema; if (schema != null) { container.Apply(schema); result = true; } } } return(result); }
public bool AutoApplySchemas(IPropertiesContainer container) { bool result = false; Scope scope = Scope.Undefined; if (container is IExternalInteractor) { scope = Scope.ExternalInteractor; } else if (container is IProcess) { scope = Scope.Process; } else if (container is IDataStore) { scope = Scope.DataStore; } else if (container is IDataFlow) { scope = Scope.DataFlow; } else if (container is ITrustBoundary) { scope = Scope.TrustBoundary; } else if (container is IThreatType) { scope = Scope.ThreatType; } else if (container is IThreatEvent) { scope = Scope.ThreatEvent; } else if (container is IThreatEventScenario) { scope = Scope.ThreatEventScenario; } else if (container is IMitigation) { scope = Scope.Mitigation; } else if (container is IDiagram) { scope = Scope.Diagram; } else if (container is IEntityTemplate template) { switch (template.EntityType) { case EntityType.ExternalInteractor: scope = Scope.ExternalInteractor; break; case EntityType.Process: scope = Scope.Process; break; case EntityType.DataStore: scope = Scope.DataStore; break; } } if (scope != Scope.Undefined) { var schemas = _schemas?.Where(x => x.AutoApply && x.AppliesTo.HasFlag(scope)).OrderBy(x => x.Priority).ToArray(); if (schemas?.Any() ?? false) { foreach (var schema in schemas) { container?.Apply(schema); } result = true; } } return(result); }