コード例 #1
0
        public BoxCollection GetFolderDetails(string id, int limit, int offSet, string fileFilters = "")
        {
            try
            {
                BoxCollection    collection = new BoxCollection();
                List <BoxEntity> result     = new List <BoxEntity>();

                var items = Task.Run(() => boxClient.FoldersManager.GetFolderItemsAsync(id, limit, offSet,
                                                                                        new List <string>()
                {
                    BoxFolder.FieldName,
                    BoxFolder.FieldPathCollection,
                    BoxFolder.FieldModifiedAt,
                    BoxFolder.FieldSize
                }
                                                                                        )).GetAwaiter().GetResult();

                foreach (var item in items.Entries)
                {
                    if (item.Type == "file" && !string.IsNullOrEmpty(fileFilters))
                    {
                        string fileExtension = Path.GetExtension(item.Name);
                        if (!fileFilters.Split(',').Contains(fileExtension))
                        {
                            continue;
                        }
                    }

                    var boxEnt = new BoxEntity()
                    {
                        Type         = item.Type,
                        Id           = item.Id,
                        Name         = item.Name,
                        ParentPath   = GetParentPath(item.PathCollection),
                        Size         = item.Size,
                        ModifiedTime = item.ModifiedAt
                    };


                    result.Add(boxEnt);
                }
                collection.BoxEntities = result;
                collection.Limit       = items.Limit;
                collection.Offset      = items.Offset;
                collection.TotalCount  = items.TotalCount;
                BoxFolder folderDetails = Task.Run(() => boxClient.FoldersManager.GetInformationAsync(id)).GetAwaiter().GetResult();
                collection.Path = GetFolderPath(folderDetails);
                collection.Path.Add(new BoxEntity()
                {
                    Id = folderDetails.Id, Name = folderDetails.Name
                });

                return(collection);
            }
            catch (Exception ex)
            {
                throw HandleException(ex);
            }
        }
コード例 #2
0
        private string GetParentPath(BoxCollection <BoxFolder> folderCollextion)
        {
            string path = "";

            foreach (var item in folderCollextion.Entries)
            {
                path += "/" + item.Name;
            }
            return(path);
        }