Beispiel #1
0
    public override async Task <bool> DeleteAsync(BlobProviderDeleteArgs args)
    {
        var blobName = AzureBlobNameCalculator.Calculate(args);

        if (await BlobExistsAsync(args, blobName))
        {
            return(await GetBlobClient(args, blobName).DeleteIfExistsAsync());
        }

        return(false);
    }
Beispiel #2
0
    public override async Task <Stream> GetOrNullAsync(BlobProviderGetArgs args)
    {
        var blobName = AzureBlobNameCalculator.Calculate(args);

        if (!await BlobExistsAsync(args, blobName))
        {
            return(null);
        }

        var blobClient = GetBlobClient(args, blobName);
        var download   = await blobClient.DownloadAsync();

        return(await TryCopyToMemoryStreamAsync(download.Value.Content, args.CancellationToken));
    }
Beispiel #3
0
    public override async Task SaveAsync(BlobProviderSaveArgs args)
    {
        var blobName      = AzureBlobNameCalculator.Calculate(args);
        var configuration = args.Configuration.GetAzureConfiguration();

        if (!args.OverrideExisting && await BlobExistsAsync(args, blobName))
        {
            throw new BlobAlreadyExistsException($"Saving BLOB '{args.BlobName}' does already exists in the container '{GetContainerName(args)}'! Set {nameof(args.OverrideExisting)} if it should be overwritten.");
        }

        if (configuration.CreateContainerIfNotExists)
        {
            await CreateContainerIfNotExists(args);
        }

        await GetBlobClient(args, blobName).UploadAsync(args.BlobStream, true);
    }
Beispiel #4
0
        public override async Task <Stream> GetOrNullAsync(BlobProviderGetArgs args)
        {
            var blobName = AzureBlobNameCalculator.Calculate(args);

            if (!await BlobExistsAsync(args, blobName))
            {
                return(null);
            }

            var blobClient = GetBlobClient(args, blobName);
            var download   = await blobClient.DownloadAsync();

            var memoryStream = new MemoryStream();
            await download.Value.Content.CopyToAsync(memoryStream);

            return(memoryStream);
        }
Beispiel #5
0
    public override async Task <bool> ExistsAsync(BlobProviderExistsArgs args)
    {
        var blobName = AzureBlobNameCalculator.Calculate(args);

        return(await BlobExistsAsync(args, blobName));
    }