private GoogleDriveItem _ToGoogleDriveItem(Google.Apis.Drive.v3.Data.File file)
        {
            List <string> metdata = file.Description?.ToLower().Split('|').ToList();

            string title = null;
            string tags  = null;
            string desc  = null;

            // parse title, tags, and description from description field

            if (metdata?.Count() > 1)
            {
                title = metdata?.Where(m => m.StartsWith("title")).FirstOrDefault().Split(':')[1];
                tags  = metdata?.Where(m => m.StartsWith("tags")).FirstOrDefault().Split(':')[1];
                desc  = metdata?.Where(m => m.StartsWith("description")).FirstOrDefault().Split(':')[1];
            }
            var googleDriveItem = new GoogleDriveItem
            {
                Id          = file.Id,
                Name        = file.Name,
                Title       = title ?? file.Name,
                Tags        = tags?.Split(',').Select(t => t),
                Description = desc ?? file.Description,
                Url         = file.WebViewLink,
                IsVideo     = file.MimeType.Contains("video"),
                IsFolder    = file.MimeType.Equals("application/vnd.google-apps.folder"),
                Parents     = file.Parents,
            };


            // googleDriveItem.Children = childFolders;

            return(googleDriveItem);
        }
        private List <GoogleDriveItem> _BuildHeirarchy()
        {
            // non recursive solution. recursive would be a bit more elegant
            var allFolders = _allItems.Where(f => f.Parents != null && f.MimeType == "application/vnd.google-apps.folder").ToList();


            // loop thru folders, add all child folders
            var googleFolders = new List <GoogleDriveItem>();

            foreach (var folder in allFolders)
            {
                var item = _ToGoogleDriveItem(folder);

                // get children
                var childItems = _allItems.Where(f => f.Parents != null && f.MimeType == "application/vnd.google-apps.folder").Where(f2 => f2.Parents.Contains(folder.Id)).ToList();
                var childList  = new List <GoogleDriveItem>();

                foreach (var child in childItems)
                {
                    childList.Add(_ToGoogleDriveItem(child));
                }
                item.Children = childList;

                // add to folder list
                googleFolders.Add(item);
            }


            // process all folders that have children
            var stack = new Stack <GoogleDriveItem>();

            foreach (var folder in googleFolders)
            {
                if (folder.Parents != null && folder.Children.Count > 0)
                {
                    var parentId = folder.Parents[0];
                    if (parentId != _rootId)
                    {
                        stack.Push(folder);
                    }
                }
            }



            //process stack
            while (stack.Any())
            {
                // process stack item
                GoogleDriveItem node   = stack.Pop();
                var             parent = googleFolders.FirstOrDefault(f => f.Id == node.Parents[0]);

                // remove other children with same id
                var child = parent.Children.FirstOrDefault(f => f.Id == node.Id);
                if (child != null)
                {
                    parent.Children.Remove(child);
                }

                // add current node
                parent.Children.Add(node);
            }

            // return root level folders, all other folders have been moved under subfolders
            var rc = googleFolders.Where(f => f.Parents.Contains(_rootId)).ToList();

            return(rc);
        }