Ejemplo n.º 1
0
        public void DirectoryPathToPrefix(string filePath)
        {
            string prefix = AzureUtils.DirectoryPathToPrefix(filePath);

            Assert.StartsWith("media", prefix);
            Assert.EndsWith("/", prefix);
        }
Ejemplo n.º 2
0
        private IEnumerable <CloudBlockBlob> GetAllBlobs()
        {
            string prefix = AzureUtils.DirectoryPathToPrefix(this.physicalRootPath);

            BlobContinuationToken blobContinuationToken = null;

            do
            {
                BlobResultSegment results = this.cloudBlobContainer.ListBlobsSegmented(
                    prefix,
                    true,
                    BlobListingDetails.None,
                    null,
                    blobContinuationToken,
                    null,
                    null);

                blobContinuationToken = results.ContinuationToken;
                foreach (IListBlobItem item in results.Results)
                {
                    if (item is CloudBlockBlob cloudBlockBlob)
                    {
                        yield return(cloudBlockBlob);
                    }
                }
            }while (blobContinuationToken != null);
        }
        public IEnumerable <string> EnumerateFiles(string path, string extension, SearchOption searchOption)
        {
            Assert.ArgumentNotNullOrEmpty(path, nameof(path));

            extension = extension.Trim('.');
            string prefix = AzureUtils.DirectoryPathToPrefix(path);

            IEnumerable <IListBlobItem> items = this.azureProvider.EnumerateBlobs(prefix, searchOption);

            foreach (IListBlobItem item in items)
            {
                if (item is CloudBlockBlob cloudBlockBlob)
                {
                    var name = cloudBlockBlob.Name;

                    if (string.IsNullOrEmpty(prefix) || name.StartsWith(prefix))
                    {
                        if (string.IsNullOrEmpty(extension) || name.EndsWith($".{extension}"))
                        {
                            yield return(cloudBlockBlob.Name);
                        }
                    }
                }
            }
        }
        public bool DirectoryExists(string directoryPath)
        {
            string prefix = AzureUtils.DirectoryPathToPrefix(directoryPath);

            IEnumerable <IListBlobItem> list = this.azureProvider.EnumerateBlobs(
                prefix,
                SearchOption.AllDirectories,
                4);

            return(list.OfType <CloudBlockBlob>().Any());
        }
Ejemplo n.º 5
0
        private void EnsureCache()
        {
            if (!this.blobsItemsCache.Any())
            {
                lock (this.blobsItemsCache)
                {
                    if (!this.blobsItemsCache.Any())
                    {
                        string prefix = AzureUtils.DirectoryPathToPrefix(this.physicalRootPath);
                        Log.Info($"AZURE BLOB STORAGE. Creating cache (container={this.cloudBlobContainer.Name}, root={prefix}).", this);

                        foreach (CloudBlockBlob blob in this.GetAllBlobs())
                        {
                            this.blobsItemsCache[blob.Name] = blob;
                        }

                        Log.Info($"AZURE BLOB STORAGE. Cached created. Total nodes: {this.blobsItemsCache.Keys.Count} (container={this.cloudBlobContainer.Name}, root={prefix}).", this);
                    }
                }
            }
        }