コード例 #1
0
        public void SaveElementPosition(GroupableNode node, Point?point)
        {
            if (ShapePositions.Any(x => x.Key == node.Id))
            {
                ShapePositions.Remove(node.Id);
            }

            if (point.HasValue)
            {
                ShapePositions.Add(node.Id, point.Value);
            }

            // Saving into file
            if (this.FilePath != null)
            {
                try
                {
                    var fileContent = JsonConvert.SerializeObject(this.ShapePositions);
                    File.WriteAllText(this.FilePath, fileContent);
                }
                catch (Exception ex)
                {
                    tracer.Error(ex, "Cannot save shape positions to DiagramShapePositions.json.");
                }
            }
        }
コード例 #2
0
        private List <GroupableNode> GetComponentsMessagesRelatedNodes(GroupableNode node)
        {
            var relatedNodes = new List <GroupableNode>();

            relatedNodes.Add(node);

            var nodeConnections = this.Connections.Cast <BaseConnection>()
                                  .Where(x => x.Source == node ||
                                         x.Target == node)
                                  .ToList();

            foreach (var nodeConnection in nodeConnections)
            {
                var nodeElement = default(GroupableNode);
                if (nodeConnection.Source == node)
                {
                    nodeElement = this.Nodes.Cast <GroupableNode>().FirstOrDefault(x => x == nodeConnection.Target);
                }
                else
                {
                    nodeElement = this.Nodes.Cast <GroupableNode>().FirstOrDefault(x => x == nodeConnection.Source);
                }

                relatedNodes.Add(nodeElement);
            }

            return(relatedNodes);
        }
コード例 #3
0
        public void DeleteNode(GroupableNode node)
        {
            // Remove Node from Parent
            if (node.ParentNode != null)
            {
                node.ParentNode.RemoveChild(node);
            }

            // Remove child nodes
            var groupNode = node as GroupNode;

            if (groupNode != null)
            {
                groupNode.ChildNodes.ForEach(x => DeleteNode(x));
            }

            this.LayoutAlgorithm.RemoveElementPosition(node);
            // Remove node
            this.Nodes.Remove(node);

            // Unhandle events
            node.ActivateElement -= Node_ActivateElement;

            node = null;
        }
コード例 #4
0
        private Point CalculateElementPosition(GroupableNode node)
        {
            var x = 50.0;
            var y = 100.0;

            if (node is EndpointNode)
            {
                var leftAlignment  = GetYPosition(Endpoint_LeftAlignment);
                var rightAlignment = GetYPosition(Endpoint_RightAlignment);

                if (leftAlignment <= rightAlignment)
                {
                    x = Endpoint_LeftAlignment;
                }
                else
                {
                    x = Endpoint_RightAlignment;
                }
            }
            else if (node is CommandNode || node is EventNode)
            {
                x = Message_Alignment;
            }

            y = GetYPosition(x);

            return(new Point(x, y));
        }
コード例 #5
0
        public Point?LoadElementPosition(GroupableNode node)
        {
            if (ShapePositions.Any(x => x.Key == node.Id))
            {
                return(ShapePositions.First(x => x.Key == node.Id).Value);
            }

            return(null);
        }
コード例 #6
0
        public Point?LoadElementPosition(GroupableNode node)
        {
            Debug.Assert(ShapePositions != null, "Shape positions not initialized");

            if (ShapePositions.Any(x => x.Key == node.Id))
            {
                return(ShapePositions.First(x => x.Key == node.Id).Value);
            }

            return(null);
        }
コード例 #7
0
        // ================ CONNECTIONS ==========================

        public CommandConnection GetOrCreateCommandConnection(GroupableNode sourceNode, GroupableNode targetNode)
        {
            var commandConnection = this.FindConnection(sourceNode, targetNode) as CommandConnection;

            if (commandConnection == null)
            {
                commandConnection = new CommandConnection(sourceNode, targetNode);
                this.Connections.Add(commandConnection);
            }

            return(commandConnection);
        }
コード例 #8
0
        public MessageConnection GetOrCreateMessageConnection(GroupableNode sourceNode, GroupableNode targetNode)
        {
            var messageConnection = this.FindConnection(sourceNode, targetNode) as MessageConnection;

            if (messageConnection == null)
            {
                messageConnection = new MessageConnection(sourceNode, targetNode);
                this.Connections.Add(messageConnection);
            }

            return(messageConnection);
        }
