Exemple #1
0
        public async Task <BlobContainerViewModel> Handle(GetBlobContainerQuery request, CancellationToken cancellationToken)
        {
            var blobContainer = _cloudBlobClient.GetContainerReference(request.Name);

            if (request.CreateIfNotExists)
            {
                await blobContainer.CreateIfNotExistsAsync();
            }

            await blobContainer.FetchAttributesAsync();

            return(new BlobContainerViewModel
            {
                BlobContainer = BlobContainerDto.Create(new BlobContainer
                {
                    Name = blobContainer.Name,
                    LastModified = Convert.ToDateTime(blobContainer.Properties.LastModified.ToString()),
                    AccessType = (BlobContainerAccessType)(blobContainer.Properties.PublicAccess)
                }),
                DeleteEnabled = true,
                EditEnabled = true
            });
        }
        public async Task <BlobContainersListViewModel> Handle(GetAllBlobContainersQuery request, CancellationToken cancellationToken)
        {
            BlobContinuationToken continuationToken = null;

            var results = new List <CloudBlobContainer>();

            var blobContainers = new List <BlobContainer>();

            var model = new BlobContainersListViewModel {
                CreateEnabled = true
            };

            do
            {
                var response = await _cloudBlobClient.ListContainersSegmentedAsync(continuationToken);

                continuationToken = response.ContinuationToken;

                results.AddRange(response.Results);
            }while (continuationToken != null);

            foreach (var container in results)
            {
                await container.FetchAttributesAsync();

                model.BlobContainers.Add(
                    BlobContainerDto.Create(
                        new BlobContainer
                {
                    Name         = container.Name,
                    LastModified = Convert.ToDateTime(container.Properties.LastModified.ToString()),
                }));
            }

            return(model);
        }