public void ItShouldGenerateValidLocations()
 {
     foreach (var filePurpose in FilePurposes.GetAll())
     {
         this.ItShouldGenerateAUrlFriendlyName(filePurpose.Name);
         this.ItShouldGenerateGuidStyleContainerNames(filePurpose.Name, filePurpose.IsPublic);
         this.ItShouldGenerateEncodeStyleBlobNames(filePurpose.Name);
         this.ItShouldGenerateTheSameOutputGivenTheSameInputs(filePurpose.Name);
         this.ItShouldGenerateDifferentOutputsGivenDifferentInputs(filePurpose.Name, filePurpose.IsPublic);
         this.ItShouldGeneratePublicAndPrivateUrlsCorrectly(filePurpose.Name, filePurpose.IsPublic);
     }
 }
Example #2
0
        public async Task ExecuteAsync(OrphanedFileData file)
        {
            file.AssertNotNull("file");

            var purpose = FilePurposes.TryGetFilePurpose(file.Purpose);

            if (purpose.IsPublic == false && file.ChannelId == null)
            {
                return;
            }

            var location = this.blobLocationGenerator.GetBlobLocation(file.ChannelId, file.FileId, file.Purpose);

            var blobClient = this.cloudStorageAccount.CreateCloudBlobClient();
            var container  = blobClient.GetContainerReference(location.ContainerName);
            var parentBlob = container.GetBlockBlobReference(location.BlobName);

            try
            {
                await parentBlob.DeleteAsync();
            }
            catch (StorageException t)
            {
                if (t.RequestInformation.HttpStatusCode != 404)
                {
                    throw;
                }
            }

            var blobDirectory = container.GetDirectoryReference(location.BlobName);

            IReadOnlyList <ICloudBlockBlob> childBlobs;

            try
            {
                childBlobs = await blobDirectory.ListCloudBlockBlobsAsync(true);
            }
            catch (StorageException t)
            {
                if (t.RequestInformation.HttpStatusCode != 404)
                {
                    throw;
                }

                return;
            }

            foreach (var blob in childBlobs)
            {
                await blob.DeleteAsync();
            }
        }
Example #3
0
        public BlobLocation GetBlobLocation(ChannelId channelId, FileId fileId, string filePurpose)
        {
            fileId.AssertNotNull("fileId");
            filePurpose.AssertNotNull("filePurpose");

            var purpose = FilePurposes.TryGetFilePurpose(filePurpose);

            if (purpose == null)
            {
                throw new BadRequestException("Unknown file purpose.");
            }

            if (purpose.IsPublic)
            {
                return(new BlobLocation(Constants.PublicFileBlobContainerName, fileId.Value.EncodeGuid()));
            }

            channelId.AssertNotNull("channelId");
            return(new BlobLocation(this.GetBlobContainerName(channelId), fileId.Value.EncodeGuid()));
        }