// // Notify callback for the TCP/IP Client // public void clientSocketNotificationHandler(ServiceNotification notify, ServiceStatus status, Reply reply, String msg) { SetClientStatus(status); String s = null; switch (notify) { case ServiceNotification.StatusChange: if (status == ServiceStatus.Started) { Logger.Instance.Log4.Debug("ClientSocketNotificationHandler - ServiceStatus.Started"); s = $"Connecting to {Settings.ClientHost}:{Settings.ClientPort}"; } else if (status == ServiceStatus.Connected) { Logger.Instance.Log4.Debug("ClientSocketNotificationHandler - ServiceStatus.Connected"); s = $"Connected to {Settings.ClientHost}:{Settings.ClientPort}"; } else if (status == ServiceStatus.Stopped) { Logger.Instance.Log4.Debug("ClientSocketNotificationHandler - ServiceStatus.Stopped"); s = "Stopped"; } else if (status == ServiceStatus.Sleeping) { Logger.Instance.Log4.Debug("ClientSocketNotificationHandler - ServiceStatus.Sleeping"); s = $"Waiting {(Settings.ClientDelayTime / 1000)} seconds to connect"; } break; case ServiceNotification.ReceivedData: Logger.Instance.Log4.Info($"Client: Received; {msg}"); ReceivedData(reply, (string)msg); return; case ServiceNotification.Error: Logger.Instance.Log4.Debug($"ClientSocketNotificationHandler - ServiceStatus.Error: {(string)msg}"); Logger.Instance.Log4.Info($"Client: Error; {(string)msg}"); RestartClient(); return; default: s = "Unknown notification"; break; } Logger.Instance.Log4.Info($"Client: {s}"); }
// // Notify callback for the Serial Server // public void HandleSerialServerNotifications(ServiceNotification notify, ServiceStatus status, Reply reply, String msg) { SetSerialStatus(status); String s = null; switch (notify) { case ServiceNotification.StatusChange: switch (status) { case ServiceStatus.Started: s = $"SerialServer: Opening port: {msg}"; break; case ServiceStatus.Waiting: s = $"SerialServer: Waiting for commands on {msg}..."; //SetStatus("Waiting for Serial commands..."); break; case ServiceStatus.Stopped: s = "SerialServer: Stopped"; //SetStatus("Serial Server Not Active"); break; } break; case ServiceNotification.ReceivedData: Logger.Instance.Log4.Info($"SerialServer: Received: {msg}"); ReceivedData(reply, (string)msg); return; case ServiceNotification.Error: s = $"SerialServer: Error: {msg}"; break; default: s = "SerialServer: Unknown notification"; break; } Logger.Instance.Log4.Info(s); }
public void serverSocketCallbackHandler(ServiceNotification notification, ServiceStatus status, Reply reply, String msg) { if (notification == ServiceNotification.StatusChange) { HandleSocketServerStatusChange(status); } else { HandleSocketServerNotification(notification, status, (SocketServer.ServerReplyContext)reply, msg); } }
public void Execute(Reply reply, String cmd) { if (!MainWindow.MainWnd.Settings.DisableInternalCommands) { if (cmd.StartsWith(McecCommand.CmdPrefix)) { var command = new McecCommand(cmd); command.Execute(reply); return; } if (cmd.StartsWith("chars:")) { // "chars:<chars> String chars = Regex.Unescape(cmd.Substring(6, cmd.Length - 6)); MainWindow.AddLogEntry(String.Format("Cmd: Sending {0} chars: {1}", chars.Length, chars)); var sim = new InputSimulator(); sim.Keyboard.TextEntry(chars); return; } if (cmd.StartsWith("api:")) { // "api:API(params) // TODO: Implement API stuff return; } if (cmd.StartsWith("shiftdown:")) { // Modifyer key down SendInputCommand.ShiftKey(cmd.Substring(10, cmd.Length - 10), true); return; } if (cmd.StartsWith("shiftup:")) { // Modifyer key up SendInputCommand.ShiftKey(cmd.Substring(8, cmd.Length - 8), false); return; } if (cmd.StartsWith(MouseCommand.CmdPrefix)) { // mouse:<action>[,<parameter>,<parameter>] var mouseCmd = new MouseCommand(cmd); mouseCmd.Execute(reply); return; } if (cmd.Length == 1) { // It's a single character, just send it // must be upper case (VirtualKeyCode codes are for upper case) cmd = cmd.ToUpper(); char c = cmd.ToCharArray()[0]; var sim = new InputSimulator(); MainWindow.AddLogEntry("Cmd: Sending keydown for: " + cmd); sim.Keyboard.KeyPress((VirtualKeyCode)c); return; } } // Command is in MCEControl.commands if (_hashTable.ContainsKey(cmd.ToUpper())) { Command command = FindKey(cmd.ToUpper()); command.Execute(reply); } else { MainWindow.AddLogEntry("Cmd: Unknown Cmd: " + cmd); } }
public virtual void Execute(Reply reply) { }
protected void SendNotification(ServiceNotification notification, ServiceStatus status, Reply replyContext = null, String msg = "") { Notifications?.Invoke(notification, status, replyContext, msg); }
public override ICommand Clone(Reply reply) => base.Clone(reply, new McecCommand());