private void HandleChatResponseMsg(ChatRequestResponse resp, TalkBackDBContext dbContext) { // first check that the addressee is in the dictionary: WebSocket peer; if (!WebSocketMiddleware._sockets.TryGetValue(resp.To, out peer)) { // not found -- ignore return; } string strMsg = resp.ToXml().ToString(); WebSocketMiddleware.SendStringAsync(peer, strMsg); return; }
private void HandleChatMessageMsg(MessageModel msg, TalkBackDBContext dbContext) { // first check that the addressee is in the dictionary: WebSocket peer; if (!WebSocketMiddleware._sockets.TryGetValue(msg.To, out peer)) { // not found -> send a ChatRequestResponse with failure: ChatRequestResponse resp = new ChatRequestResponse { Success = false, ErrorMessage = "Chat peer is not online" }; WebSocketMiddleware.SendStringAsync(_webSocket, resp.ToXml().ToString()); return; } // save message in the log: Message dbMessage = new Message { Content = msg.Content, ReceiverName = msg.To, SenderName = msg.From, Time = DateTime.Now }; try { dbContext.Message.Add(dbMessage); dbContext.SaveChanges(); } catch (Exception ex) { //do nothing } // send the message to both sender and receiver: string strMsg = msg.ToXml().ToString(); WebSocketMiddleware.SendStringAsync(_webSocket, strMsg); WebSocketMiddleware.SendStringAsync(peer, strMsg); return; }
private void HandleChatRequestMsg(ChatRequest req, TalkBackDBContext dbContext) { // first check that the addressee is in the dictionary: WebSocket peer; if (!WebSocketMiddleware._sockets.TryGetValue(req.To, out peer)) { // not found -> send a ChatRequestResponse with failure: ChatRequestResponse resp = new ChatRequestResponse { Success = false, ErrorMessage = "Chat peer is not online" }; WebSocketMiddleware.SendStringAsync(_webSocket, resp.ToXml().ToString()); return; } string strMsg = req.ToXml().ToString(); WebSocketMiddleware.SendStringAsync(peer, strMsg); return; }