示例#1
0
        /// <summary>
        /// 更新最佳选项到db
        /// </summary>
        /// <param name="session"></param>
        private static void UpdateCorrectOptions(Session session)
        {
            var kingRequest = KingRequest.FromSession(session);
            var kingAnswer  = KingAnswer.FromSession(session);

            if (kingAnswer == null || kingAnswer.IsValidate() == false)
            {
                return;
            }

            var context = KingContextTable.TakeByRequest(kingRequest);

            if (context == null)
            {
                return;
            }

            using (var sqlLite = new SqlliteContext())
            {
                var quiz       = context.KingQuestion.data.quiz;
                var quizAnswer = sqlLite.QuizAnswer.Find(quiz);

                if (quizAnswer != null)
                {
                    quizAnswer.Answer = context.GetAnswer(kingAnswer);
                    sqlLite.SaveChanges();
                    Console.WriteLine($"更新正确答案到db:{Environment.NewLine}{quizAnswer}");
                }
            }
        }
示例#2
0
        /// <summary>
        /// 更新最佳选项并保存
        /// </summary>
        /// <param name="session"></param>
        private static void UpdateBestAndSave(Session session)
        {
            session.utilDecodeRequest();
            session.utilDecodeResponse();

            var requestBody  = Encoding.UTF8.GetString(session.RequestBody);
            var responseBody = Encoding.UTF8.GetString(session.ResponseBody);

            var kingRequest = KingRequest.Parse(requestBody);
            var kingAnswer  = KingAnswer.Parse(responseBody);

            if (kingAnswer != null && kingAnswer.data != null)
            {
                var data = HistoryDataTable.TryGet(kingRequest);
                if (data != null)
                {
                    var index = kingAnswer.data.answer - 1;
                    data.SearchResult.Best = data.SearchResult.Options[index];
                }
            }
        }
示例#3
0
        /// <summary>
        /// 获取答案内容
        /// </summary>
        /// <param name="kingAnswer"></param>
        /// <returns></returns>
        public string GetAnswer(KingAnswer kingAnswer)
        {
            var index = kingAnswer.data.answer - 1;

            return(this.KingQuestion.data.options[index]);
        }