private static Packet HandlePullResponsePacket(JObject json) { Packet p; switch (json["dataType"].ToString().ToLower()) { case "users": case "user": case "connected_clients": p = new PullUsersResponsePacket(json); break; case "measurements": p = new PullResponsePacket<Measurement>(json); break; case "user_sessions": p = new PullResponsePacket<SessionData>(json); break; default: return null; break; } return p; }
public void HandlePullPacket(JObject json) { Packet resp; switch (json["dataType"].ToString()) { case "user": JToken userid; json.TryGetValue("dataID", out userid); int userId; int.TryParse((string)userid,out userId); var useristList = new List<User> {_dbConnect.getUser(userId)}; resp = new PullUsersResponsePacket(useristList, "user"); break; case "users": resp = new PullUsersResponsePacket(_database.GetAllUsers(), "User"); break; case "connected_clients": resp = new PullUsersResponsePacket(Authentication.GetClients(), "connected_clients"); break; case "user_sessions": resp = new PullResponsePacket<SessionData>(_database.GetTrainingSessions(), "user_sessions"); break; case "measurements": HandleLsmPacket(json); return; default: Console.WriteLine(Resources.ClientHandler_HandlePullPacket_Non_implemented_data_type + json["dataType"].ToString()); return; } //Console.WriteLine(json); string data = resp.ToString(); Send(data); }
public void HandleLsmPacket(JObject json) { JToken sessionId; JToken username; JToken UserId; json.TryGetValue("sessionID", out sessionId); json.TryGetValue("username", out username); json.TryGetValue("dataId", out UserId); var measurements = _dbConnect.getMeasurementsOfUser(username == null ? UserId.ToString() : username.ToString(), json["sessionID"].ToString()); var response = new PullResponsePacket<Measurement>(measurements,"measurements"); //Send the result back to the specialist. Console.WriteLine(response.ToString()); Send(response.ToString()); }
public static Packet GetPacketFromJson(JObject json) { if (json == null) return null; Packet p = null; switch ((string)json.GetValue("CMD", StringComparison.CurrentCultureIgnoreCase)) { //case ChatPacket.DefCmd: // p = new ChatPacket(json); // break; case DisconnectPacket.DefCmd: p = new DisconnectPacket(json); break; case LoginPacket.DefCmd: p = new LoginPacket(json); break; case LoginResponsePacket.DefCmd: p = new LoginResponsePacket(json); break; case SerialDataPushPacket.DefCmd: p = new SerialDataPushPacket(json); break; //case RegisterPacket.DefCmd: // p = new RegisterPacket(json); // break; //case RegisterResponsePacket.DefCmd: // p = new RegisterResponsePacket(json); // break; case UserChangedPacket.DefCmd: p = new UserChangedPacket(json); break; case PullResponsePacket.DefCmd: p = new PullResponsePacket<User>(json); break; default: try { p = new ResponsePacket(json); } catch (ArgumentException) { } break; } return p; }