public override void CreateFolder(BlobFolder folder)
 {
     if (folder.ParentUrl.IsNullOrEmpty())
     {
         folder.Name = NormalizeUrl(folder.Name);
     }
     base.CreateFolder(folder);
 }
        public static webModel.AssetListItem ToWebModel(this coreModel.BlobFolder assetFolder)
        {
            var retVal = new webModel.AssetListItem
            {
                Name      = assetFolder.Name,
                ParentUrl = assetFolder.ParentUrl,
                Url       = assetFolder.Url,
                Type      = "folder"
            };

            return(retVal);
        }
        public virtual void CreateFolder(BlobFolder folder)
        {
            var path = (folder.ParentUrl != null ? folder.ParentUrl + "/" : String.Empty) + folder.Name;

            var containerName = GetContainerNameFromUrl(path);
            var blobContainer = _cloudBlobClient.GetContainerReference(containerName);
            blobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Blob);

            var directoryPath = GetDirectoryPathFromUrl(path);
            if (!String.IsNullOrEmpty(directoryPath))
            {
                //Need upload empty blob because azure blob storage not support direct directory creation
                blobContainer.GetBlockBlobReference(directoryPath).UploadText(String.Empty);
            }
        }
        public virtual BlobSearchResult Search(string folderUrl, string keyword)
        {
            var retVal = new BlobSearchResult();

            if (!String.IsNullOrEmpty(folderUrl))
            {
                var blobContainer = GetBlobContainer(GetContainerNameFromUrl(folderUrl));

                if (blobContainer != null)
                {
                    var directoryPath = GetDirectoryPathFromUrl(folderUrl);
                    var blobDirectory = !String.IsNullOrEmpty(directoryPath) ? blobContainer.GetDirectoryReference(directoryPath) : null;
                    var listBlobs = blobDirectory != null ? blobDirectory.ListBlobs() : blobContainer.ListBlobs();
                    if (!String.IsNullOrEmpty(keyword))
                    {
                        listBlobs = blobContainer.ListBlobs(keyword, useFlatBlobListing: true);
                    }
                    // Loop over items within the container and output the length and URI.
                    foreach (IListBlobItem item in listBlobs)
                    {
                        var block = item as CloudBlockBlob;
                        var directory = item as CloudBlobDirectory;
                        if (block != null)
                        {
                            var blobInfo = new BlobInfo
                            {
                                Url = Uri.EscapeUriString(block.Uri.ToString()),
                                FileName = Path.GetFileName(Uri.UnescapeDataString(block.Uri.ToString())),
                                ContentType = block.Properties.ContentType,
                                Size = block.Properties.Length,
                                ModifiedDate = block.Properties.LastModified != null ? block.Properties.LastModified.Value.DateTime : (DateTime?)null
                            };
                            blobInfo.RelativeUrl = blobInfo.Url.Replace(_cloudBlobClient.BaseUri.ToString(), string.Empty);
                            //Do not return empty blob (created with directory because azure blob not support direct directory creation)
                            if (!String.IsNullOrEmpty(blobInfo.FileName))
                            {
                                retVal.Items.Add(blobInfo);
                            }
                        }
                        if (directory != null)
                        {
                            var folder = new BlobFolder
                            {
                                Name = Uri.UnescapeDataString(directory.Uri.AbsolutePath).Split(new[] { _cloudBlobClient.DefaultDelimiter }, StringSplitOptions.RemoveEmptyEntries).Last(),
                                Url = Uri.EscapeUriString(directory.Uri.ToString()),
                                ParentUrl = directory.Parent != null ? Uri.EscapeUriString(directory.Parent.Uri.ToString()) : null
                            };
                            folder.RelativeUrl = folder.Url.Replace(_cloudBlobClient.BaseUri.ToString(), string.Empty);
                            retVal.Folders.Add(folder);
                        }
                    }
                }
            }
            else
            {
                foreach (var container in _cloudBlobClient.ListContainers())
                {
                    var folder = new BlobFolder
                    {
                        Name = container.Uri.AbsolutePath.Split('/').Last(),
                        Url = Uri.EscapeUriString(container.Uri.ToString())
                    };
                    retVal.Folders.Add(folder);
                }
            }
            return retVal;
        }
