public async Task <IsoResult[]> Handle(Query request, CancellationToken cancellationToken) { var vm = await _vmService.GetAsync(request.Id, cancellationToken); if (vm == null) { throw new EntityNotFoundException <VsphereVirtualMachine>(); } var results = new List <IsoResult>(); var viewIds = await _viewService.GetViewIdsForTeams(vm.TeamIds, cancellationToken); var isoTasks = new List <Task <IsoResult> >(); foreach (var viewId in viewIds) { isoTasks.Add(this.GetViewIsos(viewId, cancellationToken)); } await Task.WhenAll(isoTasks); foreach (var isoResult in isoTasks.Select(x => x.Result)) { if (isoResult != null) { results.Add(isoResult); } } return(results.ToArray()); }
public async Task <IActionResult> Get(Guid id, CancellationToken ct) { var vm = await _vmService.GetAsync(id, ct); if (vm == null) { return(NotFound(vm)); } return(Ok(vm)); }
public async Task <VirtualMachineToolsStatus> Handle(Query request, CancellationToken cancellationToken) { var vm = await _vmService.GetAsync(request.Id, cancellationToken); if (vm == null) { throw new EntityNotFoundException <VsphereVirtualMachine>(); } return(await _vsphereService.GetVmToolsStatus(request.Id)); }
public async Task <VsphereVirtualMachine> Handle(Query request, CancellationToken cancellationToken) { var vm = await _vmService.GetAsync(request.Id, cancellationToken); if (vm == null) { throw new EntityNotFoundException <VsphereVirtualMachine>(); } var vsphereVirtualMachine = await base.GetVsphereVirtualMachine(vm, cancellationToken); LogAccess(vm); return(vsphereVirtualMachine); }
protected async Task <Vms.Vm> GetVm(Guid id, IEnumerable <Permissions> blockingPermissions, CancellationToken cancellationToken) { var vm = await _vmService.GetAsync(id, cancellationToken); if (vm == null) { throw new EntityNotFoundException <VsphereVirtualMachine>(); } if (blockingPermissions.Any() && (await _permissionsService.GetPermissions(vm.TeamIds, cancellationToken)).Any(x => blockingPermissions.Contains(x))) { throw new ForbiddenException(); } return(vm); }
public async Task SetActiveVirtualMachine(Guid vmId) { var vm = await _vmService.GetAsync(vmId, Context.ConnectionAborted); var userId = Context.User.GetId(); var viewIds = await _viewService.GetViewIdsForTeams(vm.TeamIds, Context.ConnectionAborted); var teamIds = new List <Guid>(); foreach (var viewId in viewIds) { var primaryTeamId = await _playerService.GetPrimaryTeamByViewIdAsync(viewId, Context.ConnectionAborted); teamIds.Add(primaryTeamId); } var groups = GetGroups(teamIds, viewIds, userId); var newVmId = _activeVirtualMachineService.SetActiveVirtualMachineForUser(userId, vmId, Context.ConnectionId, teamIds); await Clients.Groups(groups).SendAsync(VmHubMethods.ActiveVirtualMachine, newVmId, userId); }