Esempio n. 1
0
        /// <summary>
        /// Show the configuration window for the specified command with its arguments.
        /// </summary>
        /// <param name="cmdArgs">Command and its argument to be edited. </param>
        /// <returns>command with its arguments, or null if cancel or error</returns>
        public string CommandEdit(string cmdArgs)
        {
            string newCommand = null;
            if (String.IsNullOrEmpty(cmdArgs)) return null;

            try
            {
                
                if (cmdArgs.StartsWith(Common.CmdPrefixIf, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitIfCommand(cmdArgs.Substring(Common.CmdPrefixIf.Length));

                    IfCommand ifCommand = new IfCommand(commands);
                    if (ifCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixIf + ifCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixLabel, StringComparison.OrdinalIgnoreCase))
                {
                    LabelNameDialog labelDialog = new LabelNameDialog(cmdArgs.Substring(Common.CmdPrefixLabel.Length));
                    if (labelDialog.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixLabel + labelDialog.LabelName;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixGotoLabel, StringComparison.OrdinalIgnoreCase))
                {
                    LabelNameDialog labelDialog = new LabelNameDialog(cmdArgs.Substring(Common.CmdPrefixGotoLabel.Length));
                    if (labelDialog.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixGotoLabel + labelDialog.LabelName;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixSetVar, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitSetVarCommand(cmdArgs.Substring(Common.CmdPrefixSetVar.Length));

                    SetVariableCommand setVariableCommand = new SetVariableCommand(commands);
                    if (setVariableCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixSetVar + setVariableCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixLoadVars, StringComparison.OrdinalIgnoreCase))
                {
                    VariablesFileDialog varsFileDialog =
                      new VariablesFileDialog(cmdArgs.Substring(Common.CmdPrefixLoadVars.Length));
                    if (varsFileDialog.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixLoadVars + varsFileDialog.FileName;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixSaveVars, StringComparison.OrdinalIgnoreCase))
                {
                    VariablesFileDialog varsFileDialog =
                      new VariablesFileDialog(cmdArgs.Substring(Common.CmdPrefixSaveVars.Length));
                    if (varsFileDialog.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixSaveVars + varsFileDialog.FileName;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixRun, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitRunCommand(cmdArgs.Substring(Common.CmdPrefixRun.Length));

                    ExternalProgram executeProgram = new ExternalProgram(commands);
                    if (executeProgram.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixRun + executeProgram.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixPause, StringComparison.OrdinalIgnoreCase))
                {
                    PauseTime pauseTime = new PauseTime(int.Parse(cmdArgs.Substring(Common.CmdPrefixPause.Length)));
                    if (pauseTime.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixPause + pauseTime.Time;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixSerial, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitSerialCommand(cmdArgs.Substring(Common.CmdPrefixSerial.Length));

                    SerialCommand serialCommand = new SerialCommand(commands);
                    if (serialCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixSerial + serialCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixWindowMsg, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitWindowMessageCommand(cmdArgs.Substring(Common.CmdPrefixWindowMsg.Length));

                    MessageCommand messageCommand = new MessageCommand(commands);
                    if (messageCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixWindowMsg + messageCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixTcpMsg, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitTcpMessageCommand(cmdArgs.Substring(Common.CmdPrefixTcpMsg.Length));

                    TcpMessageCommand tcpMessageCommand = new TcpMessageCommand(commands);
                    if (tcpMessageCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixTcpMsg + tcpMessageCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixHttpMsg, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitHttpMessageCommand(cmdArgs.Substring(Common.CmdPrefixHttpMsg.Length));

                    HttpMessageCommand httpMessageCommand = new HttpMessageCommand(commands);
                    if (httpMessageCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixHttpMsg + httpMessageCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixKeys, StringComparison.OrdinalIgnoreCase))
                {
                    KeysCommand keysCommand = new KeysCommand(cmdArgs.Substring(Common.CmdPrefixKeys.Length));
                    if (keysCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixKeys + keysCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixMouse, StringComparison.OrdinalIgnoreCase))
                {
                    MouseCommand mouseCommand = new MouseCommand(cmdArgs.Substring(Common.CmdPrefixMouse.Length));
                    if (mouseCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixMouse + mouseCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixEject, StringComparison.OrdinalIgnoreCase))
                {
                    EjectCommand ejectCommand = new EjectCommand(cmdArgs.Substring(Common.CmdPrefixEject.Length));
                    if (ejectCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixEject + ejectCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixPopup, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitPopupCommand(cmdArgs.Substring(Common.CmdPrefixPopup.Length));

                    PopupMessage popupMessage = new PopupMessage(commands);
                    if (popupMessage.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixPopup + popupMessage.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixBeep, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitBeepCommand(cmdArgs.Substring(Common.CmdPrefixBeep.Length));

                    BeepCommand beepCommand = new BeepCommand(commands);
                    if (beepCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixBeep + beepCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixSound, StringComparison.OrdinalIgnoreCase))
                {
                    OpenFileDialog openFileDialog = new OpenFileDialog();
                    openFileDialog.Filter = "Wave Files|*.wav";
                    openFileDialog.Multiselect = false;
                    openFileDialog.FileName = cmdArgs.Substring(Common.CmdPrefixSound.Length);

                    if (openFileDialog.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixSound + openFileDialog.FileName;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixDisplayMode, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitDisplayModeCommand(cmdArgs.Substring(Common.CmdPrefixDisplayMode.Length));

                    DisplayModeCommand displayModeCommand = new DisplayModeCommand(commands);
                    if (displayModeCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixDisplayMode + displayModeCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixBlast, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitBlastCommand(cmdArgs.Substring(Common.CmdPrefixBlast.Length));
                    string[] ports = null;
                    if (IRServer != null) ports = IRServer.Ports;
                    BlastCommand blastCommand = new BlastCommand(_BlastFunc, Common.FolderIRCommands, ports, commands);

                    if (blastCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixBlast + blastCommand.CommandString;
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixMacro, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = CommandFetch(cmdArgs, true);
                }
                else
                {
                    throw new CommandStructureException(String.Format("Unknown macro command ({0})", cmdArgs));
                }
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                MessageBox.Show(this, ex.Message, "Failed to edit macro item", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return newCommand;
        }
Esempio n. 2
0
        /// <summary>
        /// Show the configuration window for the specified command with its arguments.
        /// </summary>
        /// <param name="cmdArgs">Command and its argument to be edited. </param>
        /// <returns>command with its arguments, or null if cancel or error</returns>
        public string CommandEdit(string cmdArgs)
        {
            string newCommand = null;

            if (String.IsNullOrEmpty(cmdArgs))
            {
                return(null);
            }

            try
            {
                if (cmdArgs.StartsWith(Common.CmdPrefixIf, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitIfCommand(cmdArgs.Substring(Common.CmdPrefixIf.Length));

                    IfCommand ifCommand = new IfCommand(commands);
                    if (ifCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixIf + ifCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixLabel, StringComparison.OrdinalIgnoreCase))
                {
                    LabelNameDialog labelDialog = new LabelNameDialog(cmdArgs.Substring(Common.CmdPrefixLabel.Length));
                    if (labelDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixLabel + labelDialog.LabelName;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixGotoLabel, StringComparison.OrdinalIgnoreCase))
                {
                    LabelNameDialog labelDialog = new LabelNameDialog(cmdArgs.Substring(Common.CmdPrefixGotoLabel.Length));
                    if (labelDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixGotoLabel + labelDialog.LabelName;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixSetVar, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitSetVarCommand(cmdArgs.Substring(Common.CmdPrefixSetVar.Length));

                    SetVariableCommand setVariableCommand = new SetVariableCommand(commands);
                    if (setVariableCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixSetVar + setVariableCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixLoadVars, StringComparison.OrdinalIgnoreCase))
                {
                    VariablesFileDialog varsFileDialog =
                        new VariablesFileDialog(cmdArgs.Substring(Common.CmdPrefixLoadVars.Length));
                    if (varsFileDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixLoadVars + varsFileDialog.FileName;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixSaveVars, StringComparison.OrdinalIgnoreCase))
                {
                    VariablesFileDialog varsFileDialog =
                        new VariablesFileDialog(cmdArgs.Substring(Common.CmdPrefixSaveVars.Length));
                    if (varsFileDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixSaveVars + varsFileDialog.FileName;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixRun, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitRunCommand(cmdArgs.Substring(Common.CmdPrefixRun.Length));

                    ExternalProgram executeProgram = new ExternalProgram(commands);
                    if (executeProgram.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixRun + executeProgram.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixPause, StringComparison.OrdinalIgnoreCase))
                {
                    PauseTime pauseTime = new PauseTime(int.Parse(cmdArgs.Substring(Common.CmdPrefixPause.Length)));
                    if (pauseTime.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixPause + pauseTime.Time;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixSerial, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitSerialCommand(cmdArgs.Substring(Common.CmdPrefixSerial.Length));

                    SerialCommand serialCommand = new SerialCommand(commands);
                    if (serialCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixSerial + serialCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixWindowMsg, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitWindowMessageCommand(cmdArgs.Substring(Common.CmdPrefixWindowMsg.Length));

                    MessageCommand messageCommand = new MessageCommand(commands);
                    if (messageCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixWindowMsg + messageCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixTcpMsg, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitTcpMessageCommand(cmdArgs.Substring(Common.CmdPrefixTcpMsg.Length));

                    TcpMessageCommand tcpMessageCommand = new TcpMessageCommand(commands);
                    if (tcpMessageCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixTcpMsg + tcpMessageCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixHttpMsg, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitHttpMessageCommand(cmdArgs.Substring(Common.CmdPrefixHttpMsg.Length));

                    HttpMessageCommand httpMessageCommand = new HttpMessageCommand(commands);
                    if (httpMessageCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixHttpMsg + httpMessageCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixKeys, StringComparison.OrdinalIgnoreCase))
                {
                    KeysCommand keysCommand = new KeysCommand(cmdArgs.Substring(Common.CmdPrefixKeys.Length));
                    if (keysCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixKeys + keysCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixMouse, StringComparison.OrdinalIgnoreCase))
                {
                    MouseCommand mouseCommand = new MouseCommand(cmdArgs.Substring(Common.CmdPrefixMouse.Length));
                    if (mouseCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixMouse + mouseCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixEject, StringComparison.OrdinalIgnoreCase))
                {
                    EjectCommand ejectCommand = new EjectCommand(cmdArgs.Substring(Common.CmdPrefixEject.Length));
                    if (ejectCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixEject + ejectCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixPopup, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitPopupCommand(cmdArgs.Substring(Common.CmdPrefixPopup.Length));

                    PopupMessage popupMessage = new PopupMessage(commands);
                    if (popupMessage.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixPopup + popupMessage.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixBeep, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitBeepCommand(cmdArgs.Substring(Common.CmdPrefixBeep.Length));

                    BeepCommand beepCommand = new BeepCommand(commands);
                    if (beepCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixBeep + beepCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixSound, StringComparison.OrdinalIgnoreCase))
                {
                    OpenFileDialog openFileDialog = new OpenFileDialog();
                    openFileDialog.Filter      = "Wave Files|*.wav";
                    openFileDialog.Multiselect = false;
                    openFileDialog.FileName    = cmdArgs.Substring(Common.CmdPrefixSound.Length);

                    if (openFileDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixSound + openFileDialog.FileName;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixDisplayMode, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitDisplayModeCommand(cmdArgs.Substring(Common.CmdPrefixDisplayMode.Length));

                    DisplayModeCommand displayModeCommand = new DisplayModeCommand(commands);
                    if (displayModeCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixDisplayMode + displayModeCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixBlast, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitBlastCommand(cmdArgs.Substring(Common.CmdPrefixBlast.Length));
                    string[] ports    = null;
                    if (IRServer != null)
                    {
                        ports = IRServer.Ports;
                    }
                    BlastCommand blastCommand = new BlastCommand(_BlastFunc, Common.FolderIRCommands, ports, commands);

                    if (blastCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixBlast + blastCommand.CommandString;
                    }
                }
                else if (cmdArgs.StartsWith(Common.CmdPrefixMacro, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = CommandFetch(cmdArgs, true);
                }
                else
                {
                    throw new CommandStructureException(String.Format("Unknown macro command ({0})", cmdArgs));
                }
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                MessageBox.Show(this, ex.Message, "Failed to edit macro item", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(newCommand);
        }
Esempio n. 3
0
        // --------------------------------------------------------------------------------------------------
        #region Command Forms calls

        /// <summary>
        /// Show the configuration window for the specified command without its arguments.
        /// </summary>
        /// <param name="cmdName">Command name to be configured. (Default: take the one selected in the command-list)</param>
        /// <returns>command with its arguments, or null if cancel or error</returns>
        public string CommandFetch(string cmdName=null, bool modify=false)
        {
            string newCommand = null;
            if (cmdName == null)   cmdName = SelectedCommand;
            if (cmdName == null)   return newCommand;

            try
            {

                if (cmdName.Equals(Common.UITextIf, StringComparison.OrdinalIgnoreCase))
                {
                    IfCommand ifCommand = new IfCommand();
                    if (ifCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixIf + ifCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextLabel, StringComparison.OrdinalIgnoreCase))
                {
                    LabelNameDialog labelDialog = new LabelNameDialog();
                    if (labelDialog.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixLabel + labelDialog.LabelName;
                }
                else if (cmdName.Equals(Common.UITextGotoLabel, StringComparison.OrdinalIgnoreCase))
                {
                    LabelNameDialog labelDialog = new LabelNameDialog();
                    if (labelDialog.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixGotoLabel + labelDialog.LabelName;
                }
                else if (cmdName.Equals(Common.UITextSetVar, StringComparison.OrdinalIgnoreCase))
                {
                    SetVariableCommand setVariableCommand = new SetVariableCommand();
                    if (setVariableCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixSetVar + setVariableCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextClearVars, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixClearVars;
                }
                else if (cmdName.Equals(Common.UITextLoadVars, StringComparison.OrdinalIgnoreCase))
                {
                    VariablesFileDialog varsFileDialog = new VariablesFileDialog();
                    if (varsFileDialog.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixLoadVars + varsFileDialog.FileName;
                }
                else if (cmdName.Equals(Common.UITextSaveVars, StringComparison.OrdinalIgnoreCase))
                {
                    VariablesFileDialog varsFileDialog = new VariablesFileDialog();
                    if (varsFileDialog.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixSaveVars + varsFileDialog.FileName;
                }
                else if (cmdName.Equals(Common.UITextRun, StringComparison.OrdinalIgnoreCase))
                {
                    ExternalProgram externalProgram = new ExternalProgram();
                    if (externalProgram.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixRun + externalProgram.CommandString;
                }
                else if (cmdName.Equals(Common.UITextPause, StringComparison.OrdinalIgnoreCase))
                {
                    PauseTime pauseTime = new PauseTime();
                    if (pauseTime.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixPause + pauseTime.Time;
                }
                else if (cmdName.Equals(Common.UITextSerial, StringComparison.OrdinalIgnoreCase))
                {
                    SerialCommand serialCommand = new SerialCommand();
                    if (serialCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixSerial + serialCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextWindowMsg, StringComparison.OrdinalIgnoreCase))
                {
                    MessageCommand messageCommand = new MessageCommand();
                    if (messageCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixWindowMsg + messageCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextTcpMsg, StringComparison.OrdinalIgnoreCase))
                {
                    TcpMessageCommand tcpMessageCommand = new TcpMessageCommand();
                    if (tcpMessageCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixTcpMsg + tcpMessageCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextHttpMsg, StringComparison.OrdinalIgnoreCase))
                {
                    HttpMessageCommand httpMessageCommand = new HttpMessageCommand();
                    if (httpMessageCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixHttpMsg + httpMessageCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextKeys, StringComparison.OrdinalIgnoreCase))
                {
                    KeysCommand keysCommand = new KeysCommand();
                    if (keysCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixKeys + keysCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextMouse, StringComparison.OrdinalIgnoreCase))
                {
                    MouseCommand mouseCommand = new MouseCommand();
                    if (mouseCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixMouse + mouseCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextEject, StringComparison.OrdinalIgnoreCase))
                {
                    EjectCommand ejectCommand = new EjectCommand();
                    if (ejectCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixEject + ejectCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextPopup, StringComparison.OrdinalIgnoreCase))
                {
                    PopupMessage popupMessage = new PopupMessage();
                    if (popupMessage.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixPopup + popupMessage.CommandString;
                }
                else if (cmdName.Equals(Common.UITextVirtualKB, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixVirtualKB;
                }
                else if (cmdName.Equals(Common.UITextSmsKB, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixSmsKB;
                }
                else if (cmdName.Equals(Common.UITextBeep, StringComparison.OrdinalIgnoreCase))
                {
                    BeepCommand beepCommand = new BeepCommand();
                    if (beepCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixBeep + beepCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextSound, StringComparison.OrdinalIgnoreCase))
                {
                    OpenFileDialog openFileDialog = new OpenFileDialog();
                    openFileDialog.Filter = "Wave Files|*.wav";
                    openFileDialog.Multiselect = false;

                    if (openFileDialog.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixSound + openFileDialog.FileName;
                }
                else if (cmdName.Equals(Common.UITextDisplayMode, StringComparison.OrdinalIgnoreCase))
                {
                    DisplayModeCommand displayModeCommand = new DisplayModeCommand();
                    if (displayModeCommand.ShowDialog(this) == DialogResult.OK)
                        newCommand = Common.CmdPrefixDisplayMode + displayModeCommand.CommandString;
                }
                else if (cmdName.Equals(Common.UITextStandby, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixStandby;
                }
                else if (cmdName.Equals(Common.UITextHibernate, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixHibernate;
                }
                else if (cmdName.Equals(Common.UITextReboot, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixReboot;
                }
                else if (cmdName.Equals(Common.UITextShutdown, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixShutdown;
                }
                else if (cmdName.Equals(Common.CmdPrefixTranslator, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixTranslator;
                } 
                else if (cmdName.StartsWith(Common.CmdPrefixBlast, StringComparison.OrdinalIgnoreCase))
                {
                    string[] ports = null;
                    if (IRServer != null) ports = IRServer.Ports;
                    string name = cmdName.Substring(Common.CmdPrefixBlast.Length);

                    IREditor learnIR = new IREditor(_LearnIrFunc, _BlastFunc, ports, name);
                    if (learnIR.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixBlast + learnIR.CommandString;
                        name = learnIR.BlastName;
                    }
                   
                    RefreshBlastList(name);
             

                }
                else if (cmdName.StartsWith(Common.CmdPrefixMacro, StringComparison.OrdinalIgnoreCase))
                {
                    if (modify)
                    {
                        string command = cmdName.Substring(Common.CmdPrefixBlast.Length);
                        string fileName = Path.Combine(FolderMacros, command + Common.FileExtensionMacro);
                        if (File.Exists(fileName))
                        {
                            MacroEditor macroEditor = new MacroEditor(command, IRServer, _BlastFunc, _LearnIrFunc, _ProcessCommand);
                            macroEditor.ShowDialog(this);
                            RefreshMacroList(macroEditor.MacroName);
                            if (macroEditor.DialogResult == DialogResult.OK)
                            {
                                cmdName = Common.CmdPrefixMacro + macroEditor.MacroName;
                            }
                            else
                            {
                                cmdName = null;
                            }
                        }
                        else
                        {
                            MessageBox.Show(this, "File not found: " + fileName, "Macro file missing", MessageBoxButtons.OK,
                                            MessageBoxIcon.Exclamation);
                        }
                    }

                    newCommand = cmdName;
                }
                else
                {
                    throw new CommandStructureException(String.Format("Unknown macro command ({0})", cmdName));
                }

            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                MessageBox.Show(this, ex.Message, "Failed to add macro command", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return newCommand;
        }
Esempio n. 4
0
        // --------------------------------------------------------------------------------------------------
        #region Command Forms calls

        /// <summary>
        /// Show the configuration window for the specified command without its arguments.
        /// </summary>
        /// <param name="cmdName">Command name to be configured. (Default: take the one selected in the command-list)</param>
        /// <returns>command with its arguments, or null if cancel or error</returns>
        public string CommandFetch(string cmdName = null, bool modify = false)
        {
            string newCommand = null;

            if (cmdName == null)
            {
                cmdName = SelectedCommand;
            }
            if (cmdName == null)
            {
                return(newCommand);
            }

            try
            {
                if (cmdName.Equals(Common.UITextIf, StringComparison.OrdinalIgnoreCase))
                {
                    IfCommand ifCommand = new IfCommand();
                    if (ifCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixIf + ifCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextLabel, StringComparison.OrdinalIgnoreCase))
                {
                    LabelNameDialog labelDialog = new LabelNameDialog();
                    if (labelDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixLabel + labelDialog.LabelName;
                    }
                }
                else if (cmdName.Equals(Common.UITextGotoLabel, StringComparison.OrdinalIgnoreCase))
                {
                    LabelNameDialog labelDialog = new LabelNameDialog();
                    if (labelDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixGotoLabel + labelDialog.LabelName;
                    }
                }
                else if (cmdName.Equals(Common.UITextSetVar, StringComparison.OrdinalIgnoreCase))
                {
                    SetVariableCommand setVariableCommand = new SetVariableCommand();
                    if (setVariableCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixSetVar + setVariableCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextClearVars, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixClearVars;
                }
                else if (cmdName.Equals(Common.UITextLoadVars, StringComparison.OrdinalIgnoreCase))
                {
                    VariablesFileDialog varsFileDialog = new VariablesFileDialog();
                    if (varsFileDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixLoadVars + varsFileDialog.FileName;
                    }
                }
                else if (cmdName.Equals(Common.UITextSaveVars, StringComparison.OrdinalIgnoreCase))
                {
                    VariablesFileDialog varsFileDialog = new VariablesFileDialog();
                    if (varsFileDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixSaveVars + varsFileDialog.FileName;
                    }
                }
                else if (cmdName.Equals(Common.UITextRun, StringComparison.OrdinalIgnoreCase))
                {
                    ExternalProgram externalProgram = new ExternalProgram();
                    if (externalProgram.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixRun + externalProgram.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextPause, StringComparison.OrdinalIgnoreCase))
                {
                    PauseTime pauseTime = new PauseTime();
                    if (pauseTime.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixPause + pauseTime.Time;
                    }
                }
                else if (cmdName.Equals(Common.UITextSerial, StringComparison.OrdinalIgnoreCase))
                {
                    SerialCommand serialCommand = new SerialCommand();
                    if (serialCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixSerial + serialCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextWindowMsg, StringComparison.OrdinalIgnoreCase))
                {
                    MessageCommand messageCommand = new MessageCommand();
                    if (messageCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixWindowMsg + messageCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextTcpMsg, StringComparison.OrdinalIgnoreCase))
                {
                    TcpMessageCommand tcpMessageCommand = new TcpMessageCommand();
                    if (tcpMessageCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixTcpMsg + tcpMessageCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextHttpMsg, StringComparison.OrdinalIgnoreCase))
                {
                    HttpMessageCommand httpMessageCommand = new HttpMessageCommand();
                    if (httpMessageCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixHttpMsg + httpMessageCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextKeys, StringComparison.OrdinalIgnoreCase))
                {
                    KeysCommand keysCommand = new KeysCommand();
                    if (keysCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixKeys + keysCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextMouse, StringComparison.OrdinalIgnoreCase))
                {
                    MouseCommand mouseCommand = new MouseCommand();
                    if (mouseCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixMouse + mouseCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextEject, StringComparison.OrdinalIgnoreCase))
                {
                    EjectCommand ejectCommand = new EjectCommand();
                    if (ejectCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixEject + ejectCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextPopup, StringComparison.OrdinalIgnoreCase))
                {
                    PopupMessage popupMessage = new PopupMessage();
                    if (popupMessage.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixPopup + popupMessage.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextVirtualKB, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixVirtualKB;
                }
                else if (cmdName.Equals(Common.UITextSmsKB, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixSmsKB;
                }
                else if (cmdName.Equals(Common.UITextBeep, StringComparison.OrdinalIgnoreCase))
                {
                    BeepCommand beepCommand = new BeepCommand();
                    if (beepCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixBeep + beepCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextSound, StringComparison.OrdinalIgnoreCase))
                {
                    OpenFileDialog openFileDialog = new OpenFileDialog();
                    openFileDialog.Filter      = "Wave Files|*.wav";
                    openFileDialog.Multiselect = false;

                    if (openFileDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixSound + openFileDialog.FileName;
                    }
                }
                else if (cmdName.Equals(Common.UITextDisplayMode, StringComparison.OrdinalIgnoreCase))
                {
                    DisplayModeCommand displayModeCommand = new DisplayModeCommand();
                    if (displayModeCommand.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixDisplayMode + displayModeCommand.CommandString;
                    }
                }
                else if (cmdName.Equals(Common.UITextStandby, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixStandby;
                }
                else if (cmdName.Equals(Common.UITextHibernate, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixHibernate;
                }
                else if (cmdName.Equals(Common.UITextReboot, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixReboot;
                }
                else if (cmdName.Equals(Common.UITextShutdown, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixShutdown;
                }
                else if (cmdName.Equals(Common.CmdPrefixTranslator, StringComparison.OrdinalIgnoreCase))
                {
                    newCommand = Common.CmdPrefixTranslator;
                }
                else if (cmdName.StartsWith(Common.CmdPrefixBlast, StringComparison.OrdinalIgnoreCase))
                {
                    string[] ports = null;
                    if (IRServer != null)
                    {
                        ports = IRServer.Ports;
                    }
                    string name = cmdName.Substring(Common.CmdPrefixBlast.Length);

                    IREditor learnIR = new IREditor(_LearnIrFunc, _BlastFunc, ports, name);
                    if (learnIR.ShowDialog(this) == DialogResult.OK)
                    {
                        newCommand = Common.CmdPrefixBlast + learnIR.CommandString;
                        name       = learnIR.BlastName;
                    }

                    RefreshBlastList(name);
                }
                else if (cmdName.StartsWith(Common.CmdPrefixMacro, StringComparison.OrdinalIgnoreCase))
                {
                    if (modify)
                    {
                        string command  = cmdName.Substring(Common.CmdPrefixBlast.Length);
                        string fileName = Path.Combine(FolderMacros, command + Common.FileExtensionMacro);
                        if (File.Exists(fileName))
                        {
                            MacroEditor macroEditor = new MacroEditor(command, IRServer, _BlastFunc, _LearnIrFunc, _ProcessCommand);
                            macroEditor.ShowDialog(this);
                            RefreshMacroList(macroEditor.MacroName);
                            if (macroEditor.DialogResult == DialogResult.OK)
                            {
                                cmdName = Common.CmdPrefixMacro + macroEditor.MacroName;
                            }
                            else
                            {
                                cmdName = null;
                            }
                        }
                        else
                        {
                            MessageBox.Show(this, "File not found: " + fileName, "Macro file missing", MessageBoxButtons.OK,
                                            MessageBoxIcon.Exclamation);
                        }
                    }

                    newCommand = cmdName;
                }
                else
                {
                    throw new CommandStructureException(String.Format("Unknown macro command ({0})", cmdName));
                }
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                MessageBox.Show(this, ex.Message, "Failed to add macro command", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(newCommand);
        }