public static void AddProblem(InputProblemInfo info) { var dir = problem_path + info.SimpleInfo.Title; try { Directory.CreateDirectory(dir); using (FileStream fs = new FileStream(dir + content_path, FileMode.OpenOrCreate, FileAccess.Write)) { info.Content.CopyTo(fs); } using (FileStream fs = new FileStream(dir + test_case_path, FileMode.OpenOrCreate, FileAccess.Write)) { info.TestCase.CopyTo(fs); } using (FileStream fs = new FileStream(dir + right_result_path, FileMode.OpenOrCreate, FileAccess.Write)) { info.RightResult.CopyTo(fs); } ProblemDao.AddProblem(info.SimpleInfo); } catch (Exception) { Directory.Delete(dir, true); throw new MySytemException(); } }
public Result AddProblem() { if (HttpContext.Session.GetInt32("UserId") == null) { throw new UserException(UserException.Type.NotSiginIn); } var data = HttpContext.Request.Form; InputProblemInfo inputProblemInfo = new InputProblemInfo(); inputProblemInfo.Content = data.Files.GetFile("content"); inputProblemInfo.RightResult = data.Files.GetFile("right_result"); inputProblemInfo.TestCase = data.Files.GetFile("test_case"); foreach (var item in data.Files) { if (item.ContentType != "text/plain") { throw new UserException(UserException.Type.InputError); } } try { inputProblemInfo.SimpleInfo = new Problem { MaxMemory = int.Parse(data["max_memory"].ToString()), MaxTime = int.Parse(data["max_time"].ToString()), Title = data["title"].ToString() }; } catch (Exception) { throw new UserException(UserException.Type.InputError); } if (ProblemServices.CheckTitle(inputProblemInfo.SimpleInfo.Title)) { throw new UserException(UserException.Type.ProblemExists); } ProblemServices.AddProblem(inputProblemInfo); return(new Result()); }