Exemplo n.º 1
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);
				}
			}

			var randomSuffix = Guid.NewGuid().ToString("D");
			randomSuffix = randomSuffix.Substring(randomSuffix.Length - 8);
			var submissionCompilationDirectory = workingDirectory.GetSubdir($"{submission.Id}-{randomSuffix}");
			try
			{
				submissionCompilationDirectory.Create();
			}
			catch (Exception e)
			{
				log.Error($"Не могу создать директорию для компиляции решения: {submissionCompilationDirectory.FullName}", e);
				return new RunningResults
				{
					Id = submission.Id,
					Verdict = Verdict.SandboxError,
					Error = e.ToString()
				};
			}

			try
			{
				try
				{
					if (submission is ProjRunnerSubmission)
						return new SandboxRunner(submission, settings).RunMsBuild(submissionCompilationDirectory.FullName);
					return new SandboxRunner(submission, settings).RunCsc60(submissionCompilationDirectory.FullName);
				}
				catch (Exception ex)
				{
					log.Error(ex);
					return new RunningResults
					{
						Id = submission.Id,
						Verdict = Verdict.SandboxError,
						Error = ex.ToString()
					};
				}
			}
			finally
			{
				log.Info($"Удаляю папку с решением: {submissionCompilationDirectory}");
				SafeRemoveDirectory(submissionCompilationDirectory.FullName);
			}
		}
Exemplo n.º 2
0
        public RunningResults RunContainerAndGetResultInternal(RunnerSubmission submission, DirectoryInfo submissionWorkingDirectory)
        {
            var commandRunnerSubmission = (CommandRunnerSubmission)submission;
            var settings = GetSpecificSettings(commandRunnerSubmission);
            var result   = DockerProcessRunner.Run((CommandRunnerSubmission)submission, settings, submissionWorkingDirectory.FullName);

            result.Id = submission.Id;
            return(result);
        }
Exemplo n.º 3
0
        public RunningResults RunContainerAndGetResultInternal(RunnerSubmission submission, DirectoryInfo submissionWorkingDirectory)
        {
            var instance = new CsSandboxRunner((CsRunnerSubmission)submission, new CsSandboxRunnerSettings());
            var result   = submission is ProjRunnerSubmission
                                ? instance.RunMsBuild(submissionWorkingDirectory.FullName)
                                : instance.RunCsc(submissionWorkingDirectory.FullName);

            result.Id = submission.Id;
            return(result);
        }
Exemplo n.º 4
0
        public RunningResults RunContainerAndGetResultInternal(RunnerSubmission submission, DirectoryInfo submissionWorkingDirectory)
        {
            var commandRunnerSubmission = (CommandRunnerSubmission)submission;
            var settings = GetSpecificSettings(commandRunnerSubmission);
            var result   = DockerProcessRunner.Run((CommandRunnerSubmission)submission, settings, submissionWorkingDirectory.FullName);

            if (result.Verdict == Verdict.Ok)
            {
                result = ResultParser.Parse(result.Output, result.Error);
            }
            result.Id = submission.Id;
            return(result);
        }
Exemplo n.º 5
0
        public static RunningResults WithSubmissionWorkingDirectory(RunnerSubmission submission, ISandboxRunnerClient runnerClient,
                                                                    DirectoryInfo workingDirectory, bool deleteSubmissionsAfterFinish)
        {
            if (!workingDirectory.Exists)
            {
                try
                {
                    workingDirectory.Create();
                }
                catch (Exception e)
                {
                    log.Error(e, $"Не могу создать директорию для решений: {workingDirectory}");
                    return(new RunningResults(submission.Id, Verdict.SandboxError, error: e.ToString()));
                }
            }

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

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

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

            try
            {
                return(runnerClient.RunContainerAndGetResultInternal(submission, submissionWorkingDirectory));
            }
            catch (Exception ex)
            {
                log.Error(ex, "RunContainerAndGetResultInternal error");
                return(new RunningResults(submission.Id, Verdict.SandboxError, error: ex.ToString()));
            }
            finally
            {
                if (deleteSubmissionsAfterFinish)
                {
                    log.Info($"Удаляю папку с решением: {submissionWorkingDirectory}");
                    SafeRemoveDirectory(submissionWorkingDirectory.FullName);
                }
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 7
0
 public SandboxRunner(RunnerSubmission submission, SandboxRunnerSettings settings = null)
 {
     this.submission = submission;
     this.settings   = settings ?? new SandboxRunnerSettings();
 }
Exemplo n.º 8
0
 public RunningResults Run(RunnerSubmission submission)
 {
     return(SandboxRunHelper.WithSubmissionWorkingDirectory((CsRunnerSubmission)submission, this, SandboxRunnerSettings.WorkingDirectory, SandboxRunnerSettings.DeleteSubmissionsAfterFinish));
 }
Exemplo n.º 9
0
		public SandboxRunner(RunnerSubmission submission, SandboxRunnerSettings settings = null)
		{
			this.submission = submission;
			this.settings = settings ?? new SandboxRunnerSettings();
			result.Id = submission.Id;
		}