Ejemplo n.º 1
0
        public async Task <string> PersistArticleEntryAsync(BlobStorageContainer container, Guid articleId, Guid entryContentId, string contentBase64)
        {
            if (string.IsNullOrWhiteSpace(contentBase64))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(contentBase64));
            }

            var articleEntryBlobContainer = GetCloudBlobContainer(container);
            var articleBlobDirectory      = articleEntryBlobContainer.GetDirectoryReference($"{articleId}");
            var entryContentBlob          = articleBlobDirectory.GetBlockBlobReference($"{entryContentId}");
            await entryContentBlob.UploadTextAsync(contentBase64);

            return(entryContentBlob.Uri.AbsoluteUri);
        }
Ejemplo n.º 2
0
        public async Task <bool> TryCreateContainer(BlobStorageContainer container)
        {
            var cloudBlobContainer = GetCloudBlobContainer(container);
            var isNewlyCreated     = await cloudBlobContainer.CreateIfNotExistsAsync();

            if (isNewlyCreated)
            {
                BlobContainerPermissions permissions = new BlobContainerPermissions
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob,
                };
                await cloudBlobContainer.SetPermissionsAsync(permissions);
            }

            return(isNewlyCreated);
        }
Ejemplo n.º 3
0
        private CloudBlobContainer GetCloudBlobContainer(BlobStorageContainer container)
        {
            var blobName = BlobStorageLookupValueObjects.BlobNameMap[container];

            return(_cloudBlobClient.GetContainerReference(blobName));
        }
Ejemplo n.º 4
0
        private async Task <string> UploadArticleEntry(EntryContent entryContent, string content, BlobStorageContainer storageContainer)
        {
            if (entryContent == null)
            {
                throw new ArgumentNullException(nameof(entryContent));
            }

            var contentBase64 = StringUtilities.ToBase64(content);

            return(await _blobstore.PersistArticleEntryAsync(storageContainer, entryContent.ArticleId, entryContent.Id, contentBase64));
        }