public virtual void friendLoggedOut(chat.model.User friend) { Console.WriteLine("Friend logged out " + friend); try { sendResponse(ProtoUtils.createFriendLoggedOutResponse(friend)); } catch (Exception e) { Console.WriteLine(e.StackTrace); } }
public virtual void messageReceived(chat.model.Message message) { Console.WriteLine("Message received " + message); try { sendResponse(ProtoUtils.createNewMessageResponse(message)); } catch (Exception e) { throw new ChatException("Sending error: " + e); } }
public virtual void friendLoggedIn(chat.model.User friend) { //UserDTO udto =DTOUtils.getDTO(friend); Console.WriteLine("Friend logged in " + friend); try { sendResponse(ProtoUtils.createFriendLoggedInResponse(friend)); } catch (Exception e) { Console.WriteLine(e.StackTrace); } }
private ChatResponse handleRequest(ChatRequest request) { ChatResponse response = null; ChatRequest.Types.Type reqType = request.Type; switch (reqType) { case ChatRequest.Types.Type.Login: { Console.WriteLine("Login request ..."); //LoginRequest logReq =(LoginRequest)request; //UserDTO udto =logReq.User; chat.model.User user = ProtoUtils.getUser(request); try { lock (server) { server.login(user, this); } return(ProtoUtils.createOkResponse()); } catch (ChatException e) { connected = false; return(ProtoUtils.createErrorResponse(e.Message)); } } case ChatRequest.Types.Type.Logout: { Console.WriteLine("Logout request"); //LogoutRequest logReq =(LogoutRequest)request; //UserDTO udto =logReq.User; chat.model.User user = ProtoUtils.getUser(request); try { lock (server) { server.logout(user, this); } connected = false; return(ProtoUtils.createOkResponse()); } catch (ChatException e) { return(ProtoUtils.createErrorResponse(e.Message)); } } case ChatRequest.Types.Type.SendMessage: { Console.WriteLine("SendMessageRequest ..."); //SendMessageRequest senReq =(SendMessageRequest)request; //MessageDTO mdto =senReq.Message; chat.model.Message message = ProtoUtils.getMessage(request); try { lock (server) { server.sendMessage(message); } return(ProtoUtils.createOkResponse()); } catch (ChatException e) { return(ProtoUtils.createErrorResponse(e.Message)); } } case ChatRequest.Types.Type.GetLoggedFriends: { Console.WriteLine("GetLoggedFriends Request ..."); //GetLoggedFriendsRequest getReq =(GetLoggedFriendsRequest)request; //UserDTO udto =getReq.User; chat.model.User user = ProtoUtils.getUser(request); //DTOUtils.getFromDTO(udto); try { chat.model.User[] friends; lock (server) { friends = server.getLoggedFriends(user); } //UserDTO[] frDTO =DTOUtils.getDTO(friends); return(ProtoUtils.createLoggedFriendsResponse(friends)); } catch (ChatException e) { return(ProtoUtils.createErrorResponse(e.Message)); } } } return(response); }