private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); CommandEditDialog dialog = new CommandEditDialog(new ControlLabel()); dialog.ShowDialog(); Processor commandProcessor = new Processor(BlastIr, new string[] {"Default", "Port 1"}); string[] categories = new string[] { Processor.CategoryControl, Processor.CategoryVariable, Processor.CategoryStack, Processor.CategoryGeneral, Processor.CategoryMediaPortal, Processor.CategoryIRCommands, Processor.CategoryMacros, Processor.CategorySpecial }; try { EditMacro edit1 = new EditMacro( commandProcessor, @"C:\Documents and Settings\All Users.WINDOWS\Application Data\IR Server Suite\MP Blast Zone Plugin\Macro\", categories); edit1.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } try { EditMacro edit2 = new EditMacro( commandProcessor, @"C:\Documents and Settings\All Users.WINDOWS\Application Data\IR Server Suite\MP Blast Zone Plugin\Macro\", categories, @"C:\Documents and Settings\All Users.WINDOWS\Application Data\IR Server Suite\MP Blast Zone Plugin\Macro\Toggle Example.Macro"); edit2.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Creates a Macro Editor windows form. /// </summary> /// <param name="commandProcessor">The command processor.</param> /// <param name="macroFolder">The macro folder.</param> /// <param name="categories">The command categories to include.</param> /// <param name="fileName">Full path to the macro file.</param> public EditMacro(Processor commandProcessor, string macroFolder, string[] categories, string fileName) { if (commandProcessor == null) throw new ArgumentNullException("commandProcessor"); if (String.IsNullOrEmpty(macroFolder)) throw new ArgumentNullException("macroFolder"); if (categories == null) throw new ArgumentNullException("categories"); if (String.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName"); InitializeComponent(); _commandProcessor = commandProcessor; _macroFolder = macroFolder; _fileName = fileName; string macroPath = Path.GetDirectoryName(_fileName); string macroFile = Path.GetFileNameWithoutExtension(_fileName); string macroName = Path.Combine(macroPath, macroFile); if (macroName.StartsWith(_macroFolder, StringComparison.OrdinalIgnoreCase)) macroName = macroName.Substring(_macroFolder.Length); if (macroName.StartsWith(Common.FolderAppData, StringComparison.OrdinalIgnoreCase)) macroName = macroName.Substring(Common.FolderAppData.Length); textBoxName.Text = macroName; textBoxName.Enabled = false; Macro macro = new Macro(_fileName); foreach (Command command in macro.Commands) { ListViewItem item = new ListViewItem(command.GetUserDisplayText()); item.Tag = command.ToString(); listViewMacro.Items.Add(item); } PopulateCommandList(categories); }
/// <summary> /// Creates a Macro Editor windows form. /// </summary> /// <param name="commandProcessor">The command processor.</param> /// <param name="macroFolder">The macro folder.</param> /// <param name="categories">The command categories to include.</param> public EditMacro(Processor commandProcessor, string macroFolder, string[] categories) { if (commandProcessor == null) throw new ArgumentNullException("commandProcessor"); if (String.IsNullOrEmpty(macroFolder)) throw new ArgumentNullException("macroFolder"); if (categories == null) throw new ArgumentNullException("categories"); InitializeComponent(); _commandProcessor = commandProcessor; _macroFolder = macroFolder; textBoxName.Text = "New Macro"; textBoxName.Enabled = true; PopulateCommandList(categories); }
/// <summary> /// Execute this command. /// </summary> /// <param name="commandProcessor">The command processor.</param> public void Execute(Processor commandProcessor) { string[] processed = ProcessParameters(commandProcessor.Variables, Parameters); Macro macro = new Macro(processed[0]); macro.Execute(commandProcessor); }
/// <summary> /// Exceutes this macro the specified variables and process command method. /// </summary> /// <param name="commandProcessor">The command processor.</param> public void Execute(Processor commandProcessor) { try { for (int position = 0; position < _commands.Count; position++) { Command command = _commands[position]; if (command is CommandIf) { string[] processed = Command.ProcessParameters(commandProcessor.Variables, command.Parameters); if (CommandIf.Evaluate(processed[0], processed[1], processed[2])) position = FindLabel(processed[3]); else if (!String.IsNullOrEmpty(processed[4])) position = FindLabel(processed[4]); } else if (command is CommandGotoLabel) { string[] processed = Command.ProcessParameters(commandProcessor.Variables, command.Parameters); position = FindLabel(processed[0]); } else { commandProcessor.Execute(command, false); } } } catch (Exception ex) { throw new MacroExecutionException("Error executing macro", ex); } }