Example #1
0
        private void MainLoop(Client client)
        {
            while (!shutdownEvent.WaitOne(0))
            {
                List <RunnerSubmission> newUnhandled;
                try
                {
                    newUnhandled = client.TryGetSubmissions(jobsToRequest).Result;
                }
                catch (Exception e)
                {
                    log.Error($"Не могу получить решения из ulearn. Следующая попытка через {sleep.TotalSeconds} секунд", e);
                    Thread.Sleep(sleep);
                    continue;
                }

                log.Info($"Получил {newUnhandled.Count} решение(й) со следующими ID: [{string.Join(", ", newUnhandled.Select(s => s.Id))}]");

                if (newUnhandled.Any())
                {
                    var results = newUnhandled.Select(unhandled => SandboxRunner.Run(unhandled, Settings)).ToList();
                    log.Info($"Результаты проверки: [{string.Join(", ", results.Select(r => r.Verdict))}]");
                    try
                    {
                        client.SendResults(results);
                    }
                    catch (Exception e)
                    {
                        log.Error("Не могу отправить результаты проверки на ulearn", e);
                    }
                }
                Thread.Sleep(sleep);
            }
        }
Example #2
0
        private static void SelfCheck()
        {
            var res = SandboxRunner.Run(new RunnerSubmition()
            {
                Id      = Guid.NewGuid().ToString("N"),
                NeedRun = true,
                Code    = "class C { static void Main(){ System.Console.WriteLine(\"Привет мир!\");}}"
            });

            Console.WriteLine(res);
        }
Example #3
0
        private void SelfCheck()
        {
            var res = SandboxRunner.Run(new FileRunnerSubmission
            {
                Id      = Utils.NewNormalizedGuid(),
                NeedRun = true,
                Code    = "class C { static void Main(){ System.Console.WriteLine(\"Привет мир!\");}}"
            }, Settings);

            log.Info(res);
        }
Example #4
0
        private static RunningResults GetDetails(string code, string input)
        {
            var model = new RunnerSubmition
            {
                Id      = Guid.NewGuid().ToString(),
                Code    = code,
                Input   = input,
                NeedRun = true
            };

            var result = new SandboxRunner(model).Run();

            Assert.IsNotNull(result);
            return(result);
        }
Example #5
0
        private static RunningResults GetDetails(string code, string input)
        {
            var model = new FileRunnerSubmission
            {
                Id      = Utils.NewNormalizedGuid(),
                Code    = code,
                Input   = input,
                NeedRun = true
            };

            var result = new SandboxRunner(model).RunCsc(".");

            Assert.IsNotNull(result);
            Console.WriteLine(result);
            return(result);
        }
Example #6
0
        public static RunningResults Run(RunnerSubmission submission, SandboxRunnerSettings settings = null)
        {
            settings = settings ?? new SandboxRunnerSettings();
            var workingDirectory = settings.WorkingDirectory;

            if (!workingDirectory.Exists)
            {
                try
                {
                    workingDirectory.Create();
                }
                catch (Exception e)
                {
                    log.Error($"Не могу создать директорию для компиляции решений: {workingDirectory}", e);
                    return(new RunningResults(submission.Id, Verdict.SandboxError, error: e.ToString()));
                }
            }

            var randomSuffix = Guid.NewGuid().ToString("D");

            randomSuffix = randomSuffix.Substring(randomSuffix.Length - 8);
            var submissionCompilationDirectory = workingDirectory.GetSubdirectory($"{submission.Id}-{randomSuffix}");

            try
            {
                submissionCompilationDirectory.Create();
            }
            catch (Exception e)
            {
                log.Error($"Не могу создать директорию для компиляции решения: {submissionCompilationDirectory.FullName}", e);
                return(new RunningResults(submission.Id, Verdict.SandboxError, error: e.ToString()));
            }

            try
            {
                RunningResults result;
                var            instance = new SandboxRunner(submission, settings);
                if (submission is ProjRunnerSubmission)
                {
                    result = instance.RunMsBuild(submissionCompilationDirectory.FullName);
                }
                else
                {
                    result = instance.RunCsc(submissionCompilationDirectory.FullName);
                }
                result.Id = submission.Id;
                return(result);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                return(new RunningResults(submission.Id, Verdict.SandboxError, error: ex.ToString()));
            }
            finally
            {
                if (settings.DeleteSubmissionsAfterFinish)
                {
                    log.Info($"Удаляю папку с решением: {submissionCompilationDirectory}");
                    SafeRemoveDirectory(submissionCompilationDirectory.FullName);
                }
            }
        }
Example #7
0
		private static RunningResults GetDetails(string code, string input)
		{
			var model = new RunnerSubmition
			{
				Id = Guid.NewGuid().ToString(),
				Code = code,
				Input = input,
				NeedRun = true
			};

			var result = new SandboxRunner(model).Run();
			Assert.IsNotNull(result);
			return result;
		}
Example #8
0
		private static RunningResults GetDetails(string code, string input)
		{
			var model = new FileRunnerSubmission
			{
				Id = Utils.NewNormalizedGuid(),
				Code = code,
				Input = input,
				NeedRun = true
			};

			var result = new SandboxRunner(model).RunCsc60(".");
			Assert.IsNotNull(result);
			Console.WriteLine(result);
			return result;
		}