Beispiel #1
0
        public bool Execute(IIdentity identity)
        {
            bool result = false;

            if (identity is IEntity entity && entity.Model is IThreatModel model)
            {
                var schemaManager = new AssociatedDiagramPropertySchemaManager(model);
                var propertyType  = schemaManager.GetAssociatedDiagramIdPropertyType();
                if (propertyType != null)
                {
                    var property = entity.GetProperty(propertyType);
                    if (property is IPropertyIdentityReference identityReference &&
                        identityReference.Value is IDiagram diagram)
                    {
                        result = true;
                        var factory = ExtensionUtils.GetExtensionByLabel <IPanelFactory>("Diagram");
                        if (factory != null)
                        {
                            OpenPanel?.Invoke(factory, diagram);
                        }
                    }
                }
            }

            if (!result)
            {
                ShowWarning?.Invoke("The Entity is not associated to any Diagram.");
            }

            return(result);
        }
Beispiel #2
0
        public bool IsVisible(object item)
        {
            bool result = false;

            IThreatModel model = null;

            if (item is IThreatModelChild child)
            {
                model = child.Model;
            }
            else if (item is IThreatModel threatModel)
            {
                model = threatModel;
            }

            if (model != null && item is IPropertiesContainer container)
            {
                var schemaManager = new AssociatedDiagramPropertySchemaManager(model);
                var propertyType  = schemaManager.GetAssociatedDiagramIdPropertyType();
                if (propertyType != null)
                {
                    result = !string.IsNullOrWhiteSpace(container.GetProperty(propertyType)?.StringValue?.Trim('0'));
                }
            }

            return(result);
        }
Beispiel #3
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.");
                    }
                }
            }
        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);
        }
Beispiel #5
0
        private IDiagram GetAssociatedDiagram()
        {
            IDiagram result = null;

            if (_entity?.Model is IThreatModel model)
            {
                var schemaManager = new AssociatedDiagramPropertySchemaManager(model);
                var propertyType  = schemaManager.GetAssociatedDiagramIdPropertyType();
                if (propertyType != null)
                {
                    var property = _entity.GetProperty(propertyType);
                    if (property != null && Guid.TryParse(property.StringValue, out var id))
                    {
                        result = model.GetDiagram(id);
                    }
                }
            }

            return(result);
        }
Beispiel #6
0
 private void OnModelChildRemoved([NotNull] IIdentity identity)
 {
     if (identity is IDiagram diagram && _entity != null && _entity.Model is IThreatModel model)
     {
         var schemaManager = new AssociatedDiagramPropertySchemaManager(model);
         var propertyType  = schemaManager.GetAssociatedDiagramIdPropertyType();
         if (propertyType != null)
         {
             if (_entity.GetProperty(propertyType) is IPropertyIdentityReference property)
             {
                 var associatedDiagramId = property.ValueId;
                 if (diagram.Id == associatedDiagramId)
                 {
                     property.Value = null;
                     _visible       = false;
                     Visible        = false;
                 }
             }
         }
     }
 }