public IActionResult Check(DescTraceTableViewModel viewModel) { viewModel.Row = viewModel.Row.Where(x => !string.IsNullOrEmpty(x)).ToList(); var answer = _runner.Run(viewModel.SourceCodeForCheck); answer = answer.Replace("\r\n", " ").Trim(); var userResult = string.Join(" ", viewModel.Row.Skip(viewModel.Variables.Count)).Trim(); var result = TestResults.WA; if (answer == userResult) { result = TestResults.Ok; } Guid.TryParse(User.FindFirstValue(ClaimTypes.NameIdentifier), out var userId); var solution = new Solution { Result = result, UserId = userId, Input = userResult, ProblemId = viewModel.Id, SendTime = DateTime.Now }; _solutionsService.Save(solution); return(RedirectToAction("Description", "Problems", new { viewModel.Id })); }
public IActionResult Check(DescCodeCorrectorViewModel viewModel) { var generator = _generators[viewModel.GeneratorType]; var input = generator.CreateData(); try { var problemId = viewModel.Id; Guid.TryParse(User.FindFirstValue(ClaimTypes.NameIdentifier), out var userId); var outPutRight = _runner.Run(viewModel.SourceCode, input).Trim('\n', '\r'); var result = TestResults.WA; var outPutUser = ""; try { outPutUser = _runner.Run(viewModel.IncorrectSourceCode, input).Trim('\n', '\r'); } catch { result = TestResults.CE; } if (result != TestResults.CE && outPutRight == outPutUser) { result = TestResults.Ok; } var solution = new Solution() { Result = result, UserId = userId, Input = viewModel.IncorrectSourceCode, ProblemId = problemId, SendTime = DateTime.Now }; _solutionsService.Save(solution); return(RedirectToAction("Description", "Problems", new { viewModel.Id })); } catch (Exception e) { return(View("Error", new ErrorViewModel() { RequestId = e.Message })); } }
public IActionResult Check(DescBlackBoxViewModel model) { var problemId = model.Id; Guid.TryParse(User.FindFirstValue(ClaimTypes.NameIdentifier), out var userId); var result = TestResults.WA; var userCode = model.Answer; var correctCode = model.SourceCode; var input = _generators[model.GeneratorType].CreateData(); var outPutRight = _runner.Run(correctCode, input).Trim('\n', '\r'); var outPutUser = ""; try { outPutUser = _runner.Run(userCode, input).Trim('\n', '\r'); } catch { result = TestResults.CE; } if (result != TestResults.CE && outPutRight == outPutUser) { result = TestResults.Ok; } var solution = new Solution { Result = result, UserId = userId, Input = userCode, ProblemId = problemId, SendTime = DateTime.Now }; _solutionsService.Save(solution); return(RedirectToAction("Description", "Problems", new { model.Id })); }
public IActionResult Check(DescRestoreDataViewModel viewModel) { try { var problemId = viewModel.Id; Guid.TryParse(User.FindFirstValue(ClaimTypes.NameIdentifier), out var userId); var result = TestResults.WA; var input = viewModel.InputData; var outPutRight = _runner.Run(viewModel.SourceCode, input).Trim('\n', '\r'); var outPutUser = viewModel.OutputData; if (outPutRight == outPutUser) { result = TestResults.Ok; } var solution = new Solution { Result = result, UserId = userId, Input = input, ProblemId = problemId, SendTime = DateTime.Now }; _solutionsService.Save(solution); return(RedirectToAction("Description", "Problems", new { viewModel.Id })); } catch (Exception e) { return(View("Error", new ErrorViewModel() { RequestId = e.Message })); } }