public IExecutionResult <TResult> RunSubmission <TInput, TResult>(OjsSubmission <TInput> submission)
            where TResult : class, ISingleCodeRunResult, new()
        {
            var testInputSubmission   = submission as OjsSubmission <TestsInputModel>;
            var submissionRequestBody = this.BuildRequestBody(testInputSubmission);

            var result = this.http.PostJson <object, RemoteSubmissionResult>(this.endpoint, submissionRequestBody);

            if (result.Exception != null)
            {
                throw new Exception(result.Exception.Message);
            }

            var executionResult = new ExecutionResult <TResult>
            {
                CompilerComment        = result.ExecutionResult.CompilerComment,
                IsCompiledSuccessfully = result.ExecutionResult.IsCompiledSuccessfully,
                Results = result.ExecutionResult.TaskResult.TestResults
                          .Select(testResult =>
                {
                    var test = testInputSubmission.Input.Tests.FirstOrDefault(t => t.Id == testResult.Id);
                    return(this.BuildTestResult <TResult>(test, testResult));
                })
                          .ToList(),
            };

            return(executionResult);
        }
Esempio n. 2
0
        private void ProcessSubmission <TInput, TResult>(OjsSubmission <TInput> submission)
            where TResult : ISingleCodeRunResult, new()
        {
            this.logger.Information("{SubmissionProcessor}: Work on submission {Submission} started.", this.Name, submission.Id);

            this.hubService.NotifyServer(new SrServerNotification()
            {
                Type         = SrServerNotificationType.StartedProcessing,
                SubmissionId = (int)submission.Id
            });

            this.BeforeExecute(submission);

            var executor = new SubmissionExecutor(this.portNumber);

            var executionResult = executor.Execute <TInput, TResult>(submission);

            this.logger.Information("{SubmissionProcessor}: Work on submission {Submission} ended.", this.Name, submission.Id);

            this.hubService.NotifyServer(new SrServerNotification()
            {
                Type         = SrServerNotificationType.FinishedProcessing,
                SubmissionId = (int)submission.Id
            });

            this.ProcessExecutionResult(executionResult, submission);

            this.logger.Information("{SubmissionProcessor}: Submission {Submission} was processed successfully.", this.Name, submission.Id);
        }
        public IExecutionResult <TResult> RunSubmission <TInput, TResult>(OjsSubmission <TInput> submission)
            where TResult : class, ISingleCodeRunResult, new()
        {
            this.logger.Info($"Preparing submission #{submission.Id} for remote worker {this.Location}");

            var testInputSubmission   = submission as OjsSubmission <TestsInputModel>;
            var submissionRequestBody = this.BuildRequestBody(testInputSubmission);

            this.logger.Info($"Request body for submission {submission.Id} is ready.");

            var result = this.ExecuteSubmissionRemotely(testInputSubmission, submissionRequestBody);

            var executionResult = new ExecutionResult <TResult>();

            if (result == null)
            {
                this.logger.Error($"RSP {this.Location} returned null result for submission {submission.Id}.");
                return(executionResult);
            }

            if (result.Exception != null)
            {
                this.logger.Error(
                    $"RSP {this.Location} returned {nameof(result.Exception)} for #{submission.Id} with message: " +
                    $"{result.Exception.Message} and stack trace: {result.Exception.StackTrace}");
                executionResult.CompilerComment = result.Exception.Message;
                return(executionResult);
            }

            if (result.ExecutionResult == null)
            {
                this.logger.Error(
                    $"RSP {this.Location} returned null {nameof(result.ExecutionResult)} for #{submission.Id}.");
                return(executionResult);
            }

            this.logger.Info(
                $"RSP {this.Location} successfully returned {nameof(result.ExecutionResult)} for #{submission.Id}.");

            executionResult = new ExecutionResult <TResult>
            {
                CompilerComment        = result.ExecutionResult.CompilerComment,
                IsCompiledSuccessfully = result.ExecutionResult.IsCompiledSuccessfully,
                Results = result.ExecutionResult.TaskResult.TestResults
                          .Select(testResult =>
                {
                    var test = testInputSubmission.Input.Tests.FirstOrDefault(t => t.Id == testResult.Id);
                    return(this.BuildTestResult <TResult>(test, testResult));
                })
                          .ToList(),
            };

            return(executionResult);
        }
        private void ProcessSubmission <TInput, TResult>(OjsSubmission <TInput> submission)
            where TResult : class, ISingleCodeRunResult, new()
        {
            this.Logger.Info($"{this.Name}({this.SubmissionWorker.Location}): Work on submission #{submission.Id} started.");

            this.BeforeExecute(submission);

            var executionResult = this.HandleProcessSubmission <TInput, TResult>(submission);

            this.Logger.Info($"{this.Name}({this.SubmissionWorker.Location}): Work on submission #{submission.Id} ended.");

            this.ProcessExecutionResult(executionResult, submission);

            this.Logger.Info($"{this.Name}({this.SubmissionWorker.Location}): Submission #{submission.Id} successfully processed.");
        }
        private void ProcessSubmission <TInput, TResult>(OjsSubmission <TInput> submission)
            where TResult : ISingleCodeRunResult, new()
        {
            this.logger.Info($"Work on submission #{submission.Id} started.");

            this.BeforeExecute(submission);

            var executor = new SubmissionExecutor(this.portNumber);

            var executionResult = executor.Execute <TInput, TResult>(submission);

            this.logger.Info($"Work on submission #{submission.Id} ended.");

            this.ProcessExecutionResult(executionResult, submission);

            this.logger.Info($"Submission #{submission.Id} successfully processed.");
        }
