/// <summary> /// Initializes a new instance of the <see cref="BlastCommand"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="baseFolder">The IR Command base folder.</param> /// <param name="ports">The available ports.</param> private BlastCommand(BlastIrDelegate blastIrDelegate, string baseFolder, string[] ports) { if (blastIrDelegate == null) { throw new ArgumentNullException("blastIrDelegate"); } if (String.IsNullOrEmpty(baseFolder)) { throw new ArgumentNullException("baseFolder"); } if (ports == null) { throw new ArgumentNullException("ports"); } InitializeComponent(); _blastIrDelegate = blastIrDelegate; buttonTest.Enabled = _blastIrDelegate != null; _baseFolder = baseFolder; comboBoxPort.Items.AddRange(ports); comboBoxPort.SelectedIndex = 0; }
/// <summary> /// Create a new IR Command. /// </summary> /// <param name="learnIrDelegate">Delegate to call to start the IR learn process.</param> /// <param name="blastIrDelegate">Delegate to call to test an IR Command.</param> /// <param name="ports">Available blaster ports to transmit on.</param> public LearnIR(LearnIrDelegate learnIrDelegate, BlastIrDelegate blastIrDelegate, string[] ports) { if (learnIrDelegate == null) throw new ArgumentNullException("learnIrDelegate"); if (blastIrDelegate == null) throw new ArgumentNullException("blastIrDelegate"); if (ports == null) throw new ArgumentNullException("ports"); _learnIrDelegate = learnIrDelegate; _blastIrDelegate = blastIrDelegate; InitializeComponent(); comboBoxPort.Items.Clear(); comboBoxPort.Items.AddRange(ports); comboBoxPort.SelectedIndex = 0; labelStatus.Text = "Nothing learned yet"; groupBoxTest.Enabled = false; textBoxName.Text = "New"; textBoxName.Enabled = true; _isNewCode = true; }
/// <summary> /// Create a new IR Command. /// </summary> /// <param name="learnIrDelegate">Delegate to call to start the IR learn process.</param> /// <param name="blastIrDelegate">Delegate to call to test an IR Command.</param> /// <param name="ports">Available blaster ports to transmit on.</param> public LearnIR(LearnIrDelegate learnIrDelegate, BlastIrDelegate blastIrDelegate, string[] ports) { if (learnIrDelegate == null) { throw new ArgumentNullException("learnIrDelegate"); } if (blastIrDelegate == null) { throw new ArgumentNullException("blastIrDelegate"); } if (ports == null) { throw new ArgumentNullException("ports"); } _learnIrDelegate = learnIrDelegate; _blastIrDelegate = blastIrDelegate; InitializeComponent(); comboBoxPort.Items.Clear(); comboBoxPort.Items.AddRange(ports); comboBoxPort.SelectedIndex = 0; labelStatus.Text = "Nothing learned yet"; groupBoxTest.Enabled = false; textBoxName.Text = "New"; textBoxName.Enabled = true; _isNewCode = true; }
/// <summary> /// Initializes a new instance of the <see cref="Processor"/> class. /// </summary> /// <param name="blastIrDelegate">The blast ir delegate.</param> /// <param name="blastIrPorts">The blast ir ports.</param> public Processor(BlastIrDelegate blastIrDelegate, string[] blastIrPorts) { _variables = new VariableList(); _blastIrDelegate = blastIrDelegate; _blastIrPorts = blastIrPorts; }
/// <summary> /// Initializes a new instance of the <see cref="EditBlastIR"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="ports">The available ports.</param> /// <param name="parameters">The command parameters.</param> /// <param name="commandCount">The command count for this batch of commands.</param> public EditBlastIR(BlastIrDelegate blastIrDelegate, string[] ports, string[] parameters, int commandCount) : this(blastIrDelegate, ports, parameters) { if (commandCount > 1) { checkBoxUseForAll.Text = String.Format("Use this port for all ({0})", commandCount); checkBoxUseForAll.Visible = true; } }
/// <summary> /// Initializes a new instance of the <see cref="BlastCommand"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="baseFolder">The IR Command base folder.</param> /// <param name="ports">The available ports.</param> /// <param name="name">The name of the IR Command.</param> public BlastCommand(BlastIrDelegate blastIrDelegate, string baseFolder, string[] ports, string name) : this(blastIrDelegate, baseFolder, ports) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } labelIRCommandFile.Text = name; }
/// <summary> /// Initializes a new instance of the <see cref="BlastCommand"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="baseFolder">The IR Command base folder.</param> /// <param name="ports">The available ports.</param> /// <param name="commands">The command elements.</param> /// <param name="commandCount">The command count for this batch of commands.</param> public BlastCommand(BlastIrDelegate blastIrDelegate, string baseFolder, string[] ports, string[] commands, int commandCount) : this(blastIrDelegate, baseFolder, ports, commands) { if (commandCount > 1) { checkBoxUseForAll.Text = String.Format("Use this port for all ({0})", commandCount); checkBoxUseForAll.Visible = true; } }
/// <summary> /// Edit this command. /// </summary> /// <param name="parent">The parent window.</param> /// <param name="blastIrDelegate">The blast ir delegate.</param> /// <param name="blastPorts">The blast ports.</param> /// <returns><c>true</c> if the command was modified; otherwise <c>false</c>.</returns> public bool Edit(IWin32Window parent, BlastIrDelegate blastIrDelegate, string[] blastPorts) { EditBlastIR edit = new EditBlastIR(blastIrDelegate, blastPorts, Parameters); if (edit.ShowDialog(parent) == DialogResult.OK) { Parameters = edit.Parameters; return(true); } return(false); }
// -------------------------------------------------------------------------------------------------- #region Constructor /// <summary> /// Create, insert or modify an IR Command. /// </summary> /// <param name="learnIrDelegate">Delegate to call to start the IR learn process.</param> /// <param name="blastIrDelegate">Delegate to call to test an IR Command.</param> /// <param name="ports">Available blast ports to transmit on.</param> /// <param name="name">Name of the existing IR Command, "" if new command.</param> public IREditor(LearnIrDelegate learnIrDelegate, BlastIrDelegate blastIrDelegate, string[] ports, string name = "") { _learnIrDelegate = learnIrDelegate; _blastIrDelegate = blastIrDelegate; _name = name; if (name == null) { _name = ""; } _editionEnabled = learnIrDelegate != null; _blastEnabled = blastIrDelegate != null && ports != null; _insertionEnabled = name != ""; _codeValid = name != ""; InitializeComponent(); // Initialize temporary file if (_editionEnabled) { if (name != "") { try { string filename = Path.Combine(Common.FolderIRCommands, name + Common.FileExtensionIR); if (File.Exists(tempfile)) { File.Delete(tempfile); } File.Copy(filename, tempfile, true); labelStatus.Text = "IR Command is unchanged"; } catch { _editionEnabled = false; } } } comboBoxPort.Items.Clear(); comboBoxPort.Items.AddRange(ports); comboBoxPort.SelectedIndex = 0; textBoxName.Text = name; comboBoxPort.Enabled = _blastEnabled && _codeValid; buttonTest.Enabled = _blastEnabled && _codeValid; buttonLearn.Enabled = _editionEnabled; textBoxName.Enabled = _editionEnabled; EditedIr = !_insertionEnabled; }
/// <summary> /// Relearn an existing IR Command. /// </summary> /// <param name="learnIrDelegate">Delegate to call to start the IR learn process.</param> /// <param name="blastIrDelegate">Delegate to call to test an IR Command.</param> /// <param name="ports">Available blast ports to transmit on.</param> /// <param name="existingCodeName">Name of the existing IR Command.</param> public LearnIR(LearnIrDelegate learnIrDelegate, BlastIrDelegate blastIrDelegate, string[] ports, string existingCodeName) : this(learnIrDelegate, blastIrDelegate, ports) { if (String.IsNullOrEmpty(existingCodeName)) throw new ArgumentNullException("existingCodeName"); labelStatus.Text = "IR Command is unchanged"; groupBoxTest.Enabled = true; textBoxName.Text = existingCodeName; textBoxName.Enabled = false; _isNewCode = false; }
/// <summary> /// Relearn an existing IR Command. /// </summary> /// <param name="learnIrDelegate">Delegate to call to start the IR learn process.</param> /// <param name="blastIrDelegate">Delegate to call to test an IR Command.</param> /// <param name="ports">Available blast ports to transmit on.</param> /// <param name="existingCodeName">Name of the existing IR Command.</param> public LearnIR(LearnIrDelegate learnIrDelegate, BlastIrDelegate blastIrDelegate, string[] ports, string existingCodeName) : this(learnIrDelegate, blastIrDelegate, ports) { if (String.IsNullOrEmpty(existingCodeName)) { throw new ArgumentNullException("existingCodeName"); } labelStatus.Text = "IR Command is unchanged"; groupBoxTest.Enabled = true; textBoxName.Text = existingCodeName; textBoxName.Enabled = false; _isNewCode = false; }
/// <summary> /// Initializes a new instance of the <see cref="BlastCommand"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="baseFolder">The IR Command base folder.</param> /// <param name="ports">The available ports.</param> /// <param name="commands">The command elements.</param> public BlastCommand(BlastIrDelegate blastIrDelegate, string baseFolder, string[] ports, string[] commands) : this(blastIrDelegate, baseFolder, ports) { if (commands == null) { throw new ArgumentNullException("commands"); } labelIRCommandFile.Text = commands[0]; if (comboBoxPort.Items.Contains(commands[1])) { comboBoxPort.SelectedItem = commands[1]; } }
/// <summary> /// Initializes a new instance of the <see cref="EditBlastIR"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="ports">The available ports.</param> private EditBlastIR(BlastIrDelegate blastIrDelegate, string[] ports) { if (blastIrDelegate == null) throw new ArgumentNullException("blastIrDelegate"); if (ports == null) throw new ArgumentNullException("ports"); InitializeComponent(); _blastIrDelegate = blastIrDelegate; comboBoxPort.Items.AddRange(ports); comboBoxPort.SelectedIndex = 0; }
/// <summary> /// Initializes a new instance of the <see cref="EditBlastIR"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="ports">The available ports.</param> private EditBlastIR(BlastIrDelegate blastIrDelegate, string[] ports) { if (blastIrDelegate == null) { throw new ArgumentNullException("blastIrDelegate"); } if (ports == null) { throw new ArgumentNullException("ports"); } InitializeComponent(); _blastIrDelegate = blastIrDelegate; comboBoxPort.Items.AddRange(ports); comboBoxPort.SelectedIndex = 0; }
// -------------------------------------------------------------------------------------------------- #region Constructor public CommandManager(IRServerInfo server = null, BlastIrDelegate BlastFunc = null, LearnIrDelegate LearnIrFunc = null, ProcessCommandDelegate processCommand = null, bool script = false) { InitializeComponent(); IRServer = server; _BlastFunc = BlastFunc; _LearnIrFunc = LearnIrFunc; _ProcessCommand = processCommand; _showGeneralCmds = true; _showScriptCmds = script; _showMacroCmds = true; _showMediaPortalCmds = false; _showServerCmds = BlastFunc != null && LearnIrFunc != null; _macroCommands = null; learnIRCommandToolStripMenuItem.Enabled = _LearnIrFunc != null; PopulateCommandList(); }
/// <summary> /// Initializes a new instance of the <see cref="EditBlastIR"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="ports">The available ports.</param> /// <param name="parameters">The command parameters.</param> public EditBlastIR(BlastIrDelegate blastIrDelegate, string[] ports, string[] parameters) : this(blastIrDelegate, ports) { if (parameters == null) { throw new ArgumentNullException("parameters"); } if (String.IsNullOrEmpty(parameters[0])) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "IR Command Files|*" + Processor.FileExtensionIR; if (openFileDialog.ShowDialog(this) == DialogResult.OK) { parameters[0] = openFileDialog.FileName; } } _fileName = parameters[0]; string filePath = Path.GetDirectoryName(_fileName); string fileName = Path.GetFileNameWithoutExtension(_fileName); string displayName = Path.Combine(filePath, fileName); if (displayName.StartsWith(Common.FolderIRCommands, StringComparison.OrdinalIgnoreCase)) { displayName = displayName.Substring(Common.FolderIRCommands.Length); } else if (displayName.StartsWith(Common.FolderAppData, StringComparison.OrdinalIgnoreCase)) { displayName = displayName.Substring(Common.FolderAppData.Length); } labelIRCommandFile.Text = displayName; if (comboBoxPort.Items.Contains(parameters[1])) { comboBoxPort.SelectedItem = parameters[1]; } }
// -------------------------------------------------------------------------------------------------- #region Constructor /// <summary> /// Creates a Macro Editor windows form. /// </summary> /// <param name="name">The name of an existing macro (default: new macro).</param> public MacroEditor(string name = "", IRServerInfo server = null, BlastIrDelegate blast = null, LearnIrDelegate learnIr=null, ProcessCommandDelegate processCommand=null, bool insertionEnabled = true) { if (name==null) name = ""; _insertionEnabled = insertionEnabled; _editionEnabled = !IsOpen(name); _OpenInstances.Add(name.ToLower()); _name = name; _server = server; _blast = blast; _learnIr = learnIr; _ProcessCommand = processCommand; InitializeComponent(); textBoxName.Text = name; buttonTest.Enabled = _ProcessCommand != null; buttonOK.Visible = _insertionEnabled || _editionEnabled; buttonOK.Enabled = _insertionEnabled; _MacroNameValid = name != ""; buttonShortcut.Enabled = _MacroNameValid; if (_editionEnabled && !_insertionEnabled || _name == "") { // Show save first buttonOK.Enabled = false; buttonOK.Text = "Save"; this.buttonOK.Image = global::IrssUtils.Properties.Resources.Save; } else { buttonOK.Enabled = _insertionEnabled; } if (_editionEnabled) { InitializeCommandManager(); } else { // Relayout for Read-only mode labelInvalid.Text = "Macro is already open for edition"; labelInvalid.Show(); textBoxName.Enabled = false; groupBoxCommandSequence.Controls.Remove(splitContainerMain); groupBoxCommandSequence.Controls.Add(panelActions); this.MinimumSize = new System.Drawing.Size(310, this.Height); this.Width = 350; } if (_name == "") return; try { string fileName = Path.Combine(FolderMacros, name + Common.FileExtensionMacro); string[] commands = IrssMacro.ReadFromFile(fileName); foreach (var cmd in commands) { InsertCommand(cmd); } } catch (Exception ex) { IrssLog.Error(ex); MessageBox.Show(this, ex.Message, "Failed to load macro: " + name + Common.FileExtensionMacro, MessageBoxButtons.OK, MessageBoxIcon.Error); textBoxName.Text = ""; } _editedMacro = false; }
// -------------------------------------------------------------------------------------------------- #region Constructor /// <summary> /// Create, insert or modify an IR Command. /// </summary> /// <param name="learnIrDelegate">Delegate to call to start the IR learn process.</param> /// <param name="blastIrDelegate">Delegate to call to test an IR Command.</param> /// <param name="ports">Available blast ports to transmit on.</param> /// <param name="name">Name of the existing IR Command, "" if new command.</param> public IREditor(LearnIrDelegate learnIrDelegate, BlastIrDelegate blastIrDelegate, string[] ports, string name = "") { _learnIrDelegate = learnIrDelegate; _blastIrDelegate = blastIrDelegate; _name = name; if (name == null) _name = ""; _editionEnabled = learnIrDelegate != null; _blastEnabled = blastIrDelegate != null && ports != null; _insertionEnabled = name != ""; _codeValid = name != ""; InitializeComponent(); // Initialize temporary file if (_editionEnabled) { if (name != "") { try { string filename = Path.Combine(Common.FolderIRCommands, name + Common.FileExtensionIR); if (File.Exists(tempfile)) File.Delete(tempfile); File.Copy(filename, tempfile, true); labelStatus.Text = "IR Command is unchanged"; } catch { _editionEnabled = false; } } } comboBoxPort.Items.Clear(); comboBoxPort.Items.AddRange(ports); comboBoxPort.SelectedIndex = 0; textBoxName.Text = name; comboBoxPort.Enabled = _blastEnabled && _codeValid; buttonTest.Enabled = _blastEnabled && _codeValid; buttonLearn.Enabled = _editionEnabled; textBoxName.Enabled = _editionEnabled; EditedIr = !_insertionEnabled; }
/// <summary> /// Initializes a new instance of the <see cref="BlastCommand"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="baseFolder">The IR Command base folder.</param> /// <param name="ports">The available ports.</param> private BlastCommand(BlastIrDelegate blastIrDelegate, string baseFolder, string[] ports) { if (blastIrDelegate == null) throw new ArgumentNullException("blastIrDelegate"); if (String.IsNullOrEmpty(baseFolder)) throw new ArgumentNullException("baseFolder"); if (ports == null) throw new ArgumentNullException("ports"); InitializeComponent(); _blastIrDelegate = blastIrDelegate; buttonTest.Enabled = _blastIrDelegate != null; _baseFolder = baseFolder; comboBoxPort.Items.AddRange(ports); comboBoxPort.SelectedIndex = 0; }
/// <summary> /// Initializes a new instance of the <see cref="BlastCommand"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="baseFolder">The IR Command base folder.</param> /// <param name="ports">The available ports.</param> /// <param name="commands">The command elements.</param> public BlastCommand(BlastIrDelegate blastIrDelegate, string baseFolder, string[] ports, string[] commands) : this(blastIrDelegate, baseFolder, ports) { if (commands == null) throw new ArgumentNullException("commands"); labelIRCommandFile.Text = commands[0]; if (comboBoxPort.Items.Contains(commands[1])) comboBoxPort.SelectedItem = commands[1]; }
// -------------------------------------------------------------------------------------------------- #region Constructor /// <summary> /// Creates a Macro Editor windows form. /// </summary> /// <param name="name">The name of an existing macro (default: new macro).</param> public MacroEditor(string name = "", IRServerInfo server = null, BlastIrDelegate blast = null, LearnIrDelegate learnIr = null, ProcessCommandDelegate processCommand = null, bool insertionEnabled = true) { if (name == null) { name = ""; } _insertionEnabled = insertionEnabled; _editionEnabled = !IsOpen(name); _OpenInstances.Add(name.ToLower()); _name = name; _server = server; _blast = blast; _learnIr = learnIr; _ProcessCommand = processCommand; InitializeComponent(); textBoxName.Text = name; buttonTest.Enabled = _ProcessCommand != null; buttonOK.Visible = _insertionEnabled || _editionEnabled; buttonOK.Enabled = _insertionEnabled; _MacroNameValid = name != ""; buttonShortcut.Enabled = _MacroNameValid; if (_editionEnabled && !_insertionEnabled || _name == "") { // Show save first buttonOK.Enabled = false; buttonOK.Text = "Save"; this.buttonOK.Image = global::IrssUtils.Properties.Resources.Save; } else { buttonOK.Enabled = _insertionEnabled; } if (_editionEnabled) { InitializeCommandManager(); } else { // Relayout for Read-only mode labelInvalid.Text = "Macro is already open for edition"; labelInvalid.Show(); textBoxName.Enabled = false; groupBoxCommandSequence.Controls.Remove(splitContainerMain); groupBoxCommandSequence.Controls.Add(panelActions); this.MinimumSize = new System.Drawing.Size(310, this.Height); this.Width = 350; } if (_name == "") { return; } try { string fileName = Path.Combine(FolderMacros, name + Common.FileExtensionMacro); string[] commands = IrssMacro.ReadFromFile(fileName); foreach (var cmd in commands) { InsertCommand(cmd); } } catch (Exception ex) { IrssLog.Error(ex); MessageBox.Show(this, ex.Message, "Failed to load macro: " + name + Common.FileExtensionMacro, MessageBoxButtons.OK, MessageBoxIcon.Error); textBoxName.Text = ""; } _editedMacro = false; }
/// <summary> /// Initializes a new instance of the <see cref="EditBlastIR"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="ports">The available ports.</param> /// <param name="parameters">The command parameters.</param> public EditBlastIR(BlastIrDelegate blastIrDelegate, string[] ports, string[] parameters) : this(blastIrDelegate, ports) { if (parameters == null) throw new ArgumentNullException("parameters"); if (String.IsNullOrEmpty(parameters[0])) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "IR Command Files|*" + Processor.FileExtensionIR; if (openFileDialog.ShowDialog(this) == DialogResult.OK) parameters[0] = openFileDialog.FileName; } _fileName = parameters[0]; string filePath = Path.GetDirectoryName(_fileName); string fileName = Path.GetFileNameWithoutExtension(_fileName); string displayName = Path.Combine(filePath, fileName); if (displayName.StartsWith(Common.FolderIRCommands, StringComparison.OrdinalIgnoreCase)) displayName = displayName.Substring(Common.FolderIRCommands.Length); else if (displayName.StartsWith(Common.FolderAppData, StringComparison.OrdinalIgnoreCase)) displayName = displayName.Substring(Common.FolderAppData.Length); labelIRCommandFile.Text = displayName; if (comboBoxPort.Items.Contains(parameters[1])) comboBoxPort.SelectedItem = parameters[1]; }
/// <summary> /// Initializes a new instance of the <see cref="BlastCommand"/> class. /// </summary> /// <param name="blastIrDelegate">The blast IR delegate.</param> /// <param name="baseFolder">The IR Command base folder.</param> /// <param name="ports">The available ports.</param> /// <param name="name">The name of the IR Command.</param> public BlastCommand(BlastIrDelegate blastIrDelegate, string baseFolder, string[] ports, string name) : this(blastIrDelegate, baseFolder, ports) { if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); labelIRCommandFile.Text = name; }