private async Task CreateDispatchTaskResultsAsync(DispatchTaskEntity dispatchTaskToExecute, CancellationToken ct) { var dispatchTaskResultEntities = new List <DispatchTaskResultEntity>(); var sessionEntity = dispatchTaskToExecute.SessionId == null ? null : _context.Sessions.First(s => s.Id == dispatchTaskToExecute.SessionId); if (sessionEntity != null && sessionEntity.ExerciseId != null) { // if this task has a Session associated to an Exercise, create a VmList from the VmMask var exerciseVms = await _playerVmService.GetExerciseVmsAsync((Guid)sessionEntity.ExerciseId, ct); foreach (var vm in exerciseVms) { if (vm.Name.ToLower().Contains(dispatchTaskToExecute.VmMask.ToLower())) { var dispatchTaskResultEntity = NewDispatchTaskResultEntity(dispatchTaskToExecute); dispatchTaskResultEntity.VmId = vm.Id; dispatchTaskResultEntity.VmName = vm.Name; dispatchTaskResultEntities.Add(dispatchTaskResultEntity); } } } else if (dispatchTaskToExecute.VmMask.Count() > 0) { var vmIdList = dispatchTaskToExecute.VmMask.Split(",").ToList().ConvertAll(Guid.Parse); // if this task has no Session check the VmMask for a list of VM ID's foreach (var id in vmIdList) { var dispatchTaskResultEntity = NewDispatchTaskResultEntity(dispatchTaskToExecute); dispatchTaskResultEntity.VmId = id; dispatchTaskResultEntities.Add(dispatchTaskResultEntity); } } else { // this task has no VM's associated. Create one result entity var dispatchTaskResultEntity = NewDispatchTaskResultEntity(dispatchTaskToExecute); dispatchTaskResultEntities.Add(dispatchTaskResultEntity); } await _context.DispatchTaskResults.AddRangeAsync(dispatchTaskResultEntities); await _context.SaveChangesAsync(ct); return; }
public async Task <IActionResult> GetExerciseVms(Guid exerciseId, CancellationToken ct) { var list = await _playerVmService.GetExerciseVmsAsync(exerciseId, ct); return(Ok(list)); }