Пример #5
0
 public IHttpActionResult CreateBlobFolder(BlobFolder folder)
 {
     _blobProvider.CreateFolder(folder);
     return StatusCode(HttpStatusCode.NoContent);
 }
        /// <summary>
        /// Create folder in file system within to base directory
        /// </summary>
        /// <param name="folder"></param>
        public void CreateFolder(BlobFolder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException("folder");
            }
            var path = _storagePath;
            if (folder.ParentUrl != null)
            {
                path = GetAbsoluteStoragePathFromUrl(folder.ParentUrl);
            }
            path = Path.Combine(path, folder.Name);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

        }
        /// <summary>
        /// Search folders and blobs in folder
        /// </summary>
        /// <param name="folderUrl">absolute or relative path</param>
        /// <returns></returns>
        public virtual BlobSearchResult Search(string folderUrl, string keyword)
        {
            var retVal = new BlobSearchResult();
            var storagePath = _storagePath;
            folderUrl = folderUrl ?? _basePublicUrl;

            var storageFolderPath = GetStoragePathFromUrl(folderUrl);
            if(!Directory.Exists(storageFolderPath))
            {
                return retVal;
            }
            var directories = String.IsNullOrEmpty(keyword) ? Directory.GetDirectories(storageFolderPath) : Directory.GetDirectories(storageFolderPath, "*" + keyword + "*", SearchOption.AllDirectories);
            foreach (var directory in directories)
            {
                var directoryInfo = new DirectoryInfo(directory);
                var folder = new BlobFolder
                {
                    Name = Path.GetFileName(directory),
                    Url = GetAbsoluteUrlFromPath(directory),
                    ParentUrl = GetAbsoluteUrlFromPath(directoryInfo.Parent.FullName)
                };
                folder.RelativeUrl = GetRelativeUrl(folder.Url);
                retVal.Folders.Add(folder);
            }

            var files = String.IsNullOrEmpty(keyword) ? Directory.GetFiles(storageFolderPath) : Directory.GetFiles(storageFolderPath, "*" + keyword + "*.*", SearchOption.AllDirectories);
            foreach (var file in files)
            {
                var fileInfo = new FileInfo(file);
                var blobInfo = new BlobInfo
                {
                    Url = GetAbsoluteUrlFromPath(file),
                    ContentType = MimeTypeResolver.ResolveContentType(fileInfo.Name),
                    Size = fileInfo.Length,
                    FileName = fileInfo.Name,
                    ModifiedDate = fileInfo.LastWriteTimeUtc
                };
                blobInfo.RelativeUrl = GetRelativeUrl(blobInfo.Url);
                retVal.Items.Add(blobInfo);
            }
            return retVal;
        }
Пример #8
0
        private PageFolder LoadFolderRecursive(BlobFolder blobFolder, string path)
        {
            var retVal = new PageFolder
            {
                FolderName = blobFolder.Name
            };
            var result = _contentStorageProvider.Search(blobFolder.Url, null);

            foreach (var childFolder in result.Folders)
            {
                retVal.Folders.Add(LoadFolderRecursive(childFolder, path + "/" + childFolder.Name));
            }

            foreach (var item in result.Items)
            {
                var page = item.ToPageWebModel();
                page.Id = path + "/" + item.FileName;
                retVal.Pages.Add(page);
            }
            return retVal;
        }
Пример #9
0
        private ThemeAsset[] LoadFolderAssetRecursive(BlobFolder blobFolder, string path, int level = 0)
        {
            var retVal = new List<ThemeAsset>();

            var result = _contentStorageProvider.Search(blobFolder.Url, null);
            foreach (var childFolder in result.Folders)
            {
                retVal.AddRange(LoadFolderAssetRecursive(childFolder, path + "/" + childFolder.Name, level + 1));
            }
            foreach (var item in result.Items)
            {
                var themeAssetItem = item.ToThemeAssetWebModel();
                themeAssetItem.Id = path + "/" + item.FileName;
                if (level > 0)
                {
                    themeAssetItem.Name = blobFolder.Name + "/" + themeAssetItem.Name;
                }
                retVal.Add(themeAssetItem);
            }
            return retVal.ToArray();
        }
 public static BlobFolder ToBlobModel(this ContentFolder folder)
 {
     var retVal = new BlobFolder();
     retVal.InjectFrom(folder);
     return retVal;
 }