/// <summary>
 /// Called as the user continues to drag the connection.
 /// </summary>
 public void ConnectionDragging(Point curDragPoint, AConnectionViewModel connection)
 {
     if (connection.DestConnector == null)
     {
         connection.DestConnectorHotspot = curDragPoint;
     }
     else
     {
         connection.SourceConnectorHotspot = curDragPoint;
     }
 }
 /// <summary>
 /// Utility method to delete a connection from the view-model.
 /// </summary>
 public void DeleteConnection(AConnectionViewModel connection)
 {
     this.Network.Connections.Remove(connection);
 }
        /// <summary>
        /// Called when the user has finished dragging out the new connection.
        /// Only one left- right connection is allowed
        /// invalid connections are removed
        /// </summary>
        ///
        public void ConnectionDragCompleted(AConnectionViewModel newConnection, ConnectorViewModel connectorDraggedOut, ConnectorViewModel connectorDraggedOver)
        {
            if (connectorDraggedOver == null)
            {
                //
                // The connection was unsuccessful.
                // Maybe the user dragged it out and dropped it in empty space.
                //
                Network.Connections.Remove(newConnection);
                return;
            }


            var  validPathConnection = IsValidPathConnection(connectorDraggedOut, connectorDraggedOver);
            bool connectionOk        = validPathConnection ||
                                       IsValidInputOutputConnection(connectorDraggedOut, connectorDraggedOver);

            if (!connectionOk)
            {
                Network.Connections.Remove(newConnection);
                return;
            }

            if (validPathConnection)
            {
                var isConnectingFromLeftToRight = connectorDraggedOut.Name == NodeViewModel.DefaultRightNodeConnectorName;

                var sourceConnector = isConnectingFromLeftToRight ? connectorDraggedOut : connectorDraggedOver;
                var destConnector   = isConnectingFromLeftToRight ? connectorDraggedOver : connectorDraggedOut;

                var sourceRightConnection     = sourceConnector.ParentNode.RightNodeConnection;
                var destinationLeftConnection = destConnector.ParentNode.LeftNodeConnection;


                if (sourceRightConnection != null && sourceRightConnection.IsConnected)
                {
                    var existingConnection = sourceRightConnection.AttachedConnections.Single(c => c.DestConnector != null);
                    Network.Connections.Remove(existingConnection);
                }

                if (destinationLeftConnection != null && destinationLeftConnection.IsConnected)
                {
                    var existingConnection = destinationLeftConnection.AttachedConnections.Single(c => c.SourceConnector != null);
                    Network.Connections.Remove(existingConnection);
                }
            }
            else
            {
                //
                // Remove any existing connection between the same two connectors.
                //
                var existingConnection = FindConnection(connectorDraggedOut, connectorDraggedOver);
                if (existingConnection != null)
                {
                    Network.Connections.Remove(existingConnection);
                }
            }

            //
            // Finalize the connection by attaching it to the connector
            // that the user dragged the mouse over.
            //
            if (newConnection.DestConnector == null)
            {
                newConnection.DestConnector = connectorDraggedOver;
            }
            else
            {
                newConnection.SourceConnector = connectorDraggedOver;
            }
        }