示例#1
0
        private ILink CreateLink([NotNull] GraphLink glink, [NotNull] GraphEntity source, [NotNull] GraphEntity target)
        {
            ILink result = null;

            var dataFlow = _diagram.Model?.AddDataFlow(glink.Text, source.EntityShape.AssociatedId,
                                                       target.EntityShape.AssociatedId);

            if (dataFlow == null)
            {
                dataFlow = _diagram.Model?.GetDataFlow(source.EntityShape.AssociatedId,
                                                       target.EntityShape.AssociatedId);
                if (dataFlow != null)
                {
                    result = _diagram.GetLink(dataFlow.Id);
                    if (result == null)
                    {
                        result = _diagram.AddLink(dataFlow);
                    }
                }
                else
                {
                    ShowWarning?.Invoke("The Flow in the Diagram is in an inconsistent status. Please close the Diagram and try again.");
                }
            }
            else
            {
                result = _diagram.AddLink(dataFlow);
            }

            return(result);
        }
示例#2
0
        private void RemoveRegisteredEvents(GraphEntity node)
        {
            node.SelectedShape       -= OnSelectedShape;
            node.SelectedThreatEvent -= OnSelectedThreatEvent;
            node.OpenDiagram         -= OnOpenDiagram;

            if (node.EntityShape?.Identity is IThreatEventsContainer container)
            {
                container.ThreatEventAdded   -= OnThreatEventAddedToShape;
                container.ThreatEventRemoved -= OnThreatEventRemovedFromShape;
            }

            node.Dispose();
        }
示例#3
0
        private GoNode AddShape([NotNull] IShape shape)
        {
            GoNode result = null;

            GraphGroup parent = null;

            if (shape.Identity is IGroupElement child)
            {
                _groups.TryGetValue(child.ParentId, out parent);
            }

            if (shape is IEntityShape entityShape)
            {
                var node = new GraphEntity(entityShape, _dpiState);
                if (_actions != null)
                {
                    node.SetContextAwareActions(_actions);
                }
                node.SelectedShape       += OnSelectedShape;
                node.SelectedThreatEvent += OnSelectedThreatEvent;
                node.OpenDiagram         += OnOpenDiagram;
                if (parent == null)
                {
                    _graph.Doc.Add(node);
                }
                else
                {
                    parent.Add(node);
                }
                _entities.Add(shape.AssociatedId, node);

                node.Validate();

                result = node;
            }
            else if (shape is IGroupShape groupShape)
            {
                var group = new GraphGroup(groupShape, _dpiState);
                if (_actions != null)
                {
                    group.SetContextAwareActions(_actions);
                }
                group.SelectedShape += OnSelectedShape;
                if (parent == null)
                {
                    _graph.Doc.Add(group);
                }
                else
                {
                    parent.Add(group);
                }
                _groups.Add(shape.AssociatedId, group);

                group.Validate();

                result = group;
            }

            if (shape.Identity is IThreatEventsContainer container)
            {
                container.ThreatEventAdded   += OnThreatEventAddedToShape;
                container.ThreatEventRemoved += OnThreatEventRemovedFromShape;
            }

            return(result);
        }
示例#4
0
 private void Validate(GraphEntity graphEntity)
 {
     graphEntity?.Validate();
 }