Ejemplo n.º 1
0
        public override async Task <Question> ValidateAsync(Question question)
        {
            var result = await base.ValidateAsync(question);

            if (question.Program == null)
            {
                throw ExceptionHelper.CreatePublicException("Не указана программа.");
            }

            if (string.IsNullOrWhiteSpace(question.Program.Source))
            {
                throw ExceptionHelper.CreatePublicException("Не указан исходный код программы.");
            }

            if (result.Program == null)
            {
                throw ExceptionHelper.CreatePublicException("Не удалось найти программу в вопросе.");
            }

            if (result.Program.Id != question.Program.Id)
            {
                throw ExceptionHelper.CreatePublicException("Указанная программа не принадлежит текущему вопросу.");
            }

            var response = await _codeRunner.RunAsync(question.Program);

            if (response?.CodeExecutionResult == null)
            {
                return(result.SetRight(false));
            }

            return(result
                   .SetCodeRunningResult(response)
                   .SetRight(response.CodeExecutionResult.Success));
        }
Ejemplo n.º 2
0
 public async Task <IActionResult> Run([FromBody] ProgramModel program)
 {
     return(await Ok(() => _codeRunner.RunAsync(program)));
 }