public async Task <string> Handle(RemoveFunctionParticipationSessionCommand request, CancellationToken cancellationToken) { var participation = await _repository.FindByIdAsync(new ParticipationId(request.ParticipationId)); if (participation is null) { throw new NotFoundException(request.ParticipationId.ToString(), "ParticipationSession"); } participation.RemoveFunction(new FunctionId(request.FunctionId), _userService.UserId); return((await _repository.SetAsync(participation)).ToString()); }
public async Task <string> Handle(RunParticipationCommand request, CancellationToken cancellationToken) { var participation = await _participationsSessionsRepository.FindByIdAsync(new ParticipationId(request.ParticipationId)); if (participation is null) { throw new NotFoundException(request.ParticipationId.ToString(), "ParticipationSession"); } participation.ValidateProcessStart(_currentUserService.UserId); var step = await _readStepRepository.GetOneStepNavigationById(participation.StepEntity.Id.Value); if (step is null) { throw new NotFoundException(participation.StepEntity.Id.Value.ToString(), "ParticipationSessionStep"); } var language = await _readProgrammingLanguageRepository.GetOneLanguageNavigationByIdAsync(step.LanguageId); if (language is null) { throw new NotFoundException(step.LanguageId.ToString(), "ParticipationSessionStepLanguage"); } var tests = await _readTestRepository.GetAllTestNavigationByStepId(participation.StepEntity.Id.Value); var runTestDto = new RunParticipationTestsDto( participation.Id.Value, language.Name, step.HeaderCode, tests.Select(t => new RunParticipationTestsDto.Test(t.Id, t.Name, t.OutputValidator, t.InputGenerator)) .ToList(), participation.Functions .Where(f => f.Order is not null) .Select(f => new RunParticipationTestsDto.Function(f.Id.Value, f.Code, f.Order !.Value)) .ToList() ); participation.StartProcess(_timeService.Now()); _participationExecutionService.Dispatch(runTestDto); await _participationsSessionsRepository.SetAsync(participation); return(await Task.FromResult(request.ParticipationId.ToString())); }
public async Task <int> Handle(ConnectUserToParticipation request, CancellationToken cancellationToken) { var participation = await _participationsSessionsRepository.FindByIdAsync(new ParticipationId(request.ParticipationId)); if (participation is null) { throw new NotFoundException(request.ParticipationId.ToString(), "Participation"); } var isFreshParticipation = !participation.HasConnectedUsers; var connectionCount = participation.AddConnectedUser(_currentUserService.UserId); await _participationsSessionsRepository.SetAsync(participation); if (isFreshParticipation) { await PrepareParticipation(participation); } return(connectionCount); }
public async Task <string> Handle(UpdateParticipationSessionFunctionCommand request, CancellationToken cancellationToken) { var participation = await _repository.FindByIdAsync(new ParticipationId(request.ParticipationId)); if (participation is null) { throw new NotFoundException(request.ParticipationId.ToString(), "ParticipationSession"); } var function = new FunctionEntity( new FunctionId(request.FunctionId), _userService.UserId, request.Code, _timeService.Now(), request.Order ); participation.UpdateFunction(function, _userService.UserId); await _repository.SetAsync(participation); return(function.Id.ToString()); }
public async Task <int> Handle(DisconnectUserFromParticipationCommand request, CancellationToken cancellationToken) { var participation = await _participationsSessionsRepository.FindByIdAsync(new ParticipationId(request.ParticipationId)); if (participation is null) { throw new NotFoundException(request.ParticipationId.ToString(), "Participation"); } var connectionCount = participation.RemoveConnectedUser(_currentUserService.UserId); if (participation.HasConnectedUsers) { await _participationsSessionsRepository.SetAsync(participation); } else { await _participationsSessionsRepository.RemoveAsync(participation.Id); await CleanParticipation(participation); } return(connectionCount); }