예제 #1
0
        private async Task FindRecursive(DropboxClient dbx, string filepath, DropboxFolder folder)
        {
            var list = await dbx.Files.ListFolderAsync(filepath);

            foreach (var item in list.Entries.Where(i => i.IsFile))
            {
                if (fileExtensionsHelper.IsAllowedFileExtension(item.PathLower))
                {
                    var thumbnailResult = await dbx.Files.GetThumbnailAsync(item.PathLower);

                    var imageByteArr = await thumbnailResult.GetContentAsByteArrayAsync();

                    DropboxFile dropboxFile = new DropboxFile(item.PathLower, item.Name, Convert.ToInt64(item.AsFile.Size), folder.Depth, imageByteArr);
                    folder.AddFile(dropboxFile);
                }
            }

            int newDepth = folder.Depth;

            newDepth++;
            foreach (var item in list.Entries.Where(i => i.IsFolder))
            {
                DropboxFolder dropboxFolder = new DropboxFolder(item.PathLower, item.Name, newDepth);
                folder.AddFolder(dropboxFolder);
                await FindRecursive(dbx, item.PathLower, dropboxFolder);
            }
        }
예제 #2
0
        private async Task TraverseRecursive(DropboxClient dbx, string filepath, DropboxFolder folder, ApplicationUser currUser)
        {
            var list = await dbx.Files.ListFolderAsync(filepath);

            string dropboxFolderId;

            if (filepath == string.Empty)
            {
                dropboxFolderId = "";
            }
            else
            {
                var folderMetadata = await dbx.Files.GetMetadataAsync(filepath);

                dropboxFolderId = folderMetadata.AsFolder.Id;
            }

            // adding folder to table PhotographerFolders
            var photoFolder = new PhotographerFolder
            {
                Name              = folder.Name,
                Depth             = folder.Depth,
                Path              = folder.Path,
                DropboxCursor     = list.Cursor,
                DropboxFolderId   = dropboxFolderId,
                ApplicationUserId = currUser.Id,
                ApplicationUser   = currUser,
                PhotographerFiles = new List <PhotographerFile>()
            };

            db.PhotographerFolders.Add(photoFolder);
            db.SaveChanges();

            foreach (var item in list.Entries.Where(i => i.IsFile))
            {
                if (fileExtensionsHelper.IsAllowedFileExtension(item.PathLower))
                {
                    long fileSize = Convert.ToInt64(item.AsFile.Size);

                    var thumbnailResult = await dbx.Files.GetThumbnailAsync(item.PathLower);

                    var imageByteArr = await thumbnailResult.GetContentAsByteArrayAsync();

                    DropboxFile dropboxFile = new DropboxFile(item.PathLower, item.Name, fileSize, folder.Depth, imageByteArr);
                    folder.AddFile(dropboxFile);

                    // adding file to table PhotographerFiles
                    var photoFile = new PhotographerFile
                    {
                        Name                 = item.Name,
                        Size                 = fileSize,
                        Depth                = folder.Depth,
                        Path                 = item.PathLower,
                        ThumbnailImage       = imageByteArr,
                        DropboxFileId        = item.AsFile.Id,
                        PhotographerFolderId = photoFolder.PhotographerFolderId,
                        PhotographerFolder   = photoFolder
                    };
                    db.PhotographerFiles.Add(photoFile);
                    db.SaveChanges();
                    photoFolder.PhotographerFiles.Add(photoFile);
                }
            }
            db.SaveChanges();

            currUser.PhotographerFolders.Add(photoFolder);

            int newDepth = folder.Depth;

            newDepth++;
            foreach (var item in list.Entries.Where(i => i.IsFolder))
            {
                DropboxFolder dropboxFolder = new DropboxFolder(item.PathLower, item.Name, newDepth);
                folder.AddFolder(dropboxFolder);

                await TraverseRecursive(dbx, item.PathLower, dropboxFolder, currUser);
            }
        }