/// <summary>
        /// Creates a new BlobStorage object
        /// </summary>
        /// <param name="blobContainerName">The name of the blob to be managed</param>
        /// <param name="storageConnectionString">The connection string pointing to the storage account (this can be local or hosted in Windows Azure</param>
        public BlobStorageAsync(string blobContainerName, string storageConnectionString)
        {
            Validate.BlobContainerName(blobContainerName, "blobContainerName");
            Validate.String(storageConnectionString, "storageConnectionString");

            StorageConnectionString = storageConnectionString;
            BlobContainerName       = blobContainerName;
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new BlobStorage object
        /// </summary>
        /// <param name="blobContainerName">The name of the blob to be managed</param>
        /// <param name="storageConnectionString">The connection string pointing to the storage account (this can be local or hosted in Windows Azure</param>
        public BlobStorageAsync(string blobContainerName, string storageConnectionString)
        {
            Validate.BlobContainerName(blobContainerName, "blobContainerName");
            Validate.String(storageConnectionString, "storageConnectionString");

            var cloudStorageAccount = CloudStorageAccount.Parse(storageConnectionString);
            var cloudBlobClient     = cloudStorageAccount.CreateCloudBlobClient();

            cloudBlobContainer = cloudBlobClient.GetContainerReference(blobContainerName);
            cloudBlobContainer.CreateIfNotExists();

            var permissions = cloudBlobContainer.GetPermissions();

            permissions.PublicAccess = BlobContainerPublicAccessType.Container;
            cloudBlobContainer.SetPermissions(permissions);
        }
        public async Task UploadFileToBlobAsync(string sourceFilePath, BlobOptions options)
        {
            Validate.BlobContainerName(options.ContainerName, "containerName");
            Validate.BlobName(options.BlobName, "blobName");

            var destinationBlob = DataManagerUtility.GetCloudBlob(options);

            TransferManager.Configurations.ParallelOperations = 64;

            var context = new TransferContext
            {
                OverwriteCallback = (path, destinationPath) => options.OverwriteDestination
            };

            ProgressRecorder        = new ProgressRecorder();
            context.ProgressHandler = ProgressRecorder;

            await TransferManager.UploadAsync(sourceFilePath, destinationBlob, null, context, CancellationToken.None);
        }
        /// <summary>
        /// Returns a list of all the blobs in a container
        /// </summary>
        /// <param name="containerName"></param>
        /// <returns></returns>
        public async Task <IEnumerable <IListBlobItem> > ListBlobsInContainerAsync(string containerName)
        {
            Validate.BlobContainerName(containerName, "containerName");

            BlobContinuationToken token = new BlobContinuationToken();
            List <IListBlobItem>  list  = new List <IListBlobItem>();

            do
            {
                BlobResultSegment result = await cloudBlobContainer.ListBlobsSegmentedAsync(token);

                token = result.ContinuationToken;
                var blobs = result.Results;
                foreach (IListBlobItem blob in result.Results)
                {
                    list.Add(blob);
                }
            } while (token != null);

            return(list);
        }
Beispiel #5
0
 /// <summary>
 /// Returns a list of all the blobs in a container
 /// </summary>
 /// <param name="containerName"></param>
 /// <returns></returns>
 public IEnumerable <IListBlobItem> ListBlobsInContainer(string containerName)
 {
     Validate.BlobContainerName(containerName, "containerName");
     return(cloudBlobContainer.ListBlobs(null, true).ToList());
 }