コード例 #1
0
 private void OnCommandChange(CommandType commandType)
 {
     if (CommandChanged != null)
     {
         CommandChanged.Invoke(commandType);
     }
 }
コード例 #2
0
 private void FireChangeEvent()
 {
     if (CommandChanged != null)
     {
         CommandChanged.Invoke(this, EventArgs.Empty);
     }
 }
コード例 #3
0
ファイル: MenuCommand.cs プロジェクト: rsumner31/corefx2
 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")] // Safe: FullTrust LinkDemand to instantiate an object of this class.
 protected virtual void OnCommandChanged(EventArgs e)
 {
     CommandChanged?.Invoke(this, e);
 }
コード例 #4
0
        /// <summary>
        /// Run the command
        /// </summary>
        /// <returns>Whether or not it succeeded</returns>
        public bool ExecuteCommand(Command command, string contextID)
        {
            _command = command;
            CommandChanged?.Invoke(this, new CommandChangedArgs(_command));
            _contextID = contextID;
            bool success = false;

            if (_command.Type == CommandType.Prompt)
            {
                // Determine the type of the prompt
                string promptType = _command.Parameter("Type");

                // File
                if (promptType.EqualsInvariant("File"))
                {
                    success = ExecutePromptPathAlias(
                        _command.Parameter <bool>("IsGlobal"),
                        true,
                        _command.Parameter("AliasName"),
                        _command.Parameter("DisplayName"),
                        _command.ParameterArray("DefaultPaths"));
                }
                // Directory
                else if (promptType.EqualsInvariant("Dir"))
                {
                    success = ExecutePromptPathAlias(
                        _command.Parameter <bool>("IsGlobal"),
                        false,
                        _command.Parameter("AliasName"),
                        _command.Parameter("DisplayName"),
                        _command.ParameterArray("DefaultPaths"));
                }
                // String
                else if (promptType.EqualsInvariant("String"))
                {
                    success = ExecutePromptStringAlias(
                        _command.Parameter <bool>("IsGlobal"),
                        _command.Parameter("AliasName"),
                        _command.Parameter("DisplayName"));
                }
                // YesNo
                else
                {
                    success = ExecutePrompt(
                        _command.Parameter("Message"));
                }
            }
            else if (_command.Type == CommandType.ChangeDir)
            {
                success = ExecuteChangeDir(
                    _command.Parameter("Path"));
            }
            else if (_command.Type == CommandType.CheckExists)
            {
                success = ExecuteCheckExists(
                    _command.Parameter("Path"));
            }
            else if (_command.Type == CommandType.Copy)
            {
                string source  = _command.Parameter("Source");      // is null if multiple
                var    sources = _command.ParameterArray("Source"); // is null if single

                // Determine source
                if (sources.AnySafe())
                {
                    var sourcesTrimmed = sources.StripCommonStart().ToArray();
                    int sourceIndex    =
                        _windowService.ShowComboSelectWindowAsync(Localization.Current.Command_Copy_SelectSource,
                                                                  sourcesTrimmed).GetResult();
                    source = sources[sourceIndex];
                }

                success = ExecuteCopy(
                    source,
                    _command.Parameter("Destination"));
            }
            else if (_command.Type == CommandType.Execute)
            {
                success = ExecuteCmd(
                    _command.Parameter("Cmd"),
                    _command.Parameter("Args"));
            }

            // Logging
            var parametersPretty = _command.Parameters.Properties().Select(p => $"\t{p.Name}:{p.Value}");

            Logger.Record($"Command executed {(success ? "successfully" : "unsuccessfully")}" + Environment.NewLine +
                          $"Type: {_command.Type}" + Environment.NewLine +
                          $"Parameters:" + Environment.NewLine +
                          $"{parametersPretty.JoinToString(Environment.NewLine)}");

            return(success);
        }
コード例 #5
0
        public void ChangeCommand(int algorithmNumber, int actionNumber, int commandNumber, Command command)
        {
            algorithms[algorithmNumber].actions[actionNumber].commands[commandNumber] = command;

            CommandChanged?.Invoke(this, new ChangeCommandEventArgs());
        }