public void ExecuteCommand <T>(IMssgsCommand <T> command, Handler <T> callback) where T : MssgsResponse { if (!this.IsConnected) { throw new Exception("Please connect first before you execute commands!"); } if (!this.IsWelcomed) { throw new Exception("The server needs to welcome you first before you can execute commands!"); } this.UnregisterResponseFactory(command.Method); this.RegisterResponseFactory <T>(command.Method, command.CreateResponse); var jsonObject = new Dictionary <string, object>(); jsonObject["method"] = command.Method; jsonObject["data"] = command.Data; string json = SimpleJson.SimpleJson.SerializeObject(jsonObject); this.OutgoingData.Enqueue(json); this.ResponseReceived += (MssgsResponse response) => { if (command.Method != response.Method) { return; } this.UnregisterResponseFactory(command.Method); callback((T)response); }; }
public void ExecuteCommand(IMssgsCommand command) { if (!this.IsConnected) { throw new Exception("Please connect first before you execute commands!"); } if (!this.IsWelcomed) { throw new Exception("The server needs to welcome you first before you can execute commands!"); } var jsonObject = new Dictionary <string, object>(); jsonObject["method"] = command.Method; jsonObject["data"] = command.Data; string json = SimpleJson.SimpleJson.SerializeObject(jsonObject); this.OutgoingData.Enqueue(json); }