コード例 #1
0
        public void WorksWithBlankString()
        {
            string    s = string.Empty;
            MacroItem m = new MacroItem(s);

            Assert.IsTrue(m.Label == string.Empty);
            Assert.IsTrue(m.CommandList.Count == 0);
            Assert.IsTrue(m.ToString() == ",");
        }
コード例 #2
0
        public void WorksWithSingleValueString()
        {
            string    s = "Hi";
            MacroItem m = new MacroItem(s);

            Assert.IsTrue(m.Label == "Hi");
            Assert.IsTrue(m.CommandList.Count == 0);
            Assert.IsTrue(m.ToString() == "Hi,");
        }
コード例 #3
0
        public void WorksWithSingleCommandString()
        {
            string    s = "Hi,Command1";
            MacroItem m = new MacroItem(s);

            Assert.IsTrue(m.Label == "Hi");
            Assert.IsTrue(m.CommandList.Count == 1);
            Assert.IsTrue(m.CommandList[0] == "Command1");
            Assert.IsTrue(m.ToString() == s);
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: EWouters/MagicTile
        internal Macro SelectedMacro()
        {
            MacroItem i = SelectedMacroItem();

            if (i == null)
            {
                return(null);
            }
            return(i.Macro);
        }
コード例 #5
0
        public void WhitespaceAndCRLFAreDropped()
        {
            string    s = "Hi,Command1,, ,\r,\n,\r\n, \r\n,Command2,Command3";
            MacroItem m = new MacroItem(s);

            Assert.IsTrue(m.Label == "Hi");
            Assert.IsTrue(m.CommandList.Count == 3);
            Assert.IsTrue(m.CommandList[0] == "Command1");
            Assert.IsTrue(m.CommandList[1] == "Command2");
            Assert.IsTrue(m.CommandList[2] == "Command3");
            Assert.IsTrue(m.ToString() == "Hi,Command1,Command2,Command3");
        }
コード例 #6
0
        public void WorksWithMultipleCommandString()
        {
            string    s = "Hi,Command1,Command2,Command3";
            MacroItem m = new MacroItem(s);

            Assert.IsTrue(m.Label == "Hi");
            Assert.IsTrue(m.CommandList.Count == 3);
            Assert.IsTrue(m.CommandList[0] == "Command1");
            Assert.IsTrue(m.CommandList[1] == "Command2");
            Assert.IsTrue(m.CommandList[2] == "Command3");
            Assert.IsTrue(m.ToString() == s);
        }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: EWouters/MagicTile
        private void DeleteSelectedMacro()
        {
            MacroItem i = SelectedMacroItem();

            if (i == null)
            {
                return;
            }

            int idx = i.Index;

            m_puzzle.MacroList.Macros.Remove(i.Macro);
            m_macroListView.Items.Remove(i);
            UpdateEnabled();
        }
コード例 #8
0
ファイル: MainForm.cs プロジェクト: Lothrazar/MagicTile
        private void m_btnDelete_Click(object sender, EventArgs e)
        {
            MacroItem i = SelectedMacroItem();

            if (i == null)
            {
                return;
            }

            int idx = i.Index;

            m_puzzle.MacroList.Macros.Remove(i.Macro);
            m_macroListView.Items.Remove(i);
            UpdateEnabled();
        }
コード例 #9
0
ファイル: TerminalParser.cs プロジェクト: haohanl/ScriptExNeo
        /// <summary>
        /// Validate commands string and convert into individual items.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static List <string> ParseCommands(string input, ModeConfig mode)
        {
            // Initialise new list
            List <string> _cmdlist = new List <string>();

            // Check for shell calls with parameters
            if (IsValidFullInvoke(input))
            {
                _cmdlist.Add(input);
                return(_cmdlist);
            }

            // Simulate current mode and mode switches
            ModeConfig _curMode = mode;

            // Check each command item
            foreach (string _cmd in input.Trim().Split(' '))
            {
                // Ignore empty entries
                if (_cmd == "")
                {
                    continue;
                }
                // Check for batch commands
                if (IsValidBatchKey(_cmd))
                {
                    _cmdlist.Add(_cmd);
                    continue;
                }

                // Check for mode changes
                if (IsValidModeSwitch(_cmd))
                {
                    _cmdlist.Add(_cmd);
                    _curMode = TerminalMode.GetMode(_cmd);
                    continue;
                }

                // Check for invoke command
                if (IsValidInvoke(_cmd))
                {
                    _cmdlist.Add(_cmd);
                    continue;
                }

                // Check for valid macro
                if (IsValidMacro(_cmd))
                {
                    MacroItem _macro = Program.Config.Macros[_cmd];
                    // Check for infinite recursion
                    if (_macro.Command.Contains(_cmd))
                    {
                        throw new BadConfigException($"Macro {_cmd} references self. Unable to resolve.");
                    }
                    // Generate mode key
                    string _mode = $"{Program.Config.Program.ModeKey}{_macro.SetMode} ";

                    // Recursively resolve macro
                    _cmdlist.AddRange(ParseCommands(_mode + _macro.Command, _curMode));
                    continue;
                }

                // Check for valid command
                if (IsValidCommand(_cmd, _curMode))
                {
                    _cmdlist.Add(_cmd);
                    continue;
                }

                // Write to terminal of invalid command
                Terminal.WriteError(
                    $"'{_cmd}' is not a valid command in '{TerminalMode.GetModeName(_curMode)} Mode'."
                    );

                // No valid command has been found.
                // If not ignoring, return null
                if (!Program.Config.Program.SkipInvalidCommands)
                {
                    return(null);
                }
            }

            return(_cmdlist);
        }
コード例 #10
0
 public MacroEditWindow(MacroItem macro)
 {
     InitializeComponent();
     MacroEditWindowHandlers.Init(this);
     Macro = macro;
 }
コード例 #11
0
        private void DoneBtn_Click(object sender, RoutedEventArgs e)
        {
            if (CheckForEmtpyTextbox(nameTb))
            {
                return;
            }
            if (CheckForEmtpyTextbox(hotkeyTb))
            {
                return;
            }

            if (launchProcRb.IsChecked.Value)
            {
                if (CheckForEmtpyTextbox(lp_procPathTb))
                {
                    return;
                }
            }
            else if (sendKeysRb.IsChecked.Value)
            {
                if (CheckForEmtpyTextbox(sK_KeystrokeTb))
                {
                    return;
                }
            }
            else if (sendKeycodeRb.IsChecked.Value)
            {
                if (CheckForEmtpyTextbox(sKc_KeycodeTb))
                {
                    return;
                }
            }
            else if (sendHttpRequestRb.IsChecked.Value)
            {
                if (CheckForEmtpyTextbox(sHr_URLTb))
                {
                    return;
                }
            }

            IMacroAction action = null;

            if (launchProcRb.IsChecked.Value)
            {
                action = new LaunchProcessMacro(nameTb.Text, lp_procPathTb.Text, lp_procArgsTb.Text, lp_procStartPathTb.Text, lp_adminTBtn.IsChecked.Value);
            }
            else if (sendKeysRb.IsChecked.Value)
            {
                action = new SendKeysMacro(nameTb.Text, sK_KeystrokeTb.Text);
            }
            else if (sendKeycodeRb.IsChecked.Value)
            {
                action = new SendKeycodeMacro(nameTb.Text, int.Parse(sKc_KeycodeTb.Text));
            }
            else if (sendHttpRequestRb.IsChecked.Value)
            {
                action = new HttpRequestMacro(nameTb.Text, sHr_URLTb.Text, sHr_MethodTb.IsChecked.Value ? HttpRequestMacro.RequestMethod.POST : HttpRequestMacro.RequestMethod.GET, sHr_clipboardCb.IsChecked.Value);
            }
            MacroItem item = new MacroItem((Key)Enum.Parse(typeof(Key), hotkeyTb.Text), action);

            if (IsEditWindow)
            {
                Variables.Macros[Variables.Macros.IndexOf(Macro)] = item;
            }
            else
            {
                Variables.Macros.Add(item);
            }
            ConfigManager.StoreObject(Variables.Macros, Constants.MacrosPath);
            this.Close();
        }