예제 #1
0
        /// <summary>
        /// Deletes an upload.
        /// </summary>
        /// <param name="teantId">Tenant identifier.</param>
        /// <param name="uploadId">Upload identifier.</param>
        /// <param name="storageHierarchy">Location of upload. E.g. { "Uploads" > "Users" }.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        public void Delete(long tenantId, long uploadId, List <string> storageHierarchy, IUnitOfWork unitOfWork = null)
        {
            // If we don't have a unit of work in place, create one now so that we can rollback all changes in case of failure
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            // Try to delete upload
            try
            {
                // Get main upload details from upload repository
                Upload upload = _uploadRepository.Read(tenantId, uploadId, unitOfWork ?? localUnitOfWork);

                // Delete record of upload
                _uploadRepository.Delete(tenantId, uploadId, unitOfWork ?? localUnitOfWork);

                // Delete upload in storage
                _storageService.Delete(upload, storageHierarchy, unitOfWork ?? localUnitOfWork);

                // Commit work if local unit of work in place
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
            }
            catch
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            finally
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Dispose();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Deletes an upload from underlying storage.
        /// </summary>
        /// <param name="upload">The upload to delete from underlying storage.</param>
        /// <param name="storageHierarchy">Location of created upload. E.g. { "Uploads" > "Users" }.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        public void Delete(Upload upload, List <string> storageHierarchy, IUnitOfWork unitOfWork = null)
        {
            // Get Azure storage configuration
            AzureStorageConfiguration configuration = _azureConfigurationService.GetStorageConfiguration(upload, storageHierarchy);

            // Retrieve storage account from connection string
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(configuration.ConnectionString);

            // Create the blob client
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve reference to a previously created container
            CloudBlobContainer blobContainer = blobClient.GetContainerReference(configuration.BlobContainerName);

            // Retrieve reference to blob
            CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(configuration.BlobPath);

            // If block blob exists, delete it
            if (blockBlob.ExistsAsync().Result)
            {
                blockBlob.DeleteAsync().Wait();
            }
        }