Example #1
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;
    }
Example #2
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;
        }
Example #3
0
        // --------------------------------------------------------------------------------------------------
        #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;
        }
Example #4
0
    /// <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;
    }
Example #5
0
        /// <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;
        }
Example #6
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();
        }
Example #7
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();
        }
Example #8
0
        // --------------------------------------------------------------------------------------------------
        #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;

        }
Example #9
0
        // --------------------------------------------------------------------------------------------------
        #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;
        }
Example #10
0
        // --------------------------------------------------------------------------------------------------
        #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;
        }