public static myFolder createFolderStructure(string s, Folder folder, int indent)
        {
            myFolder fold = new myFolder();
            fold.children = new List<myFolder>();

            if (folder.Name == "")
            {
                fold.name = "root";
            } else {
                fold.name = folder.Name;
            }

            /*
             * INIT DATA FOR ATTRIBUTES
             */
            fold.size = new int();
            try{
                fold.size = folder.Size;
            }
            catch (System.InvalidOperationException e) {
                fold.size = 0;
            }

            fold.Created = folder.Created;
            fold.Role = folder.Role;
            fold.SharedLink = folder.SharedLink;
            fold.Updated = folder.Updated;
            //public DateTime Created { get; set; }
            //public string Role { get; set; }
            //public string SharedLink { get; set; }
            //public DateTime Updated { get; set; }

            string reqStr2 = "https://www.box.net/api/1.0/rest?action=get_collaborations&api_key=" + api_key + "&auth_token=" + boxProvider.authToken() + "&target=folder&target_id=" + folder.ID;
            string resp2 = getWebRequest(reqStr2);
            string respFin = "";
            while (resp2.IndexOf("<name>") > 0)
            {
                respFin += resp2.Substring(resp2.IndexOf("<name>") + 6, resp2.IndexOf("</name>") - resp2.IndexOf("<name>") - 6) + "~";
                resp2 = resp2.Substring(resp2.IndexOf("</name>") + 7);
            }

            myFolder collabs2 = new myFolder();
            collabs2.name = "Collaborators";
            collabs2.children = new List<myFolder>();

            String[] respSplit2 = respFin.Split('~');
            myFolder user = new myFolder();
            user.name = login;

            collabs2.children.Add(user);
            foreach (String collabName in respSplit2)
            {
                if (collabName != "")
                {
                    myFolder collab = new myFolder();
                    collab.name = collabName;
                    collabs2.children.Add(collab);
                }
            }

            fold.children.Add(collabs2);

            foreach (BoxSync.Core.Primitives.File file in folder.Files)
            {
                string reqStr = "https://www.box.net/api/1.0/rest?action=get_collaborations&api_key=" + api_key + "&auth_token=" + boxProvider.authToken() + "&target=file&target_id=" + file.ID;
                string resp = getWebRequest(reqStr);
                string respFin1 = "";
                while (resp.IndexOf("<name>") > 0)
                {
                    respFin1 += resp.Substring(resp.IndexOf("<name>") + 6, resp.IndexOf("</name>") - resp.IndexOf("<name>") - 6) + "~";
                    resp = resp.Substring(resp.IndexOf("</name>") + 7);
                }

                myFolder fileStruct = new myFolder();
                fileStruct.children = new List<myFolder>();
                fileStruct.size = file.Size;

                myFolder collabs = new myFolder();
                collabs.name = "Collaborators";
                collabs.children = new List<myFolder>();

                String[] respSplit99 = respFin1.Split('~');

                collabs.children.Add(user);
                foreach (String collabNames in respSplit99)
                {
                    if (collabNames != "")
                    {
                        myFolder collab = new myFolder();
                        collab.name = collabNames;
                        collabs.children.Add(collab);
                    }
                }

                fileStruct.children.Add(collabs);

                fileStruct.name = file.Name;
                fold.children.Add(fileStruct);
            }

            foreach (Folder subFolder in folder.Folders)
            {
                fold.children.Add(createFolderStructure(s, subFolder, indent + 1));
            }

            return fold;
        }
