Example #1
0
		public async Task<UserExerciseSubmission> AddUserExerciseSubmission(
			string courseId, Guid slideId,
			string code, string compilationError, string output,
			string userId, string executionServiceName, string displayName,
			Language language,
			AutomaticExerciseCheckingStatus status = AutomaticExerciseCheckingStatus.Waiting)
		{
			if (string.IsNullOrWhiteSpace(code))
				code = "// no code";
			var hash = (await textsRepo.AddText(code)).Hash;
			var compilationErrorHash = (await textsRepo.AddText(compilationError)).Hash;
			var outputHash = (await textsRepo.AddText(output)).Hash;
			var exerciseBlock = (courseManager.FindCourse(courseId)?.FindSlideById(slideId) as ExerciseSlide)?.Exercise;

			AutomaticExerciseChecking automaticChecking;
			if (language.HasAutomaticChecking() && (language == Language.CSharp || exerciseBlock is UniversalExerciseBlock))
			{
				automaticChecking = new AutomaticExerciseChecking
				{
					CourseId = courseId,
					SlideId = slideId,
					UserId = userId,
					Timestamp = DateTime.Now,
					CompilationErrorHash = compilationErrorHash,
					IsCompilationError = !string.IsNullOrWhiteSpace(compilationError),
					OutputHash = outputHash,
					ExecutionServiceName = executionServiceName,
					DisplayName = displayName,
					Status = status,
					IsRightAnswer = false,
				};

				db.AutomaticExerciseCheckings.Add(automaticChecking);
			}
			else
			{
				automaticChecking = null;
			}

			var submission = new UserExerciseSubmission
			{
				CourseId = courseId,
				SlideId = slideId,
				UserId = userId,
				Timestamp = DateTime.Now,
				SolutionCodeHash = hash,
				CodeHash = code.Split('\n').Select(x => x.Trim()).Aggregate("", (x, y) => x + y).GetHashCode(),
				Likes = new List<Like>(),
				AutomaticChecking = automaticChecking,
				AutomaticCheckingIsRightAnswer = automaticChecking?.IsRightAnswer ?? true,
				Language = language,
			};

			db.UserExerciseSubmissions.Add(submission);

			await db.SaveChangesAsync();

			return submission;
		}
Example #2
0
        public async Task <UserExerciseSubmission> AddUserExerciseSubmission(
            string courseId, Guid slideId,
            string code, string compilationError, string output,
            string userId, string executionServiceName, string displayName,
            AutomaticExerciseCheckingStatus status = AutomaticExerciseCheckingStatus.Waiting)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                code = "// no code";
            }
            var hash = (await textsRepo.AddText(code)).Hash;
            var compilationErrorHash = (await textsRepo.AddText(compilationError)).Hash;
            var outputHash           = (await textsRepo.AddText(output)).Hash;

            var automaticChecking = new AutomaticExerciseChecking
            {
                CourseId             = courseId,
                SlideId              = slideId,
                UserId               = userId,
                Timestamp            = DateTime.Now,
                CompilationErrorHash = compilationErrorHash,
                IsCompilationError   = !string.IsNullOrWhiteSpace(compilationError),
                OutputHash           = outputHash,
                ExecutionServiceName = executionServiceName,
                DisplayName          = displayName,
                Status               = status,
                IsRightAnswer        = false,
            };

            db.AutomaticExerciseCheckings.Add(automaticChecking);

            var submission = new UserExerciseSubmission
            {
                CourseId          = courseId,
                SlideId           = slideId,
                UserId            = userId,
                Timestamp         = DateTime.Now,
                SolutionCodeHash  = hash,
                CodeHash          = code.Split('\n').Select(x => x.Trim()).Aggregate("", (x, y) => x + y).GetHashCode(),
                Likes             = new List <Like>(),
                AutomaticChecking = automaticChecking,
                AutomaticCheckingIsRightAnswer = false,
            };

            db.UserExerciseSubmissions.Add(submission);

            await db.SaveChangesAsync();

            return(submission);
        }