コード例 #9
0
        public EventConnection GetOrCreateEventConnection(GroupableNode sourceNode, GroupableNode targetNode)
        {
            var eventConnection = this.FindConnection(sourceNode, targetNode) as EventConnection;

            if (eventConnection == null)
            {
                eventConnection = new EventConnection(sourceNode, targetNode);
                this.Connections.Add(eventConnection);
            }

            return(eventConnection);
        }
コード例 #10
0
        public void SetElementPosition(GroupableNode node)
        {
            var position = this.LoadElementPosition(node);

            if (!position.HasValue)
            {
                position = this.CalculateElementPosition(node);
                this.SaveElementPosition(node, position.Value);
            }

            node.BoundsChanged += (s, e) => this.SaveElementPosition(node, node.Bounds.Location);
            node.Bounds         = new Rect(position.Value, node.Bounds.Size);
        }
コード例 #11
0
        public void UnhighlightNode(GroupableNode node)
        {
            if (node is ServiceNode)
            {
                var serviceRelatedNodes = GetServiceRelatedNodes(node);
                serviceRelatedNodes.ForEach(x => x.IsHighlighted = false);
            }
            else if (node is ComponentNode || node is MessageBaseNode)
            {
                var relatedNodes = GetComponentsMessagesRelatedNodes(node);
                relatedNodes.ForEach(x => x.IsHighlighted = false);
            }

            node.IsHighlighted = false;
        }
コード例 #12
0
        private List <GroupableNode> GetServiceRelatedNodes(GroupableNode node)
        {
            var service = node.InnerViewModel.Data.As <IService>();

            var nodesId = new List <Guid>();

            nodesId.Add(service.AsElement().Id);                                               // Service Id
            nodesId.AddRange(service.Components.Component.Select(x => x.AsElement().Id));      // Related Components Id
            nodesId.AddRange(service.Contract.Commands.Command.Select(x => x.AsElement().Id)); // Related Commands Id
            nodesId.AddRange(service.Contract.Events.Event.Select(x => x.AsElement().Id));     // Related Events Id

            var allNodes = this.Nodes.Cast <GroupableNode>()
                           .Where(x => nodesId.Contains(x.Id))
                           .ToList();

            return(allNodes);
        }
コード例 #13
0
        public void SaveElementPosition(GroupableNode node, Point?point)
        {
            if (ShapePositions.Any(x => x.Key == node.Id))
            {
                ShapePositions.Remove(node.Id);
            }

            if (point.HasValue)
            {
                ShapePositions.Add(node.Id, point.Value);
            }

            // Saving into file
            if (this.FilePath != null)
            {
                var fileContent = JsonConvert.SerializeObject(this.ShapePositions);
                File.WriteAllText(this.FilePath, fileContent);
            }
        }
コード例 #14
0
        public void DeleteNode(GroupableNode node)
        {
            // Remove Node from Parent
            if (node.ParentNode != null)
            {
                node.ParentNode.RemoveChild(node);
            }

            // Remove child nodes
            var groupNode = node as GroupNode;

            if (groupNode != null)
            {
                groupNode.ChildNodes.ToList().ForEach(x => DeleteNode(x));
            }

            // If It's a Component, Remove Empty Service
            if (node is ComponentNode &&
                node.ParentNode is ServiceNode &&
                node.ParentNode.ChildNodes.Count == 0)
            {
                this.DeleteNode(node.ParentNode);
            }

            // If It's a Service, Remove Empty Undeployed Endpoint
            if (node is ServiceNode &&
                node.ParentNode is EmptyEndpointNode &&
                node.ParentNode.ChildNodes.Count == 0)
            {
                this.DeleteNode(node.ParentNode);
            }

            // Remove Layout information
            this.LayoutAlgorithm.RemoveElementPosition(node);

            // Remove node
            this.Nodes.Remove(node);

            // Unhandle events
            node.ActivateElement -= Node_ActivateElement;

            node = null;
        }
コード例 #15
0
 private DiagramConnection FindConnection(GroupableNode source, GroupableNode target)
 {
     return(this.Connections.FirstOrDefault(x => source.ConnectionPoints.Any(y => y == x.FromConnectionPoint) &&
                                            target.ConnectionPoints.Any(y => y == x.ToConnectionPoint)));
 }
コード例 #16
0
 public void RemoveElementPosition(GroupableNode node)
 {
     this.SaveElementPosition(node, null);
 }
コード例 #17
0
 private void AddNode(GroupableNode node)
 {
     this.Nodes.Add(node);
     node.ActivateElement += Node_ActivateElement;
 }