/// <summary> /// Creates a blob for the specified fileUri and returns a write Stream object to it. /// </summary> public Stream Create(Uri fileUri) { var blockBlob = _client.GetBlockBlobReference(fileUri); _client.GetContainerReference(blockBlob.Blob.Container.Name).CreateIfNotExists(); return(blockBlob.Create()); }
public void Create(string path, BlobContainerPublicAccessType?accessType = null) { if (accessType.HasValue) { _cloudBlobClient.GetContainerReference(path).Create(accessType.Value); } else { _cloudBlobClient.GetContainerReference(path).Create(); } }
/// <summary> /// Recursively deletes blobs under a specified "directory URI." /// If only the container is specified, the entire container is deleted. /// </summary> public void DeleteDirectory(Uri directoryUri) { var uriSplit = directoryUri.AbsolutePath.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries); if (!uriSplit.Any()) { throw new StorageException(string.Format("URI {0} must contain at least the container.", directoryUri)); } var containerName = uriSplit[0]; var container = _client.GetContainerReference(containerName); if (uriSplit.Length == 1) { container.DeleteIfExists(); return; } var directory = container.GetDirectoryReference(uriSplit[1]); for (var i = 2; i < uriSplit.Length; i++) { directory = directory.GetDirectoryReference(uriSplit[i]); } foreach (var blob in directory.ListBlobs(true).OfType <ICloudBlob>()) { blob.DeleteIfExists(); } }
private async Task CreateContainerIfNotExistsAsync(Func <Catalog2RegistrationConfiguration, string> getContainer) { var containerName = getContainer(_options.Value); var container = _cloudBlobClient.GetContainerReference(containerName); _logger.LogInformation("Creating container {Container} with blobs publicly available if it does not already exist.", containerName); var permissions = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob, }; await container.CreateIfNotExistAsync(permissions); }
private static async Task CreateBlobIfNotExists(ICloudBlobClient cloudBlobClient, string containerName, string blobName) { var container = cloudBlobClient.GetContainerReference(containerName); await container.CreateIfNotExistsAsync(); var blob = container.GetBlockBlobReference(blobName); if (await blob.ExistsAsync()) { await blob.UploadTextAsync(string.Empty); } }
public VersionListDataClient( ICloudBlobClient cloudBlobClient, IOptionsSnapshot <AzureSearchConfiguration> options, ILogger <VersionListDataClient> logger) { _cloudBlobClient = cloudBlobClient ?? throw new ArgumentNullException(nameof(cloudBlobClient)); _options = options ?? throw new ArgumentNullException(nameof(options)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _lazyContainer = new Lazy <ICloudBlobContainer>( () => _cloudBlobClient.GetContainerReference(_options.Value.StorageContainer)); }
private async Task WriteFinalBlobAsync(List <RepositoryInformation> finalList) { var blobReference = _cloudClient.GetContainerReference(BlobStorageContainerName).GetBlobReference(GitHubUsageFileName); using (var stream = await blobReference.OpenWriteAsync(accessCondition: null)) using (var streamWriter = new StreamWriter(stream)) using (var jsonTextWriter = new JsonTextWriter(streamWriter)) { blobReference.Properties.ContentType = "application/json"; Serializer.Serialize(jsonTextWriter, finalList); } }
private async Task <ICloudBlobContainer> PrepareContainer(string folderName, bool isPublic) { var container = _client.GetContainerReference(folderName); await container.CreateIfNotExistAsync(); await container.SetPermissionsAsync( new BlobContainerPermissions { PublicAccess = isPublic ? BlobContainerPublicAccessType.Blob : BlobContainerPublicAccessType.Off }); return(container); }
public PopularityTransferDataClient( ICloudBlobClient cloudBlobClient, IOptionsSnapshot <AzureSearchConfiguration> options, IAzureSearchTelemetryService telemetryService, ILogger <PopularityTransferDataClient> logger) { _cloudBlobClient = cloudBlobClient ?? throw new ArgumentNullException(nameof(cloudBlobClient)); _options = options ?? throw new ArgumentNullException(nameof(options)); _telemetryService = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _lazyContainer = new Lazy <ICloudBlobContainer>( () => _cloudBlobClient.GetContainerReference(_options.Value.StorageContainer)); }
/// <summary> /// This constructor is used for testing. /// </summary> internal BlobContainerBuilder( ICloudBlobClient cloudBlobClient, IOptionsSnapshot <AzureSearchConfiguration> options, ILogger <BlobContainerBuilder> logger, TimeSpan retryDelay) { _cloudBlobClient = cloudBlobClient ?? throw new ArgumentNullException(nameof(cloudBlobClient)); _options = options ?? throw new ArgumentNullException(nameof(options)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _lazyContainer = new Lazy <ICloudBlobContainer>(() => { return(_cloudBlobClient.GetContainerReference(_options.Value.StorageContainer)); }); _retryDelay = retryDelay; }
public IFileSystem GetAzureFileSystem() { var conf = AzureBlockBlobFileSystemConfiguration.ConfigurationModule .Set(AzureBlockBlobFileSystemConfiguration.ConnectionString, "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;") .Build(); var injector = TangFactory.GetTang().NewInjector(conf); injector.BindVolatileInstance(TestCloudBlobClient); var fs = injector.GetInstance <AzureBlockBlobFileSystem>(); TestCloudBlobClient.BaseUri.ReturnsForAnyArgs(FakeUri); TestCloudBlobClient.GetBlockBlobReference(FakeUri).ReturnsForAnyArgs(TestCloudBlockBlob); TestCloudBlobClient.GetContainerReference("container").ReturnsForAnyArgs(TestCloudBlobContainer); TestCloudBlobContainer.GetDirectoryReference("directory").ReturnsForAnyArgs(TestCloudBlobDirectory); TestCloudBlobDirectory.GetDirectoryReference("directory").ReturnsForAnyArgs(TestCloudBlobDirectory); return(fs); }
public IFileSystem GetAzureFileSystem() { var conf = AzureBlobFileSystemConfiguration.ConfigurationModule .Set(AzureBlobFileSystemConfiguration.AccountName, "accountName") .Set(AzureBlobFileSystemConfiguration.AccountKey, "accountKey") .Build(); var injector = TangFactory.GetTang().NewInjector(conf); injector.BindVolatileInstance(TestCloudBlobClient); var fs = injector.GetInstance <AzureBlobFileSystem>(); TestCloudBlobClient.BaseUri.ReturnsForAnyArgs(BaseUri); TestCloudBlockBlob.Open().Returns(TestOpenStream); TestCloudBlockBlob.Create().Returns(TestCreateStream); TestCloudBlockBlob.Blob.ReturnsForAnyArgs(new CloudBlockBlob(FakeUri)); TestCloudBlobClient.GetBlockBlobReference(FakeUri).ReturnsForAnyArgs(TestCloudBlockBlob); TestCloudBlobClient.GetContainerReference("container").ReturnsForAnyArgs(TestCloudBlobContainer); TestCloudBlobContainer.GetDirectoryReference("directory").ReturnsForAnyArgs(TestCloudBlobDirectory); TestCloudBlobDirectory.GetDirectoryReference("directory").ReturnsForAnyArgs(TestCloudBlobDirectory); return(fs); }
void PrepareContainer( string folderName, bool isPublic) { var container = client.GetContainerReference(folderName); container.CreateIfNotExist(); if (isPublic) { container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); } else { container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Off }); } containers.Add(folderName, container); }
protected Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob GetBlobReference(string path) { BlobContainerCollection.Instance.GetOrCreate(AccountInfo.Instance.RootContainer); return(_cloudBlobClient.GetContainerReference(AccountInfo.Instance.RootContainer).GetBlockBlobReference(path)); }
private static async Task CreateBlobContainerIfNotExists(ICloudBlobClient cloudBlobClient, string containerName) { var container = cloudBlobClient.GetContainerReference(containerName); await container.CreateIfNotExistsAsync(); }
private ICloudBlobContainer GetContainer(HiveType hive) { var containerName = GetContainerName(hive); return(_cloudBlobClient.GetContainerReference(containerName)); }
protected Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory GetDirectoryReference(string path) { return(_cloudBlobClient.GetContainerReference(AccountInfo.Instance.RootContainer).GetDirectoryReference(path)); }