Exemplo n.º 1
0
            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());
            }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
            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));
            }
Exemplo n.º 4
0
            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);
            }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }