public bool Execute(IIdentity identity) { bool result = false; // ReSharper disable once SuspiciousTypeConversion.Global if (identity is IDiagram diagram) { var interactor = diagram.Model?.AddEntity <IExternalInteractor>(); IdentityAddingRequired?.Invoke(diagram, interactor, PointF.Empty, SizeF.Empty); result = true; } else if (identity is IThreatModel threatModel) { threatModel.AddEntity <IExternalInteractor>(); result = true; } return(result); }
public bool Execute(IIdentity identity) { bool result = false; // ReSharper disable once SuspiciousTypeConversion.Global if (identity is IDiagram diagram) { var trustBoundary = diagram.Model?.AddGroup <ITrustBoundary>(); IdentityAddingRequired?.Invoke(diagram, trustBoundary, PointF.Empty, new SizeF(600, 300)); result = true; } else if (identity is IThreatModel threatModel) { threatModel.AddGroup <ITrustBoundary>(); result = true; } return(result); }
public bool Execute(IIdentity identity) { bool result = false; // ReSharper disable once SuspiciousTypeConversion.Global if (identity is IDiagram diagram) { if (Clipboard.GetDataObject() is DataObject dataObject && dataObject.GetDataPresent("ShapesInfo") && dataObject.GetData("ShapesInfo") is string shapesInfo) { var deserialized = JsonConvert.DeserializeObject <ShapesInfo>(shapesInfo, new JsonSerializerSettings() { #pragma warning disable SCS0028 // Type information used to serialize and deserialize objects #pragma warning disable SEC0030 // Insecure Deserialization - Newtonsoft JSON TypeNameHandling = TypeNameHandling.All #pragma warning restore SEC0030 // Insecure Deserialization - Newtonsoft JSON #pragma warning restore SCS0028 // Type information used to serialize and deserialize objects }); var shapes = deserialized?.Shapes? .Where(x => (x.Identity as IThreatModelChild)?.Model == diagram.Model) .ToArray(); if (shapes?.Any() ?? false) { float x = shapes.Min(t => t.Position.X); float y = shapes.Min(t => t.Position.Y); var groups = new List <IGroup>(); foreach (var shape in shapes) { if (shape is IEntityShape && shape.Identity is IEntity entity && diagram.GetShape(entity) == null) { result = true; IdentityAddingRequired?.Invoke(diagram, entity, new PointF(shape.Position.X - x, shape.Position.Y - y), SizeF.Empty); RecursivelyAddParents(entity, groups); } } foreach (var shape in shapes) { if (shape is IGroupShape groupShape && shape.Identity is IGroup group && !groups.Contains(group)) { result = true; IdentityAddingRequired?.Invoke(diagram, group, new PointF(shape.Position.X - x, shape.Position.Y - y), groupShape.Size); } } var links = deserialized?.Links? .Where(l => l.DataFlow?.Model == diagram.Model) .ToArray(); if (links?.Any() ?? false) { foreach (var link in links) { result = true; DataFlowAddingRequired?.Invoke(diagram, link.DataFlow); } } } else { ShowMessage?.Invoke("There is nothing to paste."); } } } return(result); }