Ejemplo n.º 1
0
        public IEnumerable <FileSystemItem> GetItems(FileSystemLoadItemOptions options)
        {
            int parentId              = ParseKey(options.Directory.Key);
            var fileItems             = GetDirectoryContents(parentId);
            var hasSubDirectoriesInfo = GetHasSubDirectoriesInfo(fileItems);

            var clientItemList = new List <FileSystemItem>();

            foreach (var item in fileItems)
            {
                var clientItem = new FileSystemItem {
                    Key          = item.Id.ToString(),
                    Name         = item.Name,
                    IsDirectory  = item.IsDirectory,
                    DateModified = item.Modified
                };

                if (item.IsDirectory)
                {
                    clientItem.HasSubDirectories = hasSubDirectoriesInfo.ContainsKey(item.Id) && hasSubDirectoriesInfo[item.Id];
                }

                clientItem.CustomFields["modifiedBy"] = item.ModifiedBy.FullName;
                clientItem.CustomFields["created"]    = item.Created;
                clientItemList.Add(clientItem);
            }
            return(clientItemList);
        }
        public IEnumerable <FileSystemItem> GetItems(FileSystemLoadItemOptions options)
        {
            int parentId  = ParseKey(options.Directory.Key);
            var fileItems = GetDirectoryContents(parentId);

            var clientItemList = new List <FileSystemItem>();

            foreach (var item in fileItems)
            {
                var clientItem = new FileSystemItem {
                    Key          = item.Id.ToString(),
                    Name         = item.Name,
                    IsDirectory  = item.IsDirectory,
                    DateModified = item.Modified
                };

                if (item.IsDirectory)
                {
                    clientItem.HasSubDirectories = FileManagementDbContext.FileItems.Where(i => i.ParentId == item.Id && i.IsDirectory).Any();
                }

                clientItem.CustomFields["modifiedBy"] = item.ModifiedBy != null ? item.ModifiedBy.FullName : "";
                clientItem.CustomFields["created"]    = item.Created;
                clientItemList.Add(clientItem);
            }
            return(clientItemList);
        }
        public IEnumerable <FileSystemItem> GetItems(FileSystemLoadItemOptions options)
        {
            var result = new List <FileSystemItem>();
            BlobContinuationToken continuationToken = null;
            string dirKey = GetFileItemPath(options.Directory);

            if (!string.IsNullOrEmpty(dirKey))
            {
                dirKey = dirKey + "/";
            }
            CloudBlobDirectory dir = Container.GetDirectoryReference(dirKey);

            do
            {
                BlobResultSegment segmentResult = dir.ListBlobsSegmented(continuationToken);
                continuationToken = segmentResult.ContinuationToken;
                foreach (IListBlobItem blob in segmentResult.Results)
                {
                    var    item = new FileSystemItem();
                    string name = GetFileItemName(blob);
                    if (name == EmptyDirectoryDummyBlobName)
                    {
                        continue;
                    }

                    if (blob is CloudBlob)
                    {
                        var blockBlob = (CloudBlob)blob;
                        item.Name         = name;
                        item.DateModified = blockBlob.Properties.LastModified.GetValueOrDefault().DateTime;
                        item.Size         = blockBlob.Properties.Length;
                    }
                    else if (blob is CloudBlobDirectory)
                    {
                        var subDir = (CloudBlobDirectory)blob;
                        item.Name              = name.Substring(0, name.Length - 1);
                        item.IsDirectory       = true;
                        item.HasSubDirectories = GetHasDirectories(subDir);
                        item.DateModified      = DateTime.UtcNow;
                    }
                    else
                    {
                        throw new Exception("Unsupported blob type");
                    }
                    result.Add(item);
                }
            } while(continuationToken != null);

            return(result.OrderByDescending(item => item.IsDirectory)
                   .ThenBy(item => item.Name)
                   .ToList());
        }