private async Task BackupFromValidationsContainerAsync(ICorePackageFileService fileService, Package package)
 {
     using (var packageStream = await fileService.DownloadValidationPackageFileAsync(package))
     {
         if (packageStream != null)
         {
             await fileService.StorePackageFileInBackupLocationAsync(package, packageStream);
         }
     }
 }
        private async Task MoveFileToPublicStorageAndMarkPackageAsAvailable(PackageValidationSet validationSet, Package package)
        {
            _logger.LogInformation("Copying .nupkg to public storage for package {PackageId} {PackageVersion}, validation set {ValidationSetId}",
                                   package.PackageRegistration.Id,
                                   package.NormalizedVersion,
                                   validationSet.ValidationTrackingId);
            var packageStream = await _packageFileService.DownloadValidationPackageFileAsync(package);

            await _packageFileService.SavePackageFileAsync(package, packageStream);

            try
            {
                _logger.LogInformation("Marking package {PackageId} {PackageVersion}, validation set {ValidationSetId} as {PackageStatus} in DB",
                                       package.PackageRegistration.Id,
                                       package.NormalizedVersion,
                                       validationSet.ValidationTrackingId,
                                       PackageStatus.Available);
                await _galleryPackageService.UpdatePackageStatusAsync(package, PackageStatus.Available, commitChanges : true);

                _messageService.SendPackagePublishedMessage(package);
            }
            catch (Exception e)
            {
                _logger.LogError(
                    Error.UpdatingPackageDbStatusFailed,
                    e,
                    "Failed to update package status in Gallery Db. Package {PackageId} {PackageVersion}, validation set {ValidationSetId}",
                    package.PackageRegistration.Id,
                    package.NormalizedVersion,
                    validationSet.ValidationTrackingId);

                await _packageFileService.DeletePackageFileAsync(package.PackageRegistration.Id, package.Version);

                throw;
            }

            _logger.LogInformation("Deleting from the source for package {PackageId} {PackageVersion}, validation set {ValidationSetId}",
                                   package.PackageRegistration.Id,
                                   package.NormalizedVersion,
                                   validationSet.ValidationTrackingId);
            await _packageFileService.DeleteValidationPackageFileAsync(package.PackageRegistration.Id, package.Version);
        }