private int _ProcessJsonFileFolder(string FileFolder) { int result = 0; var fileContentArr = ReadJsonFile(FileFolder); string fileContent = fileContentArr[0]; if ((fileContent == "") || (fileContent == null)) { _WriteLogWithEnter("读取Json失败", 1); return(1); } _WriteLogWithEnter("开始检查Json文件: ", 0); JsonResult deserializedProduct = JsonConvert.DeserializeObject <JsonResult>(fileContent); if (deserializedProduct == null) { _WriteLogWithEnter("Json文件解析失败,请先检查json文件格式是否正确", 1); return(1); } Boolean jsonResult = ValidateJsonContent(deserializedProduct); if (true == jsonResult) { _WriteLogWithEnter("Json文件检查成功", 0); } else { _WriteLogWithEnter("Json文件检查失败", 1); result = 1; } fileContent = fileContentArr[1]; if ((fileContent != "") && (fileContent != null)) { JsonResult deserializedProduct_extend = JsonConvert.DeserializeObject <JsonResult>(fileContent); if (deserializedProduct_extend == null) { _WriteLogWithEnter("Extend Json文件解析失败,请先检查Extend json文件格式是否正确", 1); return(1); } var extendCourseFolder = new JsonFileProcessor(FileFolder + "_延伸", this.enCoding); var strArray = FileFolder.Split('\\'); extendCourseFolder.CourseName = strArray[strArray.Length - 1] + "_延伸"; Boolean jsonResult_extend = extendCourseFolder.ValidateJsonContent(deserializedProduct_extend); extendCourseFolder.ValidateFolderFiles(extendCourseFolder.CourseName); if (true == jsonResult_extend) { _WriteLogWithEnter("Extend Json文件检查成功", 0); } else { _WriteLogWithEnter("Extend Json文件检查失败", 1); result = 1; } } return(result); }
public Boolean ValidateJsonContent(JsonResult JsonContent) { Boolean result = true; string coursNameInJson = JsonContent.notetitle; if (coursNameInJson != this.CourseName) { _WriteLogWithEnter("NoteTile中的课程名《" + coursNameInJson + "》与文件夹名称不一致", 1); result = false; } int indexStart, indexEnd; string videoInJsonOfSection; CourseVideoInJsonOfLinkedVideo = JsonContent.linkedvideo; //匹配视频名称: 课程名_数字.mp4 或者 课程名.obb string regEpx = "^((" + coursNameInJson + "_)?\\d *\\.mp4)|(" + coursNameInJson + ".obb)"; foreach (string videoName in CourseVideoInJsonOfLinkedVideo) { if (!Regex.IsMatch(videoName, regEpx)) { _WriteLogWithEnter("LinkedVideo中的视频名称与notetile不一致:" + videoName, 1); result = false; } } foreach (CourseValidationTool_CSharp.Notecontent noteContent in JsonContent.notecontent) { if (noteContent.sectioncontent != null) { foreach (CourseValidationTool_CSharp.Sectioncontent sectionContent in noteContent.sectioncontent) { foreach (string section in sectionContent.section) { indexStart = section.IndexOf("播放课件《"); if (indexStart != -1) { indexEnd = section.IndexOf("》"); if (indexEnd != -1) { videoInJsonOfSection = section.Substring(indexStart + 5, indexEnd - indexStart - 5) + ".mp4"; if (CourseVideoInJsonOfLinkedVideo.IndexOf(videoInJsonOfSection) == -1) { _WriteLogWithEnter("Json sectioncontent中的视频在linkedvideo 中不存在\r\n 视频:" + videoInJsonOfSection, 1); result = false; } CourseVideoInJsonOfSecton.Add(videoInJsonOfSection); } } } } } } if (CourseVideoInJsonOfSecton.Count != CourseVideoInFolder.Count) { _WriteLogWithEnter("Json sectioncontent 包含的视频个数和文件夹中不一致" + " Json sectioncontent视频个数" + CourseVideoInJsonOfSecton.Count + " 文件夹中视频个数" + CourseVideoInFolder.Count , 1); result = false; } if (CourseVideoInJsonOfSecton.Count != CourseVideoInJsonOfLinkedVideo.Count - 1) { _WriteLogWithEnter("Json sectioncontent 包含的视频个数和 linkedvideo 中不一致\r\n" + " Json sectioncontent视频个数" + CourseVideoInJsonOfSecton.Count + " linkedvideo 中视频个数" + (CourseVideoInJsonOfLinkedVideo.Count - 1) , 1); result = false; } if (CourseVideoInJsonOfLinkedVideo.IndexOf(CourseName + ".obb") == -1) { _WriteLogWithEnter("《" + CourseName + ".obb 》在linkedvideo 中不存在", 1); result = false; } foreach (string courseName in CourseVideoInFolder) { if (CourseVideoInJsonOfLinkedVideo.IndexOf(courseName) == -1) { _WriteLogWithEnter("文件夹中的视频《" + courseName + "》在Json文件linkedvideo中未找到 ", 1); result = false; } else if (CourseVideoInJsonOfSecton.IndexOf(courseName) == -1) { _WriteLogWithEnter("文件夹中的视频《" + courseName + "》在Json文件sectioncontent中未找到 ", 1); result = false; } } return(result); }