示例#1
0
        public async Task PublishReleaseFiles(Guid releaseId)
        {
            var release = await _releaseService.Get(releaseId);

            var files = await _releaseService.GetFiles(
                releaseId,
                Ancillary,
                Chart,
                FileType.Data,
                Image
                );

            var destinationDirectoryPath = $"{release.Id}/";

            // Delete any existing blobs in public storage
            await _publicBlobStorageService.DeleteBlobs(
                containerName : PublicReleaseFiles,
                directoryPath : destinationDirectoryPath);

            // Get a list of source directory paths for all the files.
            // There will be multiple root paths if they were created on different amendment Releases
            var sourceDirectoryPaths = files
                                       .Select(f => $"{f.RootPath}/")
                                       .Distinct()
                                       .ToList();

            // Copy the blobs of those directories in private storage to the destination directory in public storage
            foreach (var sourceDirectoryPath in sourceDirectoryPaths)
            {
                await _privateBlobStorageService.CopyDirectory(
                    sourceContainerName : PrivateReleaseFiles,
                    sourceDirectoryPath : sourceDirectoryPath,
                    destinationContainerName : PublicReleaseFiles,
                    destinationDirectoryPath : destinationDirectoryPath,
                    new IBlobStorageService.CopyDirectoryOptions
                {
                    DestinationConnectionString = _publicStorageConnectionString,
                    SetAttributesCallbackAsync  = (source, destination) =>
                                                  SetPublishedBlobAttributesCallback(destination, release.PublishScheduled !.Value),
                    ShouldTransferCallbackAsync = (source, _) =>
                                                  // Filter by blobs with matching file paths
                                                  TransferBlobIfFileExistsCallback(
                        source: source,
                        files: files,
                        sourceContainerName: PrivateReleaseFiles,
                        logger: _logger)
                });
        public async Task PublishReleaseFilesAsync(Guid releaseId)
        {
            var release = await _releaseService.GetAsync(releaseId);

            var copyReleaseCommand = new CopyReleaseFilesCommand
            {
                ReleaseId        = releaseId,
                PublicationSlug  = release.Publication.Slug,
                PublishScheduled = release.PublishScheduled.Value,
                ReleaseSlug      = release.Slug,
                Files            = await _releaseService.GetFiles(releaseId,
                                                                  Ancillary,
                                                                  Chart,
                                                                  FileType.Data)
            };
            await _fileStorageService.CopyReleaseFilesToPublicContainer(copyReleaseCommand);
        }