Beispiel #2
0
 public GetAccountTreeStatus GetFolderStructure(long folderID, RetrieveFolderStructureOptions retrieveOptions, out Folder folder);
        private Folder ParseFolderElement(XElement folderElement, Expression<Func<long, TagPrimitive>> materializeTag)
        {
            Folder folder = new Folder();

            XAttribute idAttribute = folderElement.Attribute(XName.Get("id"));
            XAttribute nameAttribute = folderElement.Attribute(XName.Get("name"));
            XAttribute descriptionAttribute = folderElement.Attribute(XName.Get("description"));
            XAttribute userIdAttribute = folderElement.Attribute(XName.Get("user_id"));
            XAttribute sharedAttribute = folderElement.Attribute(XName.Get("shared"));
            XAttribute sharedLinkAttribute = folderElement.Attribute(XName.Get("shared_link"));
            XAttribute permissionsAttribute = folderElement.Attribute(XName.Get("permissions"));
            XAttribute sizeAttribute = folderElement.Attribute(XName.Get("size"));
            XAttribute fileCountAttribute = folderElement.Attribute(XName.Get("file_count"));
            XAttribute createdAttribute = folderElement.Attribute(XName.Get("created"));
            XAttribute updatedAttribute = folderElement.Attribute(XName.Get("updated"));

            folder.Description = descriptionAttribute == null ? null : descriptionAttribute.Value;
            folder.ID = long.Parse(idAttribute.Value);
            folder.IsShared = sharedAttribute == null ? null : (bool?)sharedAttribute.Value.Equals("1");
            folder.Name = nameAttribute.Value;
            folder.SharedLink = sharedLinkAttribute == null ? null : sharedLinkAttribute.Value;
            folder.OwnerID = userIdAttribute == null ? null : (long?)long.Parse(userIdAttribute.Value);
            folder.Size = sizeAttribute == null ? null : (long?)long.Parse(sizeAttribute.Value);
            folder.PermissionFlags = permissionsAttribute == null ? null : (UserPermissionFlags?)ParsePermissionString(permissionsAttribute.Value);

            if (createdAttribute != null && !string.IsNullOrEmpty(createdAttribute.Value))
            {
                folder.Created = UnixTimeConverter.Instance.FromUnixTime(double.Parse(createdAttribute.Value));
            }

            if (updatedAttribute != null && !string.IsNullOrEmpty(updatedAttribute.Value))
            {
                folder.Updated = UnixTimeConverter.Instance.FromUnixTime(double.Parse(updatedAttribute.Value));
            }

            if (fileCountAttribute != null && !string.IsNullOrEmpty(fileCountAttribute.Value))
            {
                folder.FileCount = int.Parse(fileCountAttribute.Value);
            }

            XElement folders = GetFoldersElement(folderElement);
            IEnumerable<XElement> folderElements = GetFolderElements(folders);
            foreach (XElement fElement in folderElements)
            {
                folder.Folders.Add(ParseFolderElement(fElement, materializeTag));
            }

            XElement files = GetFilesElement(folderElement);
            IEnumerable<XElement> fileElements = GetFileElements(files);
            foreach (XElement fileElement in fileElements)
            {
                folder.Files.Add(ParseFileElement(fileElement));
            }

            XElement tagsElement = GetTagsElement(folderElement);
            IEnumerable<XElement> tagELements = GetTagElements(tagsElement);
            foreach (XElement tagElement in tagELements)
            {
                folder.Tags.Add(ParseTagElement(tagElement, materializeTag));
            }

            return folder;
        }
Beispiel #4
0
 public GetAccountTreeStatus GetRootFolderStructure(RetrieveFolderStructureOptions retrieveOptions, out Folder folder);
        public GetAccountTreeStatus GetFolderStructure(
            long folderID,
            RetrieveFolderStructureOptions retrieveOptions,
            out Folder folder)
        {
            folder = null;

            byte[] folderInfoXml;

            string result = _service.get_account_tree(_apiKey, _token, folderID, retrieveOptions.ToStringArray(), out folderInfoXml);
            GetAccountTreeStatus status = StatusMessageParser.ParseGetAccountTreeStatus(result);

            switch (status)
            {
                case GetAccountTreeStatus.Successful:
                    string folderInfo = null;

                    if (!retrieveOptions.Contains(RetrieveFolderStructureOptions.NoZip))
                    {
                        folderInfoXml = Unzip(folderInfoXml);
                    }

                    if (folderInfoXml != null)
                    {
                        folderInfo = Encoding.ASCII.GetString(folderInfoXml);
                    }

                    folder = ParseFolderStructureXmlMessage(folderInfo);
                    break;
            }

            return status;
        }