Esempio n. 1
0
        /// <summary>
        /// 开始考试 生成考试号  服务端
        /// </summary>
        private bool BeginExamApi()
        {
            var ml = new BeginExamModel()
            {
                exam_id = GlobalUser.SelectPaperNumber.Split('#')[0]
            };

            var result1 = WebProxy(ml, ApiType.BeginExam, GlobalUser.USER.Token);

            if (result1.retCode == 4001 && result1.retMsg.ToLower().Contains("token"))
            {
                //回到登录
                GlobalUser.CleanUp();
                Messenger.Default.Send(new ExamScoreNavigateMessage(), "LoginFailure");

                return(false);
            }

            if (result1.retCode == 40400)
            {
                Messenger.Default.Send(new MainDialogMessage(result1.retMsg), "MainMessageDialog");
                return(false);
            }

            GlobalUser.AttendPaperItemId = result1.retData.exam_attend_id;

            GlobalUser.SelectExamAttendResult = "";
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// 绑定选中试卷信息
        /// </summary>
        /// <param name="OutMsg">是否显示异常消息  true 显示</param>
        /// <returns></returns>
        public bool BindPaperInfo(bool OutMsg = true)
        {
            var ml = new GetPaperInfoDetail()
            {
                exam_id = GlobalUser.SelectPaperNumber.Split('#')[0],
                token   = GlobalUser.USER.Token
            };

            ApiType api = ApiType.GetPaperInfoDetail;

            if (GlobalUser.MenuType == MenuType.Task)
            {
                api = ApiType.GetUserHomeworkDetail;
            }

            var result1 = WebProxy(ml, api, null, "get");

            if (result1.retCode == 4001 && result1.retMsg.ToLower().Contains("token"))
            {
                //回到登录
                GlobalUser.CleanUp();
                if (OutMsg)
                {
                    Messenger.Default.Send(new ExamScoreNavigateMessage(), "LoginFailure");
                }

                return(false);
            }

            if (result1.retCode == 40400)
            {
                if (OutMsg)
                {
                    Messenger.Default.Send(new MainDialogMessage(result1.retMsg), "MainMessageDialog");
                }
                return(false);
            }

            GlobalUser.SelectPaperInfo =
                JsonHelper.FromJson <Paper_Info>(result1.retData.paper_info.ToString());

            GlobalUser.SelectExamAttendResult = result1.retData.exam_attend_result.ToString().Replace("[]", "");

            GlobalUser.SelectExamAttend =
                JsonHelper.FromJson <Exam_Attend>(result1.retData.exam_attend.ToString());

            return(true);
        }
Esempio n. 3
0
        private void UpdateAnswer(string scoreJson)
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                string errStr     = "";
                ErrMsgLog msgInfo = new ErrMsgLog();
                msgInfo.user      = GlobalUser.USER.Mobile;

                if (GlobalUser.ErrScoreInfo == null)
                {
                    GlobalUser.ErrScoreInfo = new Dictionary <string, ExamScoreNavigateMessage>();
                }

                try
                {
                    if (!GlobalUser.DoAnswer)
                    {
                        //errStr = $"评分失败 -- result: 当前不是做题过程!";
                        msgInfo.msginfo      = "评分失败";
                        msgInfo.error        = "当前不是做题过程";
                        msgInfo.isErr        = true;
                        GlobalUser.DoneScore = ScoreType.NoScore;
                        Log4NetHelper.Error(msgInfo.ToJson());
                        return;
                    }

                    ScoreRoot score = JsonHelper.FromJson <ScoreRoot>(scoreJson.Replace("\"params\"", "\"param\""));

                    if (!string.IsNullOrEmpty(score.errId))
                    {
                        //20009   网络无效
                        //20013   评分超时
                        //20010   调用顺序出错
                        //42003   请求顺序出错
                        //可以重评
                        if (_errIds.Contains(score.errId))
                        {
                            ExamScore.SubmitNum++;
                        }
                        else
                        {
                            ExamScore.SubmitNum = 999;
                        }

                        if (!GlobalUser.ErrScoreInfo.ContainsKey(ExamScore.WaveFileName))
                        {
                            GlobalUser.ErrScoreInfo.Add(ExamScore.WaveFileName, ExamScore);
                        }
                        throw new Exception($"评分失败 errID:{score.errId}");
                    }

                    string scoreStr = "0";

                    if (ExamScore.EType == EngineType.CHOICE)
                    {
                        var answer =
                            ExamScore.AnswerModel.item_answer.Split(new string[] { "|" }, StringSplitOptions.None);

                        ExamScore.AnswerModel.item_answer = answer[answer.Length - 1];

                        if (score.result.confidence >= (ExamScore.AnswerModel.item_score * 0.45) &&
                            ExamScore.AnswerModel.item_answer.ToLower().Trim()
                            .Equals(score.result.recognition.ToLower().Trim()))
                        {
                            scoreStr = ExamScore.AnswerModel.item_score.ToString("f2");
                        }
                    }
                    else
                    {
                        scoreStr = score.result.overall
                                   .ToString(); //((score.result.overall / 100) * ExamScore.AnswerModel.item_score).ToString("f2");
                    }

                    ExamScore.AnswerModel.user_answer = scoreJson.TrimEnd('\0');

                    ExamScore.AnswerModel.exam_score = Convert.ToSingle(scoreStr); //Convert.ToSingle(scoreStr);

                    if (ExamScore.AnswerModel.item_score < 0)
                    {
                        ExamScore.AnswerModel.exam_score = Math.Abs(ExamScore.AnswerModel.item_score);
                    }

                    var result = WebApiProxy.GetHtmlRespInfo(ExamScore.AnswerModel, ApiType.SubmitRecord,
                                                             GlobalUser.USER.Token);

                    Log4NetHelper.Info($"完成评分 -- result:{result.retCode == 1} {result.retCode} {result.retMsg}");

                    //Log4NetHelper.Info($"完成评分 -- 音频文件: {ExamScore.WaveFileName}");

                    GlobalUser.DoneItemExam = true;
                    GlobalUser.DoneScore    = ScoreType.ScoreSuccess; //评分
                    if (result?.retCode != 0)
                    {
                        //errStr = $"errmsg:上传评分失败,result:{result.retCode} {result.retCode} {result.retMsg}";
                        msgInfo.msginfo = "上传评分失败";
                        msgInfo.error   = $"{result.retCode} {result.retCode} {result.retMsg}";
                        msgInfo.isErr   = true;

                        GlobalUser.DoneScore = ScoreType.ScoreFailure;
                        Log4NetHelper.Error(msgInfo.ToJson());

                        if (result.retCode == 4001 && result.retMsg.Contains("密码"))
                        {
                            //回到登录
                            GlobalUser.CleanUp();
                            Messenger.Default.Send(new ExamScoreNavigateMessage(), "LoginFailure");
                            //errStr += ",LoginFailure:已在其他设备登录!";
                            msgInfo.error += ",已在其他设备登录";
                            msgInfo.isErr  = true;
                        }
                    }
                    else
                    {
                        msgInfo.isErr = false;
                        if (GlobalUser.ErrScoreInfo != null && GlobalUser.ErrScoreInfo.Count > 0)
                        {
                            //移除异常记录
                            if (GlobalUser.ErrScoreInfo.ContainsKey(ExamScore.WaveFileName))
                            {
                                GlobalUser.ErrScoreInfo.Remove(ExamScore.WaveFileName);
                            }
                            else
                            {
                                foreach (var key in GlobalUser.ErrScoreInfo.Keys)
                                {
                                    if (GlobalUser.ErrScoreInfo.Values.ToList().Where(w =>
                                                                                      w.AnswerModel.exam_attend_id == GlobalUser.AttendPaperItemId &&
                                                                                      w.AnswerModel.item_id == ExamScore.AnswerModel.item_id).Any())
                                    {
                                        GlobalUser.ErrScoreInfo.Remove(key);
                                        break;
                                    }
                                }
                            }

                            GlobalUser.UpdateErrScore(GlobalUser.USER.Mobile,
                                                      GlobalUser.SelectPaperNumber,
                                                      GlobalUser.AttendPaperItemId);
                        }

                        if (File.Exists(Path.Combine(ExamScore.WaveFileName)))
                        {
                            File.Delete(ExamScore.WaveFileName);
                        }

                        if (GlobalUser.MenuType == MenuType.Sync)
                        {
                            //更新 当前 同步 评分
                            Messenger.Default.Send(
                                new SyncScoreCallbckMessage(ExamScore.ModelTarget, score, ExamScore.EType),
                                ExamScore.ModelTarget);
                            //更新 左侧列表 得分
                            Messenger.Default.Send(
                                new SyncUploadScoreCallbckMessage(ExamScore.ModelTarget, Convert.ToInt32(score.result.overall), ExamScore.AnswerModel.item_id),
                                "SyncUploadScoreNavi");
                        }
                    }
                }
                catch (Exception ex)
                {
                    //errStr = $"[user:{GlobalUser.USER?.Mobile},error:{ex},scoreJson: {scoreJson}]";
                    msgInfo.msginfo   = "上传评分失败";
                    msgInfo.error     = ex;
                    msgInfo.scoreJson = scoreJson;
                    msgInfo.isErr     = true;

                    Log4NetHelper.Error(msgInfo.ToJson());
                    //Log4NetHelper.Error($"scoreJson: {scoreJson}");
                    Log4NetHelper.Error($"record url: {ExamScore.WaveFileName}");
                }
                finally
                {
                    if (msgInfo.isErr)
                    {
                        GlobalUser.DoneScore = ScoreType.ScoreFailure;

                        if (!GlobalUser.ErrScoreInfo.ContainsKey(ExamScore.WaveFileName))
                        {
                            ExamScore.SubmitNum++;
                            GlobalUser.ErrScoreInfo.Add(ExamScore.WaveFileName, ExamScore);
                        }

                        GlobalUser.UpdateErrScore(GlobalUser.USER.Mobile,
                                                  GlobalUser.SelectPaperNumber,
                                                  GlobalUser.AttendPaperItemId);

                        Log_Data log   = new Log_Data();
                        log.log_desc   = Log_Type.PC_Score.ToString();
                        log.log_text   = msgInfo.ToJson();
                        log.log_device = JsonHelper.ToJson(GlobalUser.MACHINEINFO.GetDevice());
                        WebApiProxy.GetHtmlRespInfo(log, ApiType.SysLog, null, "Post");
                    }
                }
            }));
        }