Exemple #1
0
        /// <summary>
        /// Used by ProcessCommand to actually handle the command.
        /// Can be called Synchronously or as a Parameterized Thread.
        /// </summary>
        /// <param name="commandObj">Command string to process.</param>
        private static void ProcCommand(object commandObj)
        {
            try
            {
                if (commandObj == null)
                {
                    throw new ArgumentNullException("commandObj");
                }

                string command = commandObj as string;

                if (String.IsNullOrEmpty(command))
                {
                    throw new ArgumentException("commandObj translates to empty or null string", "commandObj");
                }

                if (command.StartsWith(Common.CmdPrefixMacro, StringComparison.OrdinalIgnoreCase))
                {
                    string fileName = FolderMacros + command.Substring(Common.CmdPrefixMacro.Length) + Common.FileExtensionMacro;
                    ProcMacro(fileName);
                }
                else if (command.StartsWith(Common.CmdPrefixBlast, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitBlastCommand(command.Substring(Common.CmdPrefixBlast.Length));
                    BlastIR(Common.FolderIRCommands + commands[0] + Common.FileExtensionIR, commands[1]);
                }
                else if (command.StartsWith(Common.CmdPrefixSTB, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitBlastCommand(command.Substring(Common.CmdPrefixSTB.Length));
                    BlastIR(Common.FolderSTB + commands[0] + Common.FileExtensionIR, commands[1]);
                }
                else if (command.StartsWith(Common.CmdPrefixPause, StringComparison.OrdinalIgnoreCase))
                {
                    int pauseTime = int.Parse(command.Substring(Common.CmdPrefixPause.Length));
                    Thread.Sleep(pauseTime);
                }
                else if (command.StartsWith(Common.CmdPrefixRun, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitRunCommand(command.Substring(Common.CmdPrefixRun.Length));
                    Common.ProcessRunCommand(commands);
                }
                else if (command.StartsWith(Common.CmdPrefixSerial, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitSerialCommand(command.Substring(Common.CmdPrefixSerial.Length));
                    Common.ProcessSerialCommand(commands);
                }
                else if (command.StartsWith(Common.CmdPrefixWindowMsg, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitWindowMessageCommand(command.Substring(Common.CmdPrefixWindowMsg.Length));
                    Common.ProcessWindowMessageCommand(commands);
                }
                else if (command.StartsWith(Common.CmdPrefixTcpMsg, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitTcpMessageCommand(command.Substring(Common.CmdPrefixTcpMsg.Length));
                    Common.ProcessTcpMessageCommand(commands);
                }
                else if (command.StartsWith(Common.CmdPrefixHttpMsg, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitHttpMessageCommand(command.Substring(Common.CmdPrefixHttpMsg.Length));
                    Common.ProcessHttpCommand(commands);
                }
                else if (command.StartsWith(Common.CmdPrefixKeys, StringComparison.OrdinalIgnoreCase))
                {
                    string keyCommand = command.Substring(Common.CmdPrefixKeys.Length);
                    if (_inConfiguration)
                    {
                        MessageBox.Show(keyCommand, Common.UITextKeys, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        Common.ProcessKeyCommand(keyCommand);
                    }
                }
                else if (command.StartsWith(Common.CmdPrefixEject, StringComparison.OrdinalIgnoreCase))
                {
                    string ejectCommand = command.Substring(Common.CmdPrefixEject.Length);
                    Common.ProcessEjectCommand(ejectCommand);
                }
                else if (command.StartsWith(Common.CmdPrefixPopup, StringComparison.OrdinalIgnoreCase))
                {
                    string[]         commands         = Common.SplitPopupCommand(command.Substring(Common.CmdPrefixPopup.Length));
                    ShowPopupMessage showPopupMessage = new ShowPopupMessage(commands[0], commands[1], int.Parse(commands[2]));
                    showPopupMessage.ShowDialog();
                }
                else
                {
                    throw new ArgumentException(String.Format("Cannot process unrecognized command \"{0}\"", command), "command");
                }
            }
            catch (Exception ex)
            {
                if (!String.IsNullOrEmpty(Thread.CurrentThread.Name) &&
                    Thread.CurrentThread.Name.Equals(ProcessCommandThreadName, StringComparison.OrdinalIgnoreCase))
                {
                    IrssLog.Error(ex);
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Processes the external channel change command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="channelDigit">The current channel digit.</param>
        /// <param name="channelFull">The channel full ID.</param>
        internal static void ProcessExternalCommand(string command, int channelDigit, string channelFull)
        {
            IrssLog.Debug("ProcessExternalCommand(\"{0}\", {1}, {2})", command, channelDigit, channelFull);

            if (command.StartsWith(Common.CmdPrefixRun, StringComparison.OrdinalIgnoreCase))
            {
                string[] commands = Common.SplitRunCommand(command.Substring(Common.CmdPrefixRun.Length));

                commands[2] = commands[2].Replace("%1", channelDigit.ToString());
                commands[2] = commands[2].Replace("%2", channelFull);

                Common.ProcessRunCommand(commands);
            }
            else if (command.StartsWith(Common.CmdPrefixSerial, StringComparison.OrdinalIgnoreCase))
            {
                string[] commands = Common.SplitSerialCommand(command.Substring(Common.CmdPrefixSerial.Length));

                commands[0] = commands[0].Replace("%1", channelDigit.ToString());
                commands[0] = commands[0].Replace("%2", channelFull);

                Common.ProcessSerialCommand(commands);
            }
            else if (command.StartsWith(Common.CmdPrefixWindowMsg, StringComparison.OrdinalIgnoreCase))
            {
                string[] commands = Common.SplitWindowMessageCommand(command.Substring(Common.CmdPrefixWindowMsg.Length));

                commands[3] = commands[3].Replace("%1", channelDigit.ToString());
                commands[3] = commands[3].Replace("%2", channelFull);

                commands[4] = commands[4].Replace("%1", channelDigit.ToString());
                commands[4] = commands[4].Replace("%2", channelFull);

                Common.ProcessWindowMessageCommand(commands);
            }
            else if (command.StartsWith(Common.CmdPrefixTcpMsg, StringComparison.OrdinalIgnoreCase))
            {
                string[] commands = Common.SplitTcpMessageCommand(command.Substring(Common.CmdPrefixTcpMsg.Length));

                commands[0] = commands[0].Replace("%1", channelDigit.ToString());
                commands[0] = commands[0].Replace("%2", channelFull);

                commands[2] = commands[2].Replace("%1", channelDigit.ToString());
                commands[2] = commands[2].Replace("%2", channelFull);

                Common.ProcessTcpMessageCommand(commands);
            }
            else if (command.StartsWith(Common.CmdPrefixHttpMsg, StringComparison.OrdinalIgnoreCase))
            {
                string[] commands = Common.SplitHttpMessageCommand(command.Substring(Common.CmdPrefixHttpMsg.Length));

                commands[0] = commands[0].Replace("%1", channelDigit.ToString());
                commands[0] = commands[0].Replace("%2", channelFull);

                Common.ProcessHttpCommand(commands);
            }
            else if (command.StartsWith(Common.CmdPrefixKeys, StringComparison.OrdinalIgnoreCase))
            {
                string keysCommand = command.Substring(Common.CmdPrefixKeys.Length);

                keysCommand = keysCommand.Replace("%1", channelDigit.ToString());
                keysCommand = keysCommand.Replace("%2", channelFull);

                if (_inConfiguration)
                {
                    MessageBox.Show(keysCommand, Common.UITextKeys, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    Common.ProcessKeyCommand(keysCommand);
                }
            }
            else if (command.StartsWith(Common.CmdPrefixPopup, StringComparison.OrdinalIgnoreCase))
            {
                string[] commands = Common.SplitPopupCommand(command.Substring(Common.CmdPrefixPopup.Length));

                commands[0] = commands[0].Replace("%1", channelDigit.ToString());
                commands[0] = commands[0].Replace("%2", channelFull);

                commands[1] = commands[1].Replace("%1", channelDigit.ToString());
                commands[1] = commands[1].Replace("%2", channelFull);

                ShowPopupMessage showPopupMessage = new ShowPopupMessage(commands[0], commands[1], int.Parse(commands[2]));
                showPopupMessage.ShowDialog();
            }
            else
            {
                ProcessCommand(command, false);
            }
        }