// ICommand:Execute public override void Execute() { if (this.Reply is null) { throw new InvalidOperationException("Reply property cannot be null."); } if (this.Args is null) { throw new InvalidOperationException("Args property cannot be null."); } var replyBuilder = new StringBuilder(); switch (Args.ToUpperInvariant()) { // MCE Controller version case "VER": replyBuilder.Append(Application.ProductVersion); break; // Cause MCE Controller to exit case "EXIT": Reply.WriteLine("exiting"); MainWindow.Instance.ShutDown(); return; // Return a list of supported commands (really just for testing) case "CMDS": Command cmd = this; Match match = null; try { replyBuilder.Append(Environment.NewLine); var orderedKeys = MainWindow.Instance.Invoker.Keys.Cast <string>().OrderBy(c => c); foreach (string key in orderedKeys) { cmd = (Command)MainWindow.Instance.Invoker[key]; var item = new ListViewItem(cmd.Key); match = Regex.Match(cmd.GetType().ToString(), @"MCEControl\.([A-za-z]+)Command"); replyBuilder.Append($"<{match.Groups[1].Value} {cmd.ToString()} />{Environment.NewLine}"); } } catch (Exception e) { Logger.Instance.Log4.Info($"{this.GetType().Name}: ({Key}:{Args}) <{match.Groups[1].Value} {cmd.ToString()}/> - {e.Message}"); } break; // Return the current date/time of the PC case "TIME": DateTime dt = DateTime.Now; replyBuilder.AppendFormat("{0}", DateTime.Now); break; } // Reply. replyBuilder.Insert(0, $"{Args}="); Logger.Instance.Log4.Info($"{this.GetType().Name}: Sending reply: {replyBuilder.ToString()}"); Reply.WriteLine(replyBuilder.ToString()); }
private void Reply(Reply reply, String msg) { MainWindow.AddLogEntry("Cmd: Sending reply: " + msg); reply.WriteLine(msg); }
public override void Execute(Reply reply) { if (reply == null) { return; } var replyBuilder = new StringBuilder(); switch (Key) { // MCE Controller version case "ver": replyBuilder.Append(Application.ProductVersion); break; // Cause MCE Controller to exit case "exit": reply.WriteLine("exiting"); MainWindow.MainWnd.BeginInvoke((Action)(() => MainWindow.MainWnd.ShutDown())); return; // Return a list of supported commands (really just for testing) case "cmds": foreach (Command cmd in MainWindow.MainWnd.CmdTable.List) { Match match = Regex.Match(cmd.GetType().ToString(), @"MCEControl\.([A-za-z]+)Command"); replyBuilder.AppendFormat("{0}={1}{2}", cmd.Key, match.Groups[1].Value, Environment.NewLine); } // Now add VK_ commands foreach (VirtualKeyCode vk in Enum.GetValues(typeof(VirtualKeyCode))) { string s; if (vk > VirtualKeyCode.HELP && vk < VirtualKeyCode.LWIN) { s = vk.ToString(); // already have VK_ } else { s = "VK_" + vk.ToString(); } replyBuilder.AppendFormat("{0}={1}{2}", s, "SendInput", Environment.NewLine); } break; // Return the current date/time of the PC case "time": DateTime dt = DateTime.Now; replyBuilder.AppendFormat("{0}", DateTime.Now); break; // These two are for testing. They cause a loop between two // instances of MCE Controller case "foo": reply.WriteLine("mcec:bar"); return; case "bar": reply.WriteLine("mcec:foo"); return; } // Reply. replyBuilder.Insert(0, String.Format("{0}=", Key)); Reply(reply, replyBuilder.ToString()); }