Пример #1
0
        private void MoveOutgoingDataFlow(IEntity target, IThreatModel model, IDiagram diagram, IDataFlow flow)
        {
            var newFlow = model.AddDataFlow(flow.Name, target.Id, flow.TargetId);

            CopyFlowDetails(flow, newFlow);
            if (diagram != null)
            {
                DataFlowAddingRequired?.Invoke(diagram, newFlow);
            }
            model.RemoveDataFlow(flow.Id);
        }
Пример #2
0
        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);
        }