Пример #1
0
        public bool Execute(IIdentity identity)
        {
            bool result = false;

            if (identity is IEntity entity && entity.Model is IThreatModel model &&
                MessageBox.Show(Form.ActiveForm,
                                $"You are about to disassociate the associated diagram from {model.GetIdentityTypeName(entity)} '{entity.Name}'. Are you sure?",
                                "Disassociate Diagram",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Information,
                                MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                var schemaManager = new AssociatedDiagramPropertySchemaManager(model);
                var propertyType  = schemaManager.GetAssociatedDiagramIdPropertyType();
                if (propertyType != null)
                {
                    if (entity.GetProperty(propertyType) is IPropertyIdentityReference property &&
                        property.ValueId != Guid.Empty)
                    {
                        result         = true;
                        property.Value = null;
                        DiagramAssociationHelper.NotifyDiagramDisassociation(entity);
                        ShowMessage?.Invoke("Diagram has been disassociated successfully.");
                    }
                    else
                    {
                        ShowWarning?.Invoke("The Entity is not associated to any Diagram.");
                    }
                }
            }
Пример #2
0
        public bool Execute(IIdentity identity)
        {
            bool result = false;

            if (identity is IEntity entity && entity.Model is IThreatModel model)
            {
                using (var dialog = new DiagramSelectionDialog(entity))
                {
                    if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        var diagram = dialog.Diagram;
                        if (diagram == null)
                        {
                            diagram = model.AddDiagram(dialog.DiagramName);
                        }

                        if (diagram != null)
                        {
                            var schemaManager = new AssociatedDiagramPropertySchemaManager(model);
                            var propertyType  = schemaManager.GetAssociatedDiagramIdPropertyType();
                            if (propertyType != null)
                            {
                                var property = entity.GetProperty(propertyType);
                                if (property == null)
                                {
                                    property = entity.AddProperty(propertyType, diagram.Id.ToString("N"));
                                }
                                else
                                {
                                    property.StringValue = diagram.Id.ToString("N");
                                }

                                result = true;
                                DiagramAssociationHelper.NotifyDiagramAssociation(entity, diagram);
                                var factory = ExtensionUtils.GetExtensionByLabel <IPanelFactory>("Diagram");
                                if (factory != null)
                                {
                                    OpenPanel?.Invoke(factory, diagram);
                                    ShowMessage?.Invoke("Diagram has been associated successfully.");
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }