Beispiel #1
0
        public virtual async Task <SolutionDto> UseAsync(SolutionDto input)
        {
            Check.NotNullOrWhiteSpace(input.DisplayName, nameof(input.DisplayName));
            Check.NotNullOrWhiteSpace(input.DirectoryPath, nameof(input.DirectoryPath));

            var list = await _manager.GetListAsync();

            var solution = FindSolution(list, input);

            if (solution == null)
            {
                list.AddFirst(input);
            }
            else
            {
                list.MoveItem((x) => x == solution, 0);
            }

            if (list.Count > RecentlySolutionsMaxCount)
            {
                list = list.GetRange(0, RecentlySolutionsMaxCount);
            }

            await _manager.UpdateListAsync(list);

            return(input);
        }
        public async Task <IActionResult> GetSolution(string roomCode, string username)
        {
            var quizRoom = await _context.QuizRooms.Select(q => new { q.RoomCode, q.StartedAtUtc, q.StoppedAtUtc, q.Id }).SingleAsync(q => q.RoomCode == roomCode);

            if (!quizRoom.StartedAtUtc.HasValue || !quizRoom.StoppedAtUtc.HasValue)
            {
                return(BadRequest());
            }

            var solutions   = new List <SolutionDto>();
            var participant = await _context.Participants.Include(p => p.Responses).ThenInclude(r => r.Answer).Select(p => new { p.Name, p.QuizRoomId, p.Responses }).SingleAsync(p => p.Name.ToLower() == username.ToLower() && p.QuizRoomId == quizRoom.Id);

            var questions = await _context.Questions.Include(q => q.CorrectAnswer).Select(q => new { q.QuestionText, q.Id, q.QuizRoomId, q.CorrectAnswer }).OrderBy(q => q.Id).Where(q => q.QuizRoomId == quizRoom.Id).ToListAsync();

            foreach (var item in questions)
            {
                var response = participant.Responses.Where(a => a.QuestionId == item.Id).OrderBy(a => a.CreatedOnUtc).FirstOrDefault(a => a.QuestionId == item.Id);

                var solution = new SolutionDto()
                {
                    QuestionText       = item.QuestionText,
                    CorrectAnswerText  = item.CorrectAnswer?.AnswerText,
                    SelectedAnswerText = response != null ? response.Answer?.AnswerText : string.Empty,
                    Score = response.Score
                };

                solutions.Add(solution);
            }

            return(Ok(solutions));
        }
Beispiel #3
0
        public virtual async Task <SolutionDto> UseAsync(SolutionDto input)
        {
            Check.NotNullOrWhiteSpace(input.DisplayName, nameof(input.DisplayName));
            Check.NotNullOrWhiteSpace(input.DirectoryPath, nameof(input.DirectoryPath));

            var list = await _manager.GetListAsync();

            var solution = FindSolution(list, input);

            if (solution == null)
            {
                solution = input;

                list.AddFirst(solution);
            }
            else
            {
                list.MoveItem((x) => x == solution, 0);
            }

            if (!await IsSolutionDirectoryValidAsync(solution))
            {
                list.RemoveAt(0);

                await UpdateRecentlySolutionListAsync(list);

                throw new BusinessException("Gui:InvalidSolutionDirectoryPath");
            }

            await UpdateRecentlySolutionListAsync(list);

            return(input);
        }
Beispiel #4
0
        public virtual async Task DeleteAsync(SolutionDto input)
        {
            var list = await _manager.GetListAsync();

            FindSolution(list, input);

            await _manager.UpdateListAsync(list);
        }
Beispiel #5
0
        public virtual async Task DeleteAsync(SolutionDto input)
        {
            var list = await _manager.GetListAsync();

            list.Remove(FindSolution(list, input));

            await UpdateRecentlySolutionListAsync(list);
        }
        public virtual async Task SetAsync(SolutionDto solutionDto)
        {
            Value = solutionDto;

            if (OnChangeAsync != null)
            {
                await NotifyStateChanged();
            }
        }
Beispiel #7
0
        public virtual async Task <Dictionary <string, List <string> > > GetAsync(SolutionDto solutionDto)
        {
            var output = await _solutionAppService.GetPackageDictionaryAsync(new GetPackageDictionaryInput
            {
                DirectoryPath = solutionDto.DirectoryPath
            });

            var str = $"{output.SolutionName}.";

            return(new Dictionary <string, List <string> >(output.Items.Where(x => x.Key.StartsWith(str)).Select(x =>
                                                                                                                 new KeyValuePair <string, List <string> >(x.Key.Substring(str.Length),
                                                                                                                                                           x.Value.Select(y => y.Name).ToList()))));
        }
        public async Task <IActionResult> Submit(string problemName, [FromForm] IFormFile problemSolution)
        {
            var problem =
                await _unitOfWork.ProblemRepository
                .GetProblemByTypeAndNameAsync(AppTypeName, problemName);

            if (problem is null)
            {
                return(NotFound());
            }

            var solutionTempGuid = Guid.NewGuid();

            var solutionDirectory = Directory.CreateDirectory(Path.Combine(TempDirectory, solutionTempGuid.ToString()));

            var sourcePaths = (
                Student : solutionDirectory.CreateSubdirectory("_src_actual_"),
                Lecturer : solutionDirectory.CreateSubdirectory("_src__tests_and_expected_")
                );

            await using (var stream = new MemoryStream(problem.Source))
                using (var archive = new ZipArchive(stream))
                    archive.ExtractToDirectory(sourcePaths.Lecturer.FullName);

            await using (var stream = problemSolution.OpenReadStream())
                using (var archive = new ZipArchive(stream))
                    archive.ExtractToDirectory(sourcePaths.Student.FullName);

            var config = _deserializer
                         .Deserialize <AppConfig>(problem.Config);

            var outputs = await Task.WhenAll(
                _unitOfWork.ResultRepository.GetResultsOutputByProblemIdAndUserIdAsync(problem.Id, problem.AuthorId),
                _app.TestAsync(solutionDirectory, sourcePaths.Student, sourcePaths.Lecturer.GetDirectories("tests").First(), config.StartupClass, config.Input, true)
                );

            //TODO: add solution to database, and send real guid

            var solution     = new SolutionDto(outputs[0], outputs[1], solutionTempGuid.ToString().ToUpper());
            var jsonSolution = JsonSerializer.ToJsonString(solution);

            return(Content(jsonSolution, MediaTypeNames.Application.Json, Encoding.UTF8));
        }
Beispiel #9
0
 /// <summary>
 /// 转换为解决方案实体
 /// </summary>
 /// <param name="dto">解决方案数据传输对象</param>
 public static Solution ToEntity2(this SolutionDto dto)
 {
     if (dto == null)
     {
         return(new Solution());
     }
     return(new Solution(dto.Id.ToGuid())
     {
         UserId = dto.UserId,
         Code = dto.Code,
         Name = dto.Name,
         Description = dto.Description,
         Enabled = dto.Enabled.SafeValue(),
         Note = dto.Note,
         SortId = dto.SortId,
         PinYin = dto.PinYin,
         CreationTime = dto.CreationTime,
         CreatorId = dto.CreatorId,
         LastModificationTime = dto.LastModificationTime,
         LastModifierId = dto.LastModifierId,
         IsDeleted = dto.IsDeleted.SafeValue(),
         Version = dto.Version,
     });
 }
 public virtual Task DeleteAsync(SolutionDto input)
 {
     return(_service.DeleteAsync(input));
 }
 public virtual Task <SolutionDto> UseAsync(SolutionDto input)
 {
     return(_service.UseAsync(input));
 }
Beispiel #12
0
 protected virtual string GetDeleteConfirmationMessage(SolutionDto solution)
 {
     return(UiLocalizer["ItemWillBeDeletedMessage"]);
 }
Beispiel #13
0
 protected virtual SolutionDto FindSolution(IEnumerable <SolutionDto> solutions, SolutionDto target)
 {
     return(solutions.FirstOrDefault(x =>
                                     x.DisplayName == target.DisplayName &&
                                     x.SolutionType == target.SolutionType &&
                                     x.DirectoryPath == target.DirectoryPath));
 }
Beispiel #14
0
 protected virtual Task <bool> IsSolutionDirectoryValidAsync(SolutionDto solution)
 {
     return(Task.FromResult(Directory.Exists(solution.DirectoryPath)));
 }