コード例 #1
0
        public async Task <List <GithubFolderItem> > ParseListIntoTree(IEnumerable <JsonItem> list, string path)
        {
            var    glist      = new List <GithubFolderItem>();
            string dashed     = path + "/";
            int    dashLength = dashed.Length;

            var parsed = list.Where(i =>
            {
                if (string.IsNullOrEmpty(path))
                {
                    return(!i.Path.Contains("/"));
                }

                // not our path
                if (!i.Path.StartsWith(dashed))
                {
                    return(false);
                }

                // this must be a sub-path
                if (i.Path.LastIndexOf('/') > dashLength)
                {
                    return(false);
                }


                // Yup
                return(true);
            });

            foreach (var item in parsed)
            {
                var gitem = new GithubFolderItem()
                {
                    FullPath = item.Path,
                };
                gitem.Name = gitem.FullPath;
                if (gitem.FullPath.Contains("/"))
                {
                    gitem.Name = Path.GetFileName(gitem.FullPath);
                }

                if (item.Type == "tree")
                {
                    gitem.Items = await ParseListIntoTree(list, gitem.FullPath);
                }
                else
                {
                    gitem.Size = item.Size;
                }

                glist.Add(gitem);
            }

            return(glist);
        }
コード例 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public async Task <GithubContentItem> GetItemContent(GithubFolderItem item)
 {
     return(await GetItemContent(item.FullPath));
 }