/// <summary> /// 获取测试信息 /// </summary> /// <param name="dir">测试目录名</param> /// <returns>TextInfo对象</returns> private TestInfo getTestInfo(String dir) { TestInfo ret = new TestInfo(); JObject obj; String json = File.ReadAllText(getTestsDir() + @"\" + dir + @"\testinfo" + ext); try { obj = (JObject)JsonConvert.DeserializeObject(json); } catch(JsonReaderException) { MessageBox.Show(null,"文件夹 " + dir + " 中testinfo" + ext + "读取失败!可能是json格式错误!","错误"); ret.Exists = false; return ret; } ret.Exists = true; ret.dir = dir; try { ret.name = obj["info"]["name"].ToString(); ret.desc = obj["info"]["desc"].ToString(); } catch (NullReferenceException) { MessageBox.Show(null, "测试 " + dir + " 加载失败!","提示"); ret.Exists = false; return ret; } subject[] sub = new subject[obj["subjects"].Count()]; for (int i = 0; i < obj["subjects"].Count(); ++i) { try { sub[i].name = obj["subjects"][i]["name"].ToString(); sub[i].memorylimit = int.Parse(obj["subjects"][i]["memorylimit"].ToString()); sub[i].desc = obj["subjects"][i]["desc"].ToString(); sub[i].dir = obj["subjects"][i]["folder"].ToString(); sub[i].option = obj["subjects"][i]["option"].ToString(); sub[i].points = int.Parse(obj["subjects"][i]["pointscount"].ToString()); sub[i].timelimit = int.Parse(obj["subjects"][i]["timelimit"].ToString()); } catch (NullReferenceException) { MessageBox.Show(null,"测试 " + ret.name + " 加载失败,可能存在缺少项!","提示"); ret.Exists = false; return ret; } catch (FormatException) { MessageBox.Show(null, "测试 " + ret.name + " 中testinfo" + ext + "存在格式错误!","提示"); } } ret.subjects = sub; //Additional options try { ret.additional = (JObject)obj["additional"]; } catch (NullReferenceException) { }; return ret; }
/// <summary> /// 获取测试信息 /// </summary> /// <param name="dir">测试目录名</param> /// <returns>TextInfo对象</returns> private TestInfo getTestInfo(String dir) { TestInfo ret = new TestInfo(); JObject obj; String json = File.ReadAllText(getTestsDir() + @"\" + dir + @"\testinfo" + ext); try { obj = (JObject)JsonConvert.DeserializeObject(json); } catch (JsonReaderException) { MessageBox.Show(null, "文件夹 " + dir + " 中testinfo" + ext + "读取失败!可能是json格式错误!", "错误"); ret.Exists = false; return(ret); } ret.Exists = true; ret.dir = dir; try { ret.name = obj["info"]["name"].ToString(); ret.desc = obj["info"]["desc"].ToString(); } catch (NullReferenceException) { MessageBox.Show(null, "测试 " + dir + " 加载失败!", "提示"); ret.Exists = false; return(ret); } subject[] sub = new subject[obj["subjects"].Count()]; for (int i = 0; i < obj["subjects"].Count(); ++i) { try { sub[i].name = obj["subjects"][i]["name"].ToString(); sub[i].memorylimit = int.Parse(obj["subjects"][i]["memorylimit"].ToString()); sub[i].desc = obj["subjects"][i]["desc"].ToString(); sub[i].dir = obj["subjects"][i]["folder"].ToString(); sub[i].option = obj["subjects"][i]["option"].ToString(); sub[i].points = int.Parse(obj["subjects"][i]["pointscount"].ToString()); sub[i].timelimit = int.Parse(obj["subjects"][i]["timelimit"].ToString()); } catch (NullReferenceException) { MessageBox.Show(null, "测试 " + ret.name + " 加载失败,可能存在缺少项!", "提示"); ret.Exists = false; return(ret); } catch (FormatException) { MessageBox.Show(null, "测试 " + ret.name + " 中testinfo" + ext + "存在格式错误!", "提示"); } } ret.subjects = sub; //Additional options try { ret.additional = (JObject)obj["additional"]; } catch (NullReferenceException) { }; return(ret); }
public FormTestView(TestInfo partest) { test = partest; InitializeComponent(); }