示例#1
0
        public static string GetPath(BoxItemInternal folderInfo)
        {
            if (folderInfo.Id == "0")
            {
                return("/");
            }

            if ((folderInfo.Path_Collection == null) || (folderInfo.Path_Collection.Entries == null))
            {
                return(null);
            }

            string result = "/";

            for (int i = 1; i < folderInfo.Path_Collection.Entries.Count; ++i)
            {
                result += folderInfo.Path_Collection.Entries[i].Name + "/";
            }

            return(result + folderInfo.Name);
        }
 private void mergeItemToFile(BoxItemInternal boxItem, BoxFileInternal file)
 {
     file.Type                = boxItem.Type;
     file.Id                  = boxItem.Id;
     file.Sequence_Id         = boxItem.Sequence_Id;
     file.ETag                = boxItem.ETag;
     file.SHA1                = boxItem.SHA1;
     file.Name                = boxItem.Name;
     file.Description         = boxItem.Description;
     file.Size                = boxItem.Size;
     file.Path_Collection     = boxItem.Path_Collection;
     file.Created_At          = boxItem.Created_At;
     file.Modified_At         = boxItem.Modified_At;
     file.Trashed_At          = boxItem.Trashed_At;
     file.Purged_At           = boxItem.Purged_At;
     file.Content_Created_At  = boxItem.Content_Created_At;
     file.Content_Modified_At = boxItem.Content_Modified_At;
     file.Created_By          = boxItem.Created_By;
     file.Modified_By         = boxItem.Modified_By;
     file.Owned_By            = boxItem.Owned_By;
     //file.Shared_Link = boxItem.Shared_Link;
     file.Parent      = boxItem.Parent;
     file.Item_Status = boxItem.Item_Status;
 }
        /// <summary>
        /// Method to locate item by path or find the most further existing item in the path.
        /// </summary>
        /// <param name="pathItems"></param>
        /// <returns></returns>
        /// <remarks>Because of the limitations of the Box API we are recursively walking file system.</remarks>
        private async Task <Tuple <FileInfo, bool, int> > walkFileSystemTreeToGetLastItemExistingInThePath(string[] pathItems)
        {
            FileInfo currentResult = null;
            int      currentItemIndex;
            string   currentItemPath = string.Empty;
            string   workingPath     = string.Empty;


            for (currentItemIndex = 0; currentItemIndex < pathItems.Length; ++currentItemIndex)
            {
                workingPath = string.Format("{0}/{1}", workingPath, pathItems[currentItemIndex]);

                if (cached.ContainsKey(workingPath))
                {
                    var cachedResult = cached[workingPath];
                    if (cachedResult != null)
                    {
                        currentResult = cachedResult;
                    }
                    else
                    {
                        //return the last item we found
                        break;
                    }
                }
                else if (cached.Keys.Any(k => k.StartsWith(currentItemPath + "/")))
                {
                    //This key isn't found, but it's sibling is. Assume the item doesn't exist
                    break;
                }
                else
                {
                    BoxItemInternal result = null;

                    List <BoxItemInternal> contents = await this.getAllItemsForFolder(currentResult == null? "0" : currentResult.Id, 0);

                    for (int i = 0; i < contents.Count; ++i)
                    {
                        var entry = contents[i];
                        var fi    = new FileInfo {
                            Id = entry.Id
                        };
                        switch (entry.Type.ToLowerInvariant( ))
                        {
                        case "folder":
                            fi.IsFolder = true;
                            break;

                        case "file":
                            fi.IsFolder = false;
                            break;

                        default:
                            throw new NotImplementedException("The type " + entry.Type + " was not expected by GetItemByPath.");
                        }
                        string path = string.Format("{0}/{1}", currentItemPath, entry.Name);

                        if (!cached.ContainsKey(path))
                        {
                            cached.GetOrAdd(path, s => fi);
                        }
                    }
                    if (cached.ContainsKey(workingPath))
                    {
                        currentResult = cached[workingPath];
                    }
                    else
                    {
                        cached.GetOrAdd(workingPath, s => null);
                        //return the last item we found
                        break;
                    }
                }
                currentItemPath = workingPath;
            }

            return(new Tuple <FileInfo, bool, int>(currentResult, currentItemIndex == pathItems.Length, currentItemIndex));
        }
示例#4
0
 public static bool IsItemDeleted(BoxItemInternal folderInfo)
 {
     return((!string.IsNullOrWhiteSpace(folderInfo.Item_Status)) && (folderInfo.Item_Status.ToLowerInvariant( ) == "deleted"));
 }