示例#1
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();
            }
        }
        protected bool Equals(OrphanedFileData other)
        {
            if (!object.Equals(this.FileId, other.FileId))
            {
                return(false);
            }

            if (!object.Equals(this.ChannelId, other.ChannelId))
            {
                return(false);
            }

            if (!object.Equals(this.Purpose, other.Purpose))
            {
                return(false);
            }

            return(true);
        }