/// <summary> /// 提交测试 /// </summary> /// <param name="judge">提交测试</param> /// <returns></returns> public bool Judge(judge judge) { if (judge != null) { string token = getToken(); if (token != null) { returnValue value = config.Request.RequestJson <returnValue, judgeQuery>(config.Domain + "ajax?n=api.judge.Open", new judgeQuery { token = token, judge = judge }); return(value != null && value.IsValue); } } return(false); }
/// <summary> /// 删除测试数据 /// </summary> /// <param name="problemId">题目ID</param> /// <param name="testId">测试数据ID</param> /// <returns></returns> public bool DeleteTestData(int problemId, byte testId) { if (problemId != 0 && testId != 0) { string token = getToken(); if (token != null) { returnValue value = config.Request.RequestJson <returnValue, deleteTestDataQuery>(config.Domain + "ajax?n=api.problem.DeleteTestData", new deleteTestDataQuery { token = token, problemId = problemId, testId = testId }); return(value != null && value.IsValue); } } return(false); }
/// <summary> /// 修改题目 /// </summary> /// <param name="problem">题目</param> /// <returns>是否成功</returns> public bool ReworkProblem(problem problem) { if (problem != null && problem.Id != 0) { string token = getToken(); if (token != null) { returnValue value = config.Request.RequestJson <returnValue, problemQuery>(config.Domain + "ajax?n=api.problem.Rework", new problemQuery { token = token, problem = problem }); return(value != null && value.IsValue); } } return(false); }
/// <summary> /// 添加题目 /// </summary> /// <param name="problem">题目</param> /// <returns>题目ID</returns> public int AppendProblem(problem problem) { if (problem != null) { string token = getToken(); if (token != null) { returnValue <int> value = config.Request.RequestJson <returnValue <int>, problemQuery>(config.Domain + "ajax?n=api.problem.Append", new problemQuery { token = token, problem = problem }); if (value != null) { return(value.Value); } } } return(0); }
/// <summary> /// 批量提交测试 /// </summary> /// <param name="judges">提交测试</param> /// <returns>成功提交的测试ID</returns> public int[] BatchJudge(judge[] judges) { if (judges.length() != 0) { string token = getToken(); if (token != null) { returnValue <int[]> value = config.Request.RequestJson <returnValue <int[]>, batchJudgeQuery>(config.Domain + "/ajax?n=api.judge.Batch", new batchJudgeQuery { token = token, judges = judges }); if (value != null) { return(value.Value); } } } return(null); }
/// <summary> /// Zip文件模式修改或者添加测试数据 /// </summary> /// <param name="problemId">题目ID</param> /// <param name="zipFileData">zip文件内容</param> /// <returns>上传后的测试数据数量</returns> public int UploadTestData(int problemId, byte[] zipFileData) { if (problemId != 0 && zipFileData.length() != 0) { string token = getToken(); if (token != null) { returnValue <int> value = config.Request.RequestJson <returnValue <int> >(config.Domain + "upload/ReworkTestData", zipFileData, "file", "zip", new keyValue <byte[], byte[]>[] { new keyValue <byte[], byte[]>(uploadTestDataParameterName, new uploadTestDataQuery { token = token, problemId = problemId }.ToJson().getBytes()) }); if (value != null) { return(value.Value); } } } return(0); }
/// <summary> /// 获取访问令牌 /// </summary> /// <param name="timeout">超时时间</param> /// <returns></returns> internal string GetToken(out long timeout) { if (timeoutTicks == 0) { if (timeoutSeconds <= 0) { timeoutSeconds = 60; } timeoutTicks = (long)timeoutSeconds * date.SecondTicks; getTokenTimeoutSeconds = timeoutSeconds + Math.Min(timeoutSeconds, 10 * 60); if (getTokenTimeoutSeconds < 0) { getTokenTimeoutSeconds = int.MaxValue; } } timeout = (date.UtcNowSecond.Ticks / timeoutTicks) * timeoutTicks + timeoutTicks; returnValue <string> value = Request.RequestJson <returnValue <string>, getParameter>(Domain + "ajax?n=pub.GetToken", new getParameter(email, password, randomPrefix, getTokenTimeoutSeconds)); return(value == null ? null : value.Value); }