Exemple #1
0
            protected override async Task Handle(Command request, CancellationToken cancellationToken)
            {
                if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded)
                {
                    throw new ForbiddenException();
                }

                var workspace = await _db.Workspaces.FindAsync(request.Id);

                if (workspace == null)
                {
                    throw new EntityNotFoundException <Workspace>();
                }

                using (var lockResult = await _lockService.GetWorkspaceLock(request.Id).LockAsync(0))
                {
                    if (!lockResult.AcquiredLock)
                    {
                        throw new WorkspaceConflictException();
                    }

                    if (workspace.GetState().GetResources().Any())
                    {
                        throw new ConflictException("Cannot delete a Workspace with deployed Resources.");
                    }

                    if (await _db.AnyIncompleteRuns(request.Id))
                    {
                        throw new ConflictException("Cannot delete a Workspace with pending Runs.");
                    }

                    _db.Workspaces.Remove(workspace);
                    await _db.SaveChangesAsync(cancellationToken);
                }
            }
Exemple #2
0
            public async Task <Run> Handle(Command request, CancellationToken cancellationToken)
            {
                if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded)
                {
                    throw new ForbiddenException();
                }

                await ValidateWorkspace(request.WorkspaceId);

                Domain.Models.Run run = null;

                using (var lockResult = await _lockService.GetWorkspaceLock(request.WorkspaceId).LockAsync(0))
                {
                    if (!lockResult.AcquiredLock)
                    {
                        throw new WorkspaceConflictException();
                    }

                    if ((await _db.AnyIncompleteRuns(request.WorkspaceId)))
                    {
                        throw new ConflictException("This Workspace's current Run must be rejected or applied before a new one can be created.");
                    }

                    run = await this.DoWork(request);
                }

                await _mediator.Publish(new RunCreated { RunId = run.Id });

                return(_mapper.Map <Run>(run));
            }
Exemple #3
0
        protected async Task <Workspace> PerformOperation(Workspace workspace, ResourceOperation operation, string[] addresses)
        {
            using (var lockResult = await _lockService.GetWorkspaceLock(workspace.Id).LockAsync(0))
            {
                if (!lockResult.AcquiredLock)
                {
                    throw new WorkspaceConflictException();
                }

                if (!(await _db.AnyIncompleteRuns(workspace.Id)))
                {
                    return(await this.OperationDoWork(workspace, operation, addresses));
                }
                else
                {
                    throw new WorkspaceConflictException();
                }
            }
        }