private void ProcessNonsenseResult(NonsenseLogicResponse result) { if (ServerUtilities.msgIdToUserID[result.Msg_id] is NewAnswerNonsenseCheck) { if (result.Nonsense) { ProcessChatbotLogic.ProcessNonsenseAnswer((NewAnswerNonsenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]); } else { SendAnswerOffenseRequest((NewAnswerNonsenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]); } } else if (ServerUtilities.msgIdToUserID[result.Msg_id] is NewQuestionNonsenseCheck) { if (result.Nonsense) { ProcessChatbotLogic.ProcessNonsenseQuestion((NewQuestionNonsenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]); ChatbotWebSocketController.SendAnswerToQuestion(new ChatbotVariousServerResponses((NewQuestionNonsenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id])); } else { SendQuestionOffenseRequest((NewQuestionNonsenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]); } } }
private void ProcessOffenseResult(OffensivenessLogicResponse result) { if (ServerUtilities.msgIdToUserID[result.Msg_id] is NewAnswerOffenseCheck) { if (result.Offensive) { ProcessChatbotLogic.ProcessOffensiveAnswer((NewAnswerOffenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]); } else { //ProcessChatbotLogic.SaveQuestionToDatabase((NewQuestionNonsenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]); int answerId = ProcessChatbotLogic.SaveAnswerToOpenQuestion((NewAnswerOffenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]); String openAnswerModelUser = ProcessChatbotLogic.RetrieveOpenAnswer(((NewAnswerOffenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]).question_id); ChatbotWebSocketController.SendAnswerToQuestion(new ServerAnswerAfterQuestion(openAnswerModelUser, (NewAnswerOffenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id], result, answerId, ProcessNLPResponse.getQuestionFromID(((NewAnswerOffenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]).question_id))); } } else if (ServerUtilities.msgIdToUserID[result.Msg_id] is NewQuestionNonsenseCheck) { if (result.Offensive) { ProcessChatbotLogic.ProcessOffensiveAnswer((NewQuestionNonsenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]); ChatbotWebSocketController.SendAnswerToQuestion(new ChatbotVariousServerResponses((NewQuestionNonsenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id], false)); } else { ChatbotWebSocketController.ProcessProperQuestion((NewQuestionNonsenseCheck)ServerUtilities.msgIdToUserID[result.Msg_id]); } } }
private void HandleResponse(KeyValuePair <WEBSOCKET_RESPONSE_TYPE, List <BaseModel> > model) { //TODO: what should the websocket do with bad responses? if (model.Key == WEBSOCKET_RESPONSE_TYPE.NONE) { return; } switch (model.Key) { case WEBSOCKET_RESPONSE_TYPE.MATCH_QUESTION: try { { MatchQuestionLogicResponse result = ProcessNLPResponse.ProcessNLPMatchQuestionsResponse(model.Value.Cast <MatchQuestionModelResponse>().ToList().First()); if (result != null) { if (ServerUtilities.msgIdToUserID[result.Msg_id] is NewQuestion) { if (result.Match) { ChatbotWebSocketController.SendAnswerToQuestion(new ChatbotNewAnswerModel(result)); } else { var temp = ProcessChatbotLogic.GenerateModelCompareToOpenQuestions((NewQuestion)ServerUtilities.msgIdToUserID[result.Msg_id]); if (temp != null) { NLPWebSocketController.SendQuestionMatchRequest(temp); } } } else if (ServerUtilities.msgIdToUserID[result.Msg_id] is NewOpenQuestion) { if (result.Match) { ChatbotWebSocketController.SendAnswerToQuestion(new ChatbotNewAnswerModel(result)); } else { int question_id = ProcessChatbotLogic.SaveQuestionToDatabase((NewOpenQuestion)ServerUtilities.msgIdToUserID[result.Msg_id]); String user_id = ((NewOpenQuestion)ServerUtilities.msgIdToUserID[((MatchQuestionModelResponse)model.Value.First()).msg_id]).user_id; ChatbotWebSocketController.SendAnswerToQuestion(new ServerResponseNoAnswerToQuestion(result, (MatchQuestionModelResponse)model.Value.First(), question_id)); ProcessChatbotLogic.AddNewOpenAnswer(user_id, question_id); } } } } } catch (Exception e) { System.Diagnostics.Trace.Write(e.Message); } break; case WEBSOCKET_RESPONSE_TYPE.OFFENSIVENESS: { try { var result = ProcessNLPResponse.ProcessNLPOffensivenessResponse(model.Value.Cast <OffensivenessModelResponse>().ToList().First()); if (result is OffensivenessLogicResponse) { ProcessOffenseResult(result); } } catch (Exception e) { System.Diagnostics.Trace.Write(e.Message); } } break; case WEBSOCKET_RESPONSE_TYPE.NONSENSE: { try { NonsenseLogicResponse result = ProcessNLPResponse.ProcessNLPNonsenseResponse(model.Value.Cast <NonsenseModelResponse>().ToList().First()); if (result is NonsenseLogicResponse) { ProcessNonsenseResult(result); //SendQuestionOffenseRequest((NonsenseLogicResponse)result); } } catch (Exception e) { System.Diagnostics.Trace.Write(e.Message); } } break; } }