Exemplo n.º 1
0
        /// <summary>
        /// Usado para saver origen y destino en una conexión cuando el usuario lanza un evento MousseUp en un objeto IConnection.
        /// </summary>
        /// <param name="iConnection">Objeto IConnection a ser conectado.</param>
        private void ProcessConnection(IConnection iConnectable)
        {
            if (iConnectable == null)
            {
                throw new ArgumentNullException("iConnectable", "iConnectable can not be null.");
            }

            if (iconnectableFrom == null)
            {
                // Verificar que no se hayan cometido errores.
                Error errorSingleOutput = ServiceDocument.VerifySingleOutputConnection(iConnectable.Component);
                if (errorSingleOutput != null)
                {
                    Dialog.ShowErrorDialog(SilverlightVisualDesigners.Properties.Resources.Error, errorSingleOutput.Description, this.LayoutRoot);
                    return;
                }

                MenuFormSilverlight iConnectableSL = iConnectable as MenuFormSilverlight;
                if (iConnectableSL != null)
                {
                    if (iConnectableSL.ClickedMenuItem == null)
                    {
                        Dialog.ShowErrorDialog(SilverlightVisualDesigners.Properties.Resources.InvalidConnectionError, SilverlightVisualDesigners.Properties.Resources.InvalidConnection_MenuItemMustBeSourceInMenu, this.LayoutRoot);
                        return;
                    }
                    iconnectableFrom = iConnectableSL.ClickedMenuItem;
                }
                else
                {
                    iconnectableFrom = iConnectable;
                }

                // Recordar que un objeto MenuItem tiene a su widget como un Component.
                serviceDocument.ConnectionWidgetFrom = iconnectableFrom.Component;
            }
            else if (iConnectable != iconnectableFrom)
            {
                iconnectableTarget = iConnectable;
                serviceDocument.ConnectionWidgetTarget = iconnectableTarget.Component;

                Error connectionError = serviceDocument.CheckDuplicatedConnection();
                if (connectionError != null)
                {
                    Dialog.ShowErrorDialog(SilverlightVisualDesigners.Properties.Resources.Error, connectionError.Description, this.LayoutRoot);
                    isMakeConnectionAction = false;
                    return;
                }

                Collection <Error> connectionErrors = serviceDocument.CheckConnection();

                if (connectionErrors.Count > 0)
                {
                    Dialog.ShowErrorDialog(SilverlightVisualDesigners.Properties.Resources.Error, connectionErrors[0].Description, this.LayoutRoot);
                    isMakeConnectionAction = false;
                    return;
                }

                Collection <Error> errors = serviceDocument.VerifyConnection();
                if (errors.Count > 0)
                {
                    Dialog.ShowErrorDialog(SilverlightVisualDesigners.Properties.Resources.Error, errors[0].Description, this.LayoutRoot);
                    isMakeConnectionAction = false;
                    return;
                }

                // Verificar si se puede asignar el contexto.
                CreateConnection(iconnectableFrom, iconnectableTarget);
                isMakeConnectionAction = false;
            }
        }