Example #1
0
            public async Task <ArchiveResult> Handle(Query request, CancellationToken cancellationToken)
            {
                if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded)
                {
                    throw new ForbiddenException();
                }

                var directory = await _db.Directories
                                .SingleOrDefaultAsync(e => e.Id == request.Id, cancellationToken);

                if (directory == null)
                {
                    throw new EntityNotFoundException <Directory>();
                }

                var directories = await _db.GetDirectoryWithChildren(directory.Id, cancellationToken);

                return(await _archiveService.ArchiveDirectory(directory, request.ArchiveType, request.IncludeIds));
            }
Example #2
0
            public async Task <ImportDirectoryResult> Handle(Command request, CancellationToken cancellationToken)
            {
                if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded)
                {
                    throw new ForbiddenException();
                }

                var directory = await _db.Directories
                                .SingleOrDefaultAsync(e => e.Id == request.Id, cancellationToken);

                if (directory == null)
                {
                    throw new EntityNotFoundException <Directory>();
                }

                Domain.Models.Directory extractedDirectory;

                using (var memStream = new System.IO.MemoryStream())
                {
                    await request.Archive.CopyToAsync(memStream, cancellationToken);

                    memStream.Position = 0;
                    extractedDirectory = _archiveService.ExtractDirectory(memStream, request.Archive.FileName);
                }

                var directories = await _db.GetDirectoryWithChildren(directory.Id, cancellationToken);

                var importResult = await _importService.ImportDirectory(directory, extractedDirectory, request.PreserveIds);

                var entries = _db.GetUpdatedEntries();
                await _db.SaveChangesAsync(cancellationToken);

                await this.PublishEvents(entries);

                return(_mapper.Map <ImportDirectoryResult>(importResult));
            }