예제 #1
0
        public RunResultDTO SendSolution(int id, [FromBody] TaskSolutionDTO taskSolution)
        {
            using (programming_tasksEntities entities = new programming_tasksEntities())
            {
                string username = Thread.CurrentPrincipal.Identity.Name; //get username from authentication

                user userResult = entities.users.First(user => user.username == username);
                task taskResult = entities.tasks.Find(id);

                if (taskResult == null)
                {
                    ExceptionHandler.ThrowException(HttpStatusCode.NotFound, "Task with id " + id + " doesn't exist");
                }

                CodeExecutor codeExecutor = new CodeExecutor();

                RunResultDTO runResult = codeExecutor.RunTask(taskSolution, taskResult);

                entities.users_solutions.Add(new users_solutions()
                {
                    user        = userResult,
                    task        = taskResult,
                    code        = taskSolution.Code,
                    status      = runResult.CorrectExamples == taskResult.examples.Count,
                    description = runResult.CorrectExamples == taskResult.examples.Count ?
                                  "Code executed successfully for all examples" :
                                  "Code failed at some example(s)",
                    date = DateTime.Now
                });

                entities.SaveChanges();

                return(runResult);
            }
        }
예제 #2
0
        private void MessageConsumer_RunReceived(object sender, BasicDeliverEventArgs evn)
        {
            _logger.LogInformation("message run received");
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Received Run message");
            var message       = Encoding.UTF8.GetString(evn.Body);
            var projectForRun = JsonConvert.DeserializeObject <ProjectForRunDTO>(message);
            var projectName   = $"project_{projectForRun.ProjectId}";

            Console.WriteLine($"{projectName} = =========  {projectForRun.TimeStamp}");
            Console.ForegroundColor = ConsoleColor.White;

            try
            {
                var runningResult = _worker.Run(projectForRun.UriForProjectDownload, projectName, projectForRun.Inputs);

                var runResult = new RunResultDTO()
                {
                    ProjectId    = projectForRun.ProjectId,
                    Result       = runningResult,
                    ConnectionId = projectForRun.ConnectionId
                };

                var jsonMessage = JsonConvert.SerializeObject(runResult);
                SendRunMessage(jsonMessage);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Run error");
            }

            _messageConsumerScopeRun.MessageConsumer.SetAcknowledge(evn.DeliveryTag, true);
        }
예제 #3
0
            protected RunResultDTO RunTaskExamples(task task)
            {
                ProcessResult processResult = null;
                RunResultDTO  runResult     = new RunResultDTO()
                {
                    TaskTitle = task.title
                };

                foreach (example example in task.examples)
                {
                    string description;

                    processResult = RunProcess("/C " + runCommand, example.input.Split(';'));

                    if (processResult.ExitCode == 0)
                    {
                        if (processResult.Output == example.output)
                        {
                            runResult.CorrectExamples++;
                            description = "Code runs successfully";
                        }
                        else
                        {
                            description = "Code failed";
                        }
                    }
                    else
                    {
                        description = "Error running code";
                    }

                    runResult.exampleResults.Add(new ExampleResultDTO()
                    {
                        Input          = example.input,
                        Output         = example.output,
                        SolutionResult = processResult.Output,
                        Description    = description +
                                         //remove path to the file from error
                                         processResult.Error.Replace(filePath.Replace(Path.GetFileName(filePath), ""), "")
                    });
                }

                return(runResult);
            }