Esempio n. 6
0
        public static IExecutionContext <TInput> CreateExecutionContext <TInput>(
            OjsSubmission <TInput> submission)
        {
            if (submission == null)
            {
                throw new ArgumentNullException(nameof(submission));
            }

            return(new ExecutionContext <TInput>
            {
                AdditionalCompilerArguments = submission.AdditionalCompilerArguments,
                Code = submission.Code,
                FileContent = submission.FileContent,
                AllowedFileExtensions = submission.AllowedFileExtensions,
                CompilerType = submission.CompilerType,
                MemoryLimit = submission.MemoryLimit,
                TimeLimit = submission.TimeLimit,
                Input = submission.Input
            });
        }
        private object BuildRequestBody(OjsSubmission <TestsInputModel> submission)
        {
            try
            {
                return(new
                {
                    ExecutionType = this.formatterServicesFactory.Get <ExecutionType>()
                                    .Format(submission.ExecutionType),
                    ExecutionStrategy = this.formatterServicesFactory.Get <ExecutionStrategyType>()
                                        .Format(submission.ExecutionStrategyType),
                    FileContent = string.IsNullOrEmpty(submission.Code)
                        ? submission.FileContent
                        : null,
                    Code = submission.Code ?? string.Empty,
                    submission.TimeLimit,
                    submission.MemoryLimit,
                    ExecutionDetails = new
                    {
                        submission.MaxPoints,
                        CheckerType = this.formatterServicesFactory.Get <string>()
                                      .Format(submission.Input.CheckerTypeName),
                        submission.Input.CheckerParameter,
                        submission.Input.Tests,
                        submission.Input.TaskSkeleton,
                        submission.Input.TaskSkeletonAsString,
                    },
                    ExecutionOptions = new
                    {
                        KeepDetails = true,
                        EscapeTests = false,
                        EscapeLineEndings = true,
                    },
                });
            }
            catch (Exception ex)
            {
                submission.ProcessingComment = $"Exception in building request body: {ex.Message}";

                throw new Exception($"Exception in {nameof(this.BuildRequestBody)}", ex);
            }
        }
 private object BuildRequestBody(OjsSubmission <TestsInputModel> submission)
 => new
 {
     ExecutionType = this.formatterServicesFactory.Get <ExecutionType>()
                     .Format(submission.ExecutionType),
     ExecutionStrategy = this.formatterServicesFactory.Get <ExecutionStrategyType>()
                         .Format(submission.ExecutionStrategyType),
     FileContent = string.IsNullOrEmpty(submission.Code)
             ? submission.FileContent
             : null,
     Code = submission.Code ?? string.Empty,
     submission.TimeLimit,
     submission.MemoryLimit,
     ExecutionDetails = new
     {
         MaxPoints   = submission.MaxPoints,
         CheckerType = this.formatterServicesFactory.Get <string>()
                       .Format(submission.Input.CheckerTypeName),
         submission.Input.CheckerParameter,
         submission.Input.Tests,
         submission.Input.TaskSkeleton,
         submission.Input.TaskSkeletonAsString,
     },
 };
 protected IExecutionResult <TResult> HandleProcessSubmission <TInput, TResult>(
     OjsSubmission <TInput> submission)
     where TResult : class, ISingleCodeRunResult, new()
 => this.SubmissionWorker.RunSubmission <TInput, TResult>(submission);