Exemplo n.º 1
0
        public RunCsJobProgram(ManualResetEvent externalShutdownEvent = null)
        {
            if (externalShutdownEvent != null)
            {
                shutdownEvent = externalShutdownEvent;
            }

            try
            {
                address       = ConfigurationManager.AppSettings["submissionsUrl"];
                token         = ConfigurationManager.AppSettings["runnerToken"];
                sleep         = TimeSpan.FromSeconds(int.Parse(ConfigurationManager.AppSettings["sleepSeconds"] ?? "1"));
                jobsToRequest = int.Parse(ConfigurationManager.AppSettings["jobsToRequest"] ?? "5");
                var deleteSubmissions = bool.Parse(ConfigurationManager.AppSettings["ulearn.runcsjob.deleteSubmissions"] ?? "true");
                Settings = new SandboxRunnerSettings
                {
                    DeleteSubmissionsAfterFinish = deleteSubmissions,
                };
                var workingDirectory = ConfigurationManager.AppSettings["ulearn.runcsjob.submissionsWorkingDirectory"];
                if (!string.IsNullOrWhiteSpace(workingDirectory))
                {
                    Settings.WorkingDirectory = new DirectoryInfo(workingDirectory);
                }
            }
            catch (Exception e)
            {
                log.Error(e);
                throw;
            }
        }
Exemplo n.º 2
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.º 3
0
		public RunCsJobProgram(ManualResetEvent externalShutdownEvent=null)
		{
			if (externalShutdownEvent != null)
				shutdownEvent = externalShutdownEvent;

			try
			{
				address = ConfigurationManager.AppSettings["submissionsUrl"];
				token = ConfigurationManager.AppSettings["runnerToken"];
				sleep = TimeSpan.FromSeconds(int.Parse(ConfigurationManager.AppSettings["sleepSeconds"] ?? "1"));
				jobsToRequest = int.Parse(ConfigurationManager.AppSettings["jobsToRequest"] ?? "5");
				Settings = new SandboxRunnerSettings();
				var workingDirectory = ConfigurationManager.AppSettings["ulearn.runcsjob.submissionsWorkingDirectory"];
				if (!string.IsNullOrWhiteSpace(workingDirectory))
					Settings.WorkingDirectory = new DirectoryInfo(workingDirectory);
			}
			catch (Exception e)
			{
				log.Error(e);
				throw;
			}
		}
Exemplo n.º 4
0
        public RunCsJobProgram(ManualResetEvent externalShutdownEvent = null)
        {
            if (externalShutdownEvent != null)
            {
                shutdownEvent = externalShutdownEvent;
            }

            try
            {
                address       = ConfigurationManager.AppSettings["submissionsUrl"];
                token         = ConfigurationManager.AppSettings["runnerToken"];
                sleep         = TimeSpan.FromSeconds(int.Parse(ConfigurationManager.AppSettings["sleepSeconds"] ?? "1"));
                jobsToRequest = int.Parse(ConfigurationManager.AppSettings["jobsToRequest"] ?? "5");
                var deleteSubmissions = bool.Parse(ConfigurationManager.AppSettings["ulearn.runcsjob.deleteSubmissions"] ?? "true");
                Settings = new SandboxRunnerSettings
                {
                    DeleteSubmissionsAfterFinish = deleteSubmissions,
                };
                var workingDirectory = ConfigurationManager.AppSettings["ulearn.runcsjob.submissionsWorkingDirectory"];
                if (!string.IsNullOrWhiteSpace(workingDirectory))
                {
                    Settings.WorkingDirectory = new DirectoryInfo(workingDirectory);
                }

                agentName = ConfigurationManager.AppSettings["ulearn.runcsjob.agentName"];
                if (string.IsNullOrEmpty(agentName))
                {
                    agentName = Environment.MachineName;
                    log.Info($"Автоопределённое имя клиента: {agentName}. Его можно переопределить в настройках (appSettings/ulearn.runcsjob.agentName)");
                }
            }
            catch (Exception e)
            {
                log.Error(e);
                throw;
            }
        }
Exemplo n.º 5
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.º 6
0
 public SandboxRunner(RunnerSubmission submission, SandboxRunnerSettings settings = null)
 {
     this.submission = submission;
     this.settings   = settings ?? new SandboxRunnerSettings();
 }
Exemplo n.º 7
0
		public CourseValidator(Slide[] slides, SandboxRunnerSettings settings)
		{
			this.slides = slides;
			this.settings = settings;
		}
Exemplo n.º 8
0
		public SandboxRunner(RunnerSubmission submission, SandboxRunnerSettings settings = null)
		{
			this.submission = submission;
			this.settings = settings ?? new SandboxRunnerSettings();
			result.Id = submission.Id;
		}