private void AutoConnectShapes()
        {
            IShapeBase outputShape = null;

            foreach (var inputShape in this.SelectedShapes)
            {
                // If there is an outputShape and the relevant pins are enabled, connect them.
                if (outputShape != null && inputShape.IsInputPinEnabled && outputShape.IsOutputPinEnabled)
                {
                    ConnectionShape connectionShape = new ConnectionShape(inputShape, outputShape);

                    if (this.ConnectEBCs(connectionShape))
                    {
                        this.SetConnectionShapes(connectionShape);

                        this.AddShape(connectionShape);
                    }
                    else
                    {
                        this.IsMultiSelect = false;
                    }
                }

                outputShape = inputShape;
            }

            this.Out_PaintRequest();
        }
        private bool ConnectEBCs(ConnectionShape connection)
        {
            try
            {
                IShapeBase outputShape = connection.OutputShape;
                IShapeBase inputShape = connection.InputShape;

                IEBCBase outputEBC = this.ShapeToEBC[outputShape.ID];
                IEBCBase inputEBC = this.ShapeToEBC[inputShape.ID];

                this.Out_ConnectEBCs(new ConnectEBCMessage(outputEBC, inputEBC));

                return true;
            }
            catch (ShapeConnectionException shapeConnectionException)
            {
                this.CancelConnection();

                this.OnOut_ReportError(shapeConnectionException);

                return false;
            }
            catch (CircularConnectionException circularConnectionException)
            {
                this.CancelConnection();

                this.OnOut_ReportError(circularConnectionException);

                return false;
            }
        }
        private void DisconnectEBCs(ConnectionShape connectionShape)
        {
            IShapeBase outputShape = connectionShape.OutputShape;
            IShapeBase inputShape = connectionShape.InputShape;

            IEBCBase outputEBC = this.ShapeToEBC[outputShape.ID];
            IEBCBase inputEBC = this.ShapeToEBC[inputShape.ID];

            this.Out_DisconnectEBCs(new DisconnectEBCMessage(outputEBC, inputEBC));
        }
        private void SetConnectionShapes(ConnectionShape connectionShape)
        {
            // All start-connections: They are the start of an ebc message.
            if (!this.ConnectionStartShapes.ContainsKey(connectionShape.OutputShape))
            {
                List<ConnectionShape> connections = new List<ConnectionShape>();
                connections.Add(connectionShape);
                this.ConnectionStartShapes.Add(connectionShape.OutputShape, connections);
            }
            else
            {
                this.ConnectionStartShapes[connectionShape.OutputShape].Add(connectionShape);
            }

            // All end-connections: They are the target of an ebc message.
            if (!this.ConnectionEndShapes.ContainsKey(connectionShape.InputShape))
            {
                List<ConnectionShape> connections = new List<ConnectionShape>();
                connections.Add(connectionShape);
                this.ConnectionEndShapes.Add(connectionShape.InputShape, connections);
            }
            else
            {
                this.ConnectionEndShapes[connectionShape.InputShape].Add(connectionShape);
            }
        }