public void TestIdentify() { string[] identTag = new string[] { "testing", "123" }; Command c = new Command(Command.Type.Identify, identTag); SocketState ss = GetTestingSocketState(); CommandState cs = CommandHandler.HandleCommand(c, ss); if(((string[])ss.Tag) != identTag) { throw new Exception("Identity tag not saved correctly"); } if(!cs.UpdateForm) { throw new Exception("UpdateForm not set!"); } }
public static CommandState HandleCommand(Command c, SocketState cs) { CommandState cmdState = new CommandState(); switch (c.CommandType) { case Command.Type.Identify: cs.Tag = c.Arguments; cmdState.UpdateForm = true; break; case Command.Type.Screenshot: byte[] screenshotBytes = Convert.FromBase64String(c.Arguments[0]); #if DEBUG //File.WriteAllBytes("debugscreenshot.jpg", screenshotBytes); #endif cmdState.ReturnValue = screenshotBytes; break; } return cmdState; }
/// <summary> /// Calls all command handlers (LIFO) and stops when one handles command (returns true) /// </summary> public void HandleReceiveCommand(SocketState ss, Command c) { for (int i = OnReceiveCommandCallback.Count - 1; i >= 0; i--) { if (OnReceiveCommandCallback[i] == null) continue; bool handled = OnReceiveCommandCallback[i](ss, c); if (handled) break; } }
public void Stop() { Command disconnectCommand = new Command(Command.Type.Disconnect); foreach (KeyValuePair<string, SocketState> kvp in Clients) { this.Send(kvp.Value, disconnectCommand); } Clients = new ConcurrentDictionary<string, SocketState>(); Listen = false; Listener.Close(150); }
public void Send(Command c) { this.Send(Utility.Serialize(c)); }
public void Send(SocketState ss, Command c) { this.Send(ss, Utility.Serialize(c)); }
public HandlesCommand(Command.Type typeToHandle) { this.TypeHandled = typeToHandle; }