static async Task Run() { HttpClientHandler handler = new HttpClientHandler(); using (var client = new HttpClient(handler, false)) { CategoriesItemsViewModelDB aux = await ListRootFolder(dropbox); List <DropBoxItems> items = new List <DropBoxItems>(); List <DropBoxCategory> categories = new List <DropBoxCategory>(); List <DropBoxItems> auxI = new List <DropBoxItems>(); List <DropBoxCategory> auxC = new List <DropBoxCategory>(); List <DropBoxItems> auxIRemove = new List <DropBoxItems>(); List <DropBoxCategory> auxCRemove = new List <DropBoxCategory>(); var auxItems = aux.Items.Select(DropBoxItems => DropBoxItems); var auxCategories = aux.Categories.Select(DropBoxCategory => DropBoxCategory); foreach (DropBoxItems i in auxItems) { items.Add(i); } foreach (DropBoxCategory c in auxCategories) { categories.Add(c); } if (auxCivm.Items.Count() > 0) { foreach (DropBoxItems i in auxCivm.Items) { bool exist = false; int j = 0; for (j = 0; j < items.Count() && exist == false; j++) { if (items[j].Title.Equals(i.Title)) { exist = true; } } if (exist == false) { auxIRemove.Add(i); } } foreach (DropBoxCategory c in auxCivm.Categories) { bool exist = false; int j = 0; for (j = 0; j < categories.Count() && exist == false; j++) { if (categories[j].CategoryType.Equals(c.CategoryType)) { exist = true; } } if (exist == false) { auxCRemove.Add(c); } } auxCivmRemove.Items = auxIRemove; auxCivmRemove.Categories = auxCRemove; for (int j = 0; j < items.Count(); j++) { bool exist = false; foreach (DropBoxItems i in auxCivm.Items) { if (items[j].Title.Equals(i.Title)) { exist = true; } } if (exist == false) { auxI.Add(items[j]); } } for (int j = 0; j < categories.Count(); j++) { bool exist = false; foreach (DropBoxCategory c in auxCivm.Categories) { if (categories[j].CategoryType.Equals(c.CategoryType)) { exist = true; } } if (exist == false) { auxC.Add(categories[j]); } } auxCivm.Categories = auxC; auxCivm.Items = auxI; } else { auxCivm.Categories = categories; auxCivm.Items = items; } //await Download(dbx,"","Get Started with Dropbox.pdf"); } }
static async Task <CategoriesItemsViewModelDB> ListRootFolder(DropboxClient dbx) { HttpClientHandler handler = new HttpClientHandler(); using (var client = new HttpClient(handler, false)) { CategoriesItemsViewModelDB catItems = new CategoriesItemsViewModelDB(); List <DropBoxItems> items = new List <DropBoxItems>(); List <DropBoxCategory> categories = new List <DropBoxCategory>(); var list = await dbx.Files.ListFolderAsync(string.Empty); foreach (var folder in list.Entries.Where(i => i.IsFolder)) { var cFolder = await dbx.Files.ListFolderAsync("/" + folder.Name); foreach (var file in cFolder.Entries.Where(i => i.IsFile)) { bool cExist = false; DropBoxItems item = new DropBoxItems(); String fName = file.Name; String aux = fName.Substring(0, (fName.IndexOf('.'))); String form = fName.Substring(fName.IndexOf('.'), (fName.Length - fName.IndexOf('.'))); //item = new Items{Title=aux,Format=form, Path=Path.Combine(uploads,file.FileName),date=System.DateTime.UtcNow.ToString()}; item.Title = aux; item.Format = form; item.date = System.DateTime.UtcNow.ToString(); item.Tags = folder.Name; item.Path = file.PathDisplay; //To be replaced //var author = await dbx.Users.GetCurrentAccountAsync(); //item.Author = author.Email.ToString(); item.Author = "DropBox User"; if (!item.Tags.Equals("/")) { item.Link = "https://www.dropbox.com/home/" + item.Tags + "?preview="; } else { item.Link = "https://www.dropbox.com/home?preview="; } String lPath = ""; char[] lAux = (item.Title + item.Format).ToCharArray(); foreach (var c in lAux) { if (c == ' ') { lPath = lPath + "+"; } else { lPath = lPath + c; } } item.Link = item.Link + lPath; items.Add(item); DropBoxCategory category = new DropBoxCategory { CategoryType = form }; for (int i = 0; i < (categories.Count()) && (cExist == false); i++) { if (categories[i].CategoryType.Equals(form)) { cExist = true; } } if (cExist == false) { categories.Add(category); } } } foreach (var file in list.Entries.Where(i => i.IsFile)) { bool cExist = false; DropBoxItems item = new DropBoxItems(); String fName = file.Name; String aux = fName.Substring(0, (fName.IndexOf('.'))); String form = fName.Substring(fName.IndexOf('.'), (fName.Length - fName.IndexOf('.'))); //item = new Items{Title=aux,Format=form, Path=Path.Combine(uploads,file.FileName),date=System.DateTime.UtcNow.ToString()}; item.Title = aux; item.Format = form; item.date = System.DateTime.UtcNow.ToString(); item.Tags = file.PathDisplay.Substring(0, (file.PathDisplay.IndexOf(file.Name[0]))); item.Path = file.PathDisplay; //var author = await dbx.Users.GetCurrentAccountAsync(); //item.Author = author.Email.ToString(); item.Author = "DropBox User"; if (!item.Tags.Equals("/")) { item.Link = "https://www.dropbox.com/home/" + item.Tags + "?preview="; } else { item.Link = "https://www.dropbox.com/home?preview="; } String lPath = ""; char[] lAux = (item.Title + item.Format).ToCharArray(); foreach (var c in lAux) { if (c == ' ') { lPath = lPath + "+"; } else { lPath = lPath + c; } } item.Link = item.Link + lPath; items.Add(item); DropBoxCategory category = new DropBoxCategory { CategoryType = form }; for (int i = 0; i < (categories.Count()) && (cExist == false); i++) { if (categories[i].CategoryType.Equals(form)) { cExist = true; } } if (cExist == false) { categories.Add(category); } } catItems.Categories = categories; catItems.Items = items; return(catItems); } }