//---------------------------------------------------------------------------------------------------------------------------- public static async Task <StringBuilder> Test() { StringBuilder sb = new StringBuilder(); Console.WriteLine("----- Testing list folder"); List <Metadata> mdList = await DropboxWrapper.ListFolder("/GHSP Live Documents/LEGS"); Console.WriteLine("----- Testing list folder recursively"); mdList = await DropboxWrapper.ListFolderRecursive("/GHSP Live Documents/LEGS"); foreach (Metadata item in mdList) { sb.Append("<div>" + item.PathDisplay + " " + item.IsFolder + "</div>"); } return(sb); }
//---------------------------------------------------------------------------------------------------------------------------- /* List<TreeNode> BuildTreeAndGetRoots(List<Metadata> actualObjects) { * var lookup = new Dictionary<string, TreeNode>(); * var rootNodes = new List<TreeNode>(); * * foreach (Metadata item in actualObjects) { * // add us to lookup * TreeNode ourNode; * if (lookup.TryGetValue(item.PathLower, out ourNode)) { // was already found as a parent - register the actual object * ourNode..Source = item; * } else { * ourNode = new TreeNode() { Source = item }; * lookup.Add(item.ID, ourNode); * } * * // hook into parent * if (item.ParentID == item.ID) { // is a root node * rootNodes.Add(ourNode); * } else { // is a child row - so we have a parent * TreeNode parentNode; * if (!lookup.TryGetValue(item.ParentID, out parentNode)) { // unknown parent, construct preliminary parent * parentNode = new Node(); * lookup.Add(item.ParentID, parentNode); * } * parentNode.Children.Add(ourNode); * } * } * * return rootNodes; * } */ //---------------------------------------------------------------------------------------------------------------------------- public static async Task <string> ListFigures(string path) { List <Metadata> mdList = await DropboxWrapper.ListFolderRecursive(path); HtmlGenericControl ul = new HtmlGenericControl("ul"); // This is a little nastily coded here ... Regex rFigureFile = new Regex("[.]svg[z]?$"); int figuresFound = 0; if (mdList != null && mdList.Count > 0) { foreach (Metadata item in mdList) { if (item.IsFile && rFigureFile.IsMatch(item.PathLower) == true) { HtmlGenericControl li = new HtmlGenericControl("li"); li.InnerHtml = item.Name; li.Attributes.Add("class", "DBXWebFigure"); ul.Controls.Add(li); figuresFound++; } } } string html = " No figures available in this document's Dropbox folder."; if (figuresFound > 0) { html = HTMLUtilities.RenderControlToHtml(ul); } return(html); }
/* This is the kind of output dbx.ListFolderRecursive Metadata objects will provide * /GHSP Live Documents/LEGS True * /GHSP Live Documents/LEGS/Resources True * /GHSP Live Documents/LEGS/Standards True * /GHSP Live Documents/LEGS/Standards/EN True * /GHSP Live Documents/legs/standards/EN/LEGS_Handbook.xml False * /GHSP Live Documents/legs/standards/EN/Figure 2.1.ai False * /GHSP Live Documents/legs/standards/EN/Figure 3.1.ai False * /GHSP Live Documents/legs/standards/EN/Figure 3_Introduction.ai False * /GHSP Live Documents/legs/standards/EN/Figure 4.1.ai False * /GHSP Live Documents/legs/standards/EN/Figure 4_Introduction.ai False * /GHSP Live Documents/legs/standards/EN/Figure 5.1.ai False * /GHSP Live Documents/legs/standards/EN/Figure 5_Introduction.ai False */ //---------------------------------------------------------------------------------------------------------------------------- /// <summary> /// File extensions should be without the dot and in lower case e.g. "xml" /// </summary> /// <param name="filesExtensionsToInclude"></param> /// <returns></returns> public static async Task <TreeNode> GenerateTreeView(List <string> filesExtensionsToInclude) { List <Metadata> mdList = await DropboxWrapper.ListFolderRecursive("/GHSP Live Documents"); //TreeNode tn = BuildNodeList(mdList, fileExtensionsToInclude); //List<string> filesAndFolders = new List<string>(); //foreach (Metadata item in mdList) { //filesAndFolders.Add(item.PathDisplay); //} // OK now go through and chop out those that don't end with one of our file extensions for (int i = 0; i < mdList.Count; i++) { if (mdList[i].IsFile == true) { bool isValidSuffix = false; foreach (string fileExt in filesExtensionsToInclude) { if (mdList[i].PathLower.EndsWith("." + fileExt.ToLower()) == true) { isValidSuffix = true; break; } } if (isValidSuffix == false) { mdList.RemoveAt(i); i--; } } } //TreeView tv = new TreeView(); //PopulateTreeView(tv, filesAndFolders, '/'); TreeNode tn = CreateDirectoryNode(mdList, mdList[0]); //tv.SkipLinkText = ""; //TreeView tv = new TreeView(); //tv.ID = "TreeView"; //tv.SkipLinkText = String.Empty; //tv.CollapseImageUrl = "/Images/View.png"; //tv.CollapseImageToolTip = "/Images/Add.png"; //tv.ExpandImageToolTip = "/Images/Search.png"; //tv.ExpandImageUrl = "/Images/Help.png"; //tv.NoExpandImageUrl = "/Images/Ind.png"; //tv.ShowLines = false; //tv.LineImagesFolder = ""; //tv.ShowCheckBoxes = TreeNodeTypes.None; //tv.Nodes.Add(tn); return(tn); //return BuildHTMLList(tn); }