Esempio n. 1
0
        public BlobClient(string connectionString, string containerName, string accountName, string accountKey)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new System.ArgumentException($"'{nameof(connectionString)}' cannot be null or whitespace", nameof(connectionString));
            }

            if (string.IsNullOrWhiteSpace(containerName))
            {
                throw new System.ArgumentException($"'{nameof(containerName)}' cannot be null or whitespace", nameof(containerName));
            }

            if (string.IsNullOrWhiteSpace(accountName))
            {
                throw new ArgumentException($"'{nameof(accountName)}' cannot be null or whitespace", nameof(accountName));
            }

            if (string.IsNullOrWhiteSpace(accountKey))
            {
                throw new ArgumentException($"'{nameof(accountKey)}' cannot be null or whitespace", nameof(accountKey));
            }

            this.connectionString = connectionString;
            this.containerName    = containerName;
            this.accountName      = accountName;
            this.accountKey       = accountKey;
            var client = new Blobs.BlobServiceClient(this.connectionString);

            this.blobContainerClient = client.GetBlobContainerClient(this.containerName);
        }
Esempio n. 2
0
        public async Task <IBlobData> Fetch(string virtualPath)
        {
            var prefix = prefixes.FirstOrDefault(s => virtualPath.StartsWith(s, StringComparison.Ordinal));

            if (prefix == null)
            {
                return(null);
            }

            var mapping = mappings[prefix];

            var key = string.IsNullOrEmpty(mapping.BlobPrefix)
                    ? virtualPath.Substring(prefix.Length).TrimStart('/')
                    : mapping.BlobPrefix + "/" + virtualPath.Substring(prefix.Length).TrimStart('/');

            try
            {
                var blobClient = client.GetBlobContainerClient(mapping.Container).GetBlobClient(key);

                var s = await blobClient.DownloadAsync();

                return(new AzureBlob(s));
            }
            catch (RequestFailedException e)
            {
                if (e.Status == 404)
                {
                    throw new BlobMissingException($"Azure blob \"{key}\" not found.", e);
                }

                throw;
            }
        }
Esempio n. 3
0
        public async Task <IBlobData> Fetch(string virtualPath)
        {
            var mapping = mappings.FirstOrDefault(s => virtualPath.StartsWith(s.UrlPrefix,
                                                                              s.IgnorePrefixCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal));

            if (mapping.UrlPrefix == null)
            {
                return(null);
            }

            var partialKey = virtualPath.Substring(mapping.UrlPrefix.Length).TrimStart('/');

            if (mapping.LowercaseBlobPath)
            {
                partialKey = partialKey.ToLowerInvariant();
            }

            var key = string.IsNullOrEmpty(mapping.BlobPrefix)
                    ? partialKey
                    : mapping.BlobPrefix + "/" + partialKey;


            try
            {
                var blobClient = client.GetBlobContainerClient(mapping.Container).GetBlobClient(key);

                var s = await blobClient.DownloadAsync();

                return(new AzureBlob(s));
            }
            catch (RequestFailedException e)
            {
                if (e.Status == 404)
                {
                    throw new BlobMissingException($"Azure blob \"{key}\" not found.", e);
                }

                throw;
            }
        }