/// <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) { Log.Debug("TV2BlasterPlugin: 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); if (_inConfiguration) { MessageBox.Show(commands[1], commands[0], MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ShowNotifyDialog(commands[0], commands[1], int.Parse(commands[2])); } } else { ProcessCommand(command, false); } }
/// <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 = Path.Combine(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(Path.Combine(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(Path.Combine(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)); if (_inConfiguration) { MessageBox.Show(commands[1], commands[0], MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ShowNotifyDialog(commands[0], commands[1], int.Parse(commands[2])); } } else if (command.StartsWith(Common.CmdPrefixGotoScreen, StringComparison.OrdinalIgnoreCase)) { string screenID = command.Substring(Common.CmdPrefixGotoScreen.Length); if (_inConfiguration) { MessageBox.Show(screenID, Common.UITextGotoScreen, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ProcessGoTo(screenID, _mpBasicHome); } } else if (command.StartsWith(Common.CmdPrefixSendMPAction, StringComparison.OrdinalIgnoreCase)) { string[] commands = Common.SplitSendMPActionCommand(command.Substring(Common.CmdPrefixSendMPAction.Length)); if (_inConfiguration) { MessageBox.Show(commands[0], Common.UITextSendMPAction, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ProcessSendMediaPortalAction(commands); } } else if (command.StartsWith(Common.CmdPrefixSendMPMsg, StringComparison.OrdinalIgnoreCase)) { string[] commands = Common.SplitSendMPMsgCommand(command.Substring(Common.CmdPrefixSendMPMsg.Length)); if (_inConfiguration) { MessageBox.Show(commands[0], Common.UITextSendMPMsg, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ProcessSendMediaPortalMessage(commands); } } else if (command.StartsWith(Common.CmdPrefixExit, StringComparison.OrdinalIgnoreCase)) { if (_inConfiguration) { MessageBox.Show("Cannot exit MediaPortal in configuration", Common.UITextExit, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ExitMP(); } } else { throw new ArgumentException(String.Format("Cannot process unrecognized command \"{0}\"", command), "commandObj"); } } catch (Exception ex) { if (!String.IsNullOrEmpty(Thread.CurrentThread.Name) && Thread.CurrentThread.Name.Equals(ProcessCommandThreadName, StringComparison.OrdinalIgnoreCase)) { Log.Error(ex); } else { throw; } } }
/// <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(IrssUtils.Common.CmdPrefixMacro, StringComparison.OrdinalIgnoreCase)) { string fileName = Path.Combine(FolderMacros, command.Substring(IrssUtils.Common.CmdPrefixMacro.Length) + IrssUtils.Common.FileExtensionMacro); ProcMacro(fileName); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixBlast, StringComparison.OrdinalIgnoreCase)) { string[] commands = IrssUtils.Common.SplitBlastCommand(command.Substring(IrssUtils.Common.CmdPrefixBlast.Length)); BlastIR(Path.Combine(IrssUtils.Common.FolderIRCommands, commands[0] + IrssUtils.Common.FileExtensionIR), commands[1]); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixSTB, StringComparison.OrdinalIgnoreCase)) { string[] commands = IrssUtils.Common.SplitBlastCommand(command.Substring(IrssUtils.Common.CmdPrefixSTB.Length)); BlastIR(Path.Combine(IrssUtils.Common.FolderSTB, commands[0] + IrssUtils.Common.FileExtensionIR), commands[1]); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixPause, StringComparison.OrdinalIgnoreCase)) { int pauseTime = int.Parse(command.Substring(IrssUtils.Common.CmdPrefixPause.Length)); Thread.Sleep(pauseTime); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixRun, StringComparison.OrdinalIgnoreCase)) { string[] commands = IrssUtils.Common.SplitRunCommand(command.Substring(IrssUtils.Common.CmdPrefixRun.Length)); IrssUtils.Common.ProcessRunCommand(commands); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixSerial, StringComparison.OrdinalIgnoreCase)) { string[] commands = IrssUtils.Common.SplitSerialCommand(command.Substring(IrssUtils.Common.CmdPrefixSerial.Length)); IrssUtils.Common.ProcessSerialCommand(commands); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixWindowMsg, StringComparison.OrdinalIgnoreCase)) { string[] commands = IrssUtils.Common.SplitWindowMessageCommand(command.Substring(IrssUtils.Common.CmdPrefixWindowMsg.Length)); IrssUtils.Common.ProcessWindowMessageCommand(commands); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixTcpMsg, StringComparison.OrdinalIgnoreCase)) { string[] commands = IrssUtils.Common.SplitTcpMessageCommand(command.Substring(IrssUtils.Common.CmdPrefixTcpMsg.Length)); IrssUtils.Common.ProcessTcpMessageCommand(commands); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixHttpMsg, StringComparison.OrdinalIgnoreCase)) { string[] commands = IrssUtils.Common.SplitHttpMessageCommand(command.Substring(IrssUtils.Common.CmdPrefixHttpMsg.Length)); IrssUtils.Common.ProcessHttpCommand(commands); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixKeys, StringComparison.OrdinalIgnoreCase)) { string keyCommand = command.Substring(IrssUtils.Common.CmdPrefixKeys.Length); if (_inConfiguration) { MessageBox.Show(keyCommand, IrssUtils.Common.UITextKeys, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { IrssUtils.Common.ProcessKeyCommand(keyCommand); } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixMouse, StringComparison.OrdinalIgnoreCase)) { string mouseCommand = command.Substring(IrssUtils.Common.CmdPrefixMouse.Length); IrssUtils.Common.ProcessMouseCommand(mouseCommand); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixEject, StringComparison.OrdinalIgnoreCase)) { string ejectCommand = command.Substring(IrssUtils.Common.CmdPrefixEject.Length); IrssUtils.Common.ProcessEjectCommand(ejectCommand); } else if (command.StartsWith(IrssUtils.Common.CmdPrefixPopup, StringComparison.OrdinalIgnoreCase)) { string[] commands = IrssUtils.Common.SplitPopupCommand(command.Substring(IrssUtils.Common.CmdPrefixPopup.Length)); if (_inConfiguration) { MessageBox.Show(commands[1], commands[0], MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ShowNotifyDialog(commands[0], commands[1], int.Parse(commands[2])); } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixGotoScreen, StringComparison.OrdinalIgnoreCase)) { string screenID = command.Substring(IrssUtils.Common.CmdPrefixGotoScreen.Length); if (_inConfiguration) { MessageBox.Show(screenID, IrssUtils.Common.UITextGotoScreen, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ProcessGoTo(screenID, _mpBasicHome); } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixSendMPAction, StringComparison.OrdinalIgnoreCase)) { string[] commands = IrssUtils.Common.SplitSendMPActionCommand(command.Substring(IrssUtils.Common.CmdPrefixSendMPAction.Length)); if (_inConfiguration) { MessageBox.Show(commands[0], IrssUtils.Common.UITextSendMPAction, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ProcessSendMediaPortalAction(commands); } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixSendMPMsg, StringComparison.OrdinalIgnoreCase)) { string[] commands = IrssUtils.Common.SplitSendMPMsgCommand(command.Substring(IrssUtils.Common.CmdPrefixSendMPMsg.Length)); if (_inConfiguration) { MessageBox.Show(commands[0], IrssUtils.Common.UITextSendMPMsg, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ProcessSendMediaPortalMessage(commands); } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixExit, StringComparison.OrdinalIgnoreCase)) { if (_inConfiguration) { MessageBox.Show("Cannot exit MediaPortal in configuration", IrssUtils.Common.UITextExit, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ExitMP(); } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixHibernate, StringComparison.OrdinalIgnoreCase)) { if (_inConfiguration) { MessageBox.Show("Cannot Hibernate in configuration", IrssUtils.Common.UITextHibernate, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.Hibernate(); } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixReboot, StringComparison.OrdinalIgnoreCase)) { if (_inConfiguration) { MessageBox.Show("Cannot Reboot in configuration", IrssUtils.Common.UITextReboot, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.Reboot(); } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixShutdown, StringComparison.OrdinalIgnoreCase)) { if (_inConfiguration) { MessageBox.Show("Cannot Shutdown in configuration", IrssUtils.Common.UITextShutdown, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.ShutDown(); } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixStandby, StringComparison.OrdinalIgnoreCase)) { if (_inConfiguration) { MessageBox.Show("Cannot enter Standby in configuration", IrssUtils.Common.UITextStandby, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MPCommon.Standby(); } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixVirtualKB, StringComparison.OrdinalIgnoreCase)) { if (_inConfiguration) { MessageBox.Show("Cannot show Virtual Keyboard in configuration", IrssUtils.Common.UITextVirtualKB, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { VirtualKeyboard vk = new VirtualKeyboard(); if (vk.ShowDialog() == DialogResult.OK) { Keyboard.ProcessCommand(vk.TextOutput); } } } else if (command.StartsWith(IrssUtils.Common.CmdPrefixSmsKB, StringComparison.OrdinalIgnoreCase)) { if (_inConfiguration) { MessageBox.Show("Cannot show SMS Keyboard in configuration", IrssUtils.Common.UITextSmsKB, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { SmsKeyboard sms = new SmsKeyboard(); if (sms.ShowDialog() == DialogResult.OK) { Keyboard.ProcessCommand(sms.TextOutput); } } } else { throw new ArgumentException(String.Format("Cannot process unrecognized command \"{0}\"", command), "commandObj"); } } catch (Exception ex) { if (!String.IsNullOrEmpty(Thread.CurrentThread.Name) && Thread.CurrentThread.Name.Equals(ProcessCommandThreadName, StringComparison.OrdinalIgnoreCase)) { Log.Error(ex); } else { throw; } } }