|
@@ -3,6 +3,7 @@ using IES.ExamServer.DI;
|
|
|
using IES.ExamServer.DI.SignalRHost;
|
|
|
using IES.ExamServer.Filters;
|
|
|
using IES.ExamServer.Helper;
|
|
|
+using IES.ExamServer.Helpers;
|
|
|
using IES.ExamServer.Models;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
@@ -26,7 +27,6 @@ namespace IES.ExamServer.Controllers
|
|
|
private readonly DataCenterConnectionService _connectionService;
|
|
|
private readonly int DelayMicro = 10;//微观数据延迟
|
|
|
private readonly int DelayMacro = 100;//宏观数据延迟
|
|
|
-
|
|
|
private readonly SignalRExamServerHub _signalRExamServerHub;
|
|
|
public ManageController(LiteDBFactory liteDBFactory,ILogger<ManageController> logger, IConfiguration configuration,
|
|
|
IHttpClientFactory httpClientFactory, IMemoryCache memoryCache, DataCenterConnectionService connectionService,SignalRExamServerHub signalRExamServerHub)
|
|
@@ -43,11 +43,12 @@ namespace IES.ExamServer.Controllers
|
|
|
[AuthToken("admin","teacher")]
|
|
|
public async Task<IActionResult> DownloadPackage(JsonNode json)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
//C#.NET 6 后端与前端流式通信
|
|
|
//https://www.doubao.com/chat/collection/687687510791426?type=Thread
|
|
|
//下载日志记录:1.步骤,检查,2.获取描述信息,3.分类型,4下载文件,5.前端处理,6.返回结果 , 正在下载...==> [INFO]https://www.doubao.com/chat/collection/687687510791426?type=Thread [Size=180kb] Ok...
|
|
|
//进度条 展示下载文件总大小和已下载,末尾展示 文件总个数和已下载个数
|
|
|
+ //https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/8.0.7/signalr.min.js
|
|
|
return Ok();
|
|
|
}
|
|
|
[HttpPost("check-short-code")]
|
|
@@ -56,6 +57,7 @@ namespace IES.ExamServer.Controllers
|
|
|
|
|
|
string shortCode = $"{json["shortCode"]}";
|
|
|
string evaluationId = $"{json["evaluationId"]}";
|
|
|
+ string deviceId = $"{json["deviceId"]}";
|
|
|
Expression<Func<EvaluationClient, bool>> predicate = x => true;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(shortCode))
|
|
@@ -160,30 +162,159 @@ namespace IES.ExamServer.Controllers
|
|
|
status = 4;
|
|
|
_liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().Insert(evaluationLocal);
|
|
|
}
|
|
|
- List<int> file_intact = new List<int>();
|
|
|
+ List<string> file_error = new List<string>();
|
|
|
if (evaluationLocal!=null)
|
|
|
{
|
|
|
+
|
|
|
+
|
|
|
+ await _signalRExamServerHub.SendMessage(deviceId, Constant._Message_grant_type_check_file,
|
|
|
+ new MessageContent {messageType=Constant._Message_type_message, status=0, content="开始检查评测信息文件.." });
|
|
|
//校验本地文件数据
|
|
|
string packagePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "package");
|
|
|
if (!Directory.Exists(packagePath))
|
|
|
Directory.CreateDirectory(packagePath);
|
|
|
string evaluationPath = Path.Combine(packagePath, evaluationLocal.id!);
|
|
|
- await Task.Delay(DelayMacro);
|
|
|
- if (!System.IO.File.Exists(Path.Combine(evaluationPath, "evaluation.json")))
|
|
|
+ // await Task.Delay(DelayMacro);
|
|
|
+ int msg_status = Constant._Message_status_info;
|
|
|
+ string path_evaluation = Path.Combine(evaluationPath, "evaluation.json");
|
|
|
+ if (!System.IO.File.Exists(path_evaluation))
|
|
|
{
|
|
|
- file_intact.Add(0);
|
|
|
+ file_error.Add("evaluation");
|
|
|
+ msg_status=Constant._Message_status_error;
|
|
|
}
|
|
|
- await Task.Delay(DelayMacro);
|
|
|
- if (!System.IO.File.Exists(Path.Combine(evaluationPath, "groupList.json")))
|
|
|
+ else
|
|
|
{
|
|
|
- file_intact.Add(0);
|
|
|
+ msg_status=Constant._Message_status_success;
|
|
|
}
|
|
|
- await Task.Delay(DelayMacro);
|
|
|
- if (!System.IO.File.Exists(Path.Combine(evaluationPath, "source.json")))
|
|
|
+ //数据格式: [消息][信息/错误/警告][15:43]=>[开始检查评测信息文件...]
|
|
|
+ //数据格式: [检查][成功/失败][15:43]=>[评测数据文件:/wwwroot/package/623a9fe6-5445-0938-ff77-aeb80066ef27/evaluation.json]
|
|
|
+ //数据格式: [下载][成功/失败][15:43]=>[评测数据文件:/wwwroot/package/623a9fe6-5445-0938-ff77-aeb80066ef27/evaluation.json][1024kb][15ms]
|
|
|
+ await _signalRExamServerHub.SendMessage(deviceId, Constant._Message_grant_type_check_file,
|
|
|
+ new MessageContent { messageType= Constant._Message_type_check, status=msg_status,content=$"评测数据文件:{path_evaluation}" });
|
|
|
+ //await Task.Delay(DelayMacro);
|
|
|
+ string path_groupList = Path.Combine(evaluationPath, "groupList.json");
|
|
|
+ msg_status =Constant._Message_status_info;
|
|
|
+ if (!System.IO.File.Exists(path_groupList))
|
|
|
{
|
|
|
- file_intact.Add(0);
|
|
|
+ file_error.Add("groupList");
|
|
|
+ msg_status=Constant._Message_status_error;
|
|
|
}
|
|
|
- await Task.Delay(DelayMacro);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ msg_status=Constant._Message_status_success;
|
|
|
+ }
|
|
|
+ await _signalRExamServerHub.SendMessage(deviceId, Constant._Message_grant_type_check_file,
|
|
|
+ new MessageContent { messageType= Constant._Message_type_check, status=msg_status, content=$"评测名单文件:{path_groupList}" });
|
|
|
+ //await Task.Delay(DelayMacro);
|
|
|
+ string path_source = Path.Combine(evaluationPath, "source.json");
|
|
|
+ msg_status = Constant._Message_status_info;
|
|
|
+ if (!System.IO.File.Exists(path_source))
|
|
|
+ {
|
|
|
+ file_error.Add("source");
|
|
|
+ msg_status=Constant._Message_status_error;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ msg_status=Constant._Message_status_success;
|
|
|
+ }
|
|
|
+ await _signalRExamServerHub.SendMessage(deviceId, Constant._Message_grant_type_check_file,
|
|
|
+ new MessageContent { messageType= Constant._Message_type_check, status=msg_status, content=$"评测原始数据:{path_source}" });
|
|
|
+ // await Task.Delay(DelayMacro);
|
|
|
+ msg_status =Constant._Message_status_info;
|
|
|
+ try {
|
|
|
+
|
|
|
+ string evaluation_str = await System.IO.File.ReadAllTextAsync(path_evaluation);
|
|
|
+ JsonNode? evaluation_data = JsonSerializer.Deserialize<JsonNode>(evaluation_str);
|
|
|
+
|
|
|
+ if (evaluation_data!=null)
|
|
|
+ {
|
|
|
+ EvaluationClient? evaluationClient = JsonSerializer.Deserialize<EvaluationClient>(evaluation_data["evaluationClient"]);
|
|
|
+ if (evaluationClient!=null)
|
|
|
+ {
|
|
|
+ if ((!string.IsNullOrWhiteSpace(evaluationLocal.blobHash) && evaluationLocal.blobHash.Equals(evaluationClient.blobHash))
|
|
|
+ &&(evaluationLocal.blobTime==evaluationClient.blobTime)
|
|
|
+ &&(evaluationLocal.blobCount== evaluationClient.blobCount)
|
|
|
+ &&(evaluationLocal.blobSize== evaluationClient.blobSize)&& (evaluationLocal.dataTime==evaluationClient.dataTime)
|
|
|
+ &&(evaluationLocal.dataSize==evaluationClient.dataSize)&&(evaluationLocal.webviewCount==evaluationClient.webviewCount)
|
|
|
+ &&(evaluationLocal.webviewSize== evaluationClient.webviewSize)
|
|
|
+ &&(evaluationLocal.webviewTime== evaluationClient.webviewTime)
|
|
|
+ &&(!string.IsNullOrWhiteSpace(evaluationLocal.webviewPath)&& evaluationLocal.webviewPath.Equals(evaluationClient.webviewPath)))
|
|
|
+ {
|
|
|
+ msg_status=1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ msg_status=Constant._Message_status_error;
|
|
|
+ }
|
|
|
+ await _signalRExamServerHub.SendMessage(deviceId, Constant._Message_grant_type_check_file,
|
|
|
+ new MessageContent { messageType=Constant._Message_type_message, status=msg_status, content="校验本地数据文件..." });
|
|
|
+ }
|
|
|
+
|
|
|
+ List<EvaluationExam>? evaluationExams = JsonSerializer.Deserialize<List<EvaluationExam>>(evaluation_data["evaluationExams"]);
|
|
|
+ if (evaluationExams.IsNotEmpty())
|
|
|
+ {
|
|
|
+ string path_papers = Path.Combine(evaluationPath, "papers");
|
|
|
+ var papers_files = FileHelper.ListAllFiles(path_papers);
|
|
|
+ foreach (var evaluationExam in evaluationExams!)
|
|
|
+ {
|
|
|
+
|
|
|
+ int paperIndex = 0;
|
|
|
+ foreach (var paper in evaluationExam.papers)
|
|
|
+ {
|
|
|
+ paperIndex++;
|
|
|
+ List<MessageContent> contents = new List<MessageContent>();
|
|
|
+ int paper_error_count = 0;
|
|
|
+ foreach (var blobInfo in paper.blobs)
|
|
|
+ {
|
|
|
+ msg_status=Constant._Message_status_info;
|
|
|
+ if (!string.IsNullOrWhiteSpace(blobInfo.path))
|
|
|
+ {
|
|
|
+
|
|
|
+ var file = papers_files.Find(x => x.Contains(blobInfo.path));
|
|
|
+ if (file!=null)
|
|
|
+ {
|
|
|
+ msg_status=1;
|
|
|
+ msg_status=Constant._Message_status_success;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ msg_status=Constant._Message_status_error;
|
|
|
+ paper_error_count++;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ msg_status=Constant._Message_status_warning; ;
|
|
|
+ paper_error_count++;
|
|
|
+ }
|
|
|
+ contents.Add(new MessageContent { messageType=Constant._Message_type_check, status=msg_status, content=$"试卷文件信息:{paper.paperName}" });
|
|
|
+ }
|
|
|
+ int paper_msg_status = Constant. _Message_status_info;
|
|
|
+ if (paper_error_count>0)
|
|
|
+ {
|
|
|
+ paper_msg_status=Constant._Message_status_error;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ paper_msg_status=Constant._Message_status_success;
|
|
|
+ }
|
|
|
+ await _signalRExamServerHub.SendMessage(deviceId, Constant._Message_grant_type_check_file,
|
|
|
+ new MessageContent {
|
|
|
+ messageType=Constant._Message_type_message,
|
|
|
+ status=paper_msg_status,
|
|
|
+ content=$"试卷名称:[{paperIndex}]{evaluationExam.examName}-{evaluationExam.subjectName}-{paper.paperName}\r\n文件数量:{paper.blobs.Count()},检测成功数量:{contents.Count(x => x.status==Constant._Message_status_success)},检测异常数量{contents.Count(x => x.status==Constant._Message_status_error)}",
|
|
|
+ contents=contents
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ await _signalRExamServerHub.SendMessage(deviceId, Constant._Message_grant_type_check_file,
|
|
|
+ new MessageContent { messageType=Constant._Message_type_message, status=0, content="提取评测数据文件..." });
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return Ok(new {code=200, evaluation= evaluationLocal,data,blob,webview,dataSize,blobSize,webviewSize,status });
|