Beispiel #1
0
        private void DoExecute()
        {
            CommandDescriptor commandDescriptor =
                PublicCommandsHelper.GetCommandDescriptor(ControllerCommandType);

            commandDescriptor.ClearParameterValues();
            OperationParametersControlCreator.ReadParameterValues(commandDescriptor, controls);
            foreach (ParameterDescriptor parameterDescriptor in commandDescriptor.Parameters)
            {
                if (parameterDescriptor.ParameterPropertyInfo == commandDescriptor.ScopeProperty)
                {
                    parameterDescriptor.ParameterValue = ((ExolutioObject)this.ScopeObject).ID;
                }
            }
            CreateControllerCommand();
            CommandSerializer.FillParameters(ControllerCommand, commandDescriptor);
            ControllerCommand.CanExecuteChanged -= OnControllerCommandCanExecuteChanged;
            if (!ControllerCommand.CanExecute())
            {
#if SILVERLIGHT
                ExolutioErrorMsgBox.Show("Command can not be executed", ControllerCommand.ErrorDescription);
#else
                ExolutioErrorMsgBox.Show("Command can not be executed", ControllerCommand.ErrorDescription);
#endif
            }
            else
            {
                if (ControllerCommand is StackedCommand)
                {
                    if (((StackedCommand)ControllerCommand).Controller == null)
                    {
                        ((StackedCommand)ControllerCommand).Controller = Current.Controller;
                    }
                }
                try
                {
                    ControllerCommand.Execute();
                }
                catch (ExolutioCommandException e)
                {
                    ExolutioErrorMsgBox.Show("Command " + e.Command.GetType().ToString() + " can not be executed", e.Command.ErrorDescription);
                }
            }
            ControllerCommand = null;
        }
Beispiel #2
0
        public override void Execute(object parameter)
        {
            if (ScopeIsSelectedComponent && AcceptedSelectedComponentType != null && Current.ActiveDiagramView.IsSelectedComponentOfType(AcceptedSelectedComponentType))
            {
                ScopeObject = Current.ActiveDiagramView.GetSelectedComponents().First();
            }

            CommandDialogWindow w = null;

            dialogOpened = false;
            controls     = new List <Control>();

            #region substitute scope with diagram
            if (ScopeObject == null && Diagram != null)
            {
                CommandDescriptor commandDescriptor = PublicCommandsHelper.GetCommandDescriptor(ControllerCommandType);
                if (string.IsNullOrEmpty(ControllerCommandDescription))
                {
                    ControllerCommandDescription = commandDescriptor.CommandDescription;
                }
                commandDescriptor.ClearParameterValues();
                OperationParametersControlCreator.ReadParameterValues(commandDescriptor, controls);
                foreach (ParameterDescriptor parameterDescriptor in commandDescriptor.Parameters)
                {
                    if (parameterDescriptor.ParameterPropertyInfo == commandDescriptor.ScopeProperty)
                    {
                        if (parameterDescriptor.ComponentType != null &&
                            typeof(Diagram).IsAssignableFrom(parameterDescriptor.ComponentType))
                        {
                            ScopeObject = Diagram;
                        }

                        if (parameterDescriptor.ComponentType == typeof(PSMSchema) && Diagram is PSMDiagram)
                        {
                            ScopeObject = Diagram.Schema;
                        }
                    }
                }
            }
            #endregion

            if (OpenDialog)
            {
                w = new CommandDialogWindow();
                MenuHelper.CreateDialogControlsForCommand(ControllerCommandType, (ExolutioObject)ScopeObject, ProjectVersion, w.spParameters,
                                                          out controls);

                if (Diagram != null)
                {
                    foreach (Control control in controls)
                    {
                        ParameterControls.GuidLookup guidLookup = control as ParameterControls.GuidLookup;
                        if (guidLookup != null)
                        {
                            if (guidLookup.LookedUpType == typeof(PSMSchema) && Diagram is PSMDiagram)
                            {
                                guidLookup.SetSuggestedValue(Diagram.Schema);
                                guidLookup.Tag = "valueSuggested";
                                break;
                            }
                        }
                    }
                }

                w.lTitle.Content = ControllerCommandDescription;
                if (NoScope)
                {
                    w.lTarget.Content = " (global command) ";
                }
                else
                {
                    w.lTarget.Content = ScopeObject.ToString();
                }
            }

            bool dialogOk = !OpenDialog;

            if (!dialogOk)
            {
#if SILVERLIGHT
                //Current.MainWindow.FloatingWindowHost.Add(w);
                w.Closed += new EventHandler(w_Closed);
                w.Show();
#else
                w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                //w.ShowDialog();
                w.WindowStyle   = WindowStyle.ToolWindow;
                w.Topmost       = true;
                w.ShowInTaskbar = false;
                w.ShowActivated = true;
                Current.MainWindow.DisableCommands();
                w.Show();
                w.Closed += w_Closed;
#endif
                dialogOpened = true;
            }
            else
            {
                DoExecute();
            }

            //if (!OpenDialog || dialogOk)
            //{
            //    DoExecute();
            //}
        }