Esempio n. 1
0
        /// <summary>
        /// Recursive function going through all the folders & trying to find the file by the selector
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public GFile FindFileOrFolderInFolder(GFolder folder, Func <GFile, bool> predicate)
        {
            GFile result;

            result = folder.Files.FirstOrDefault(predicate);
            if (result != null)
            {
                return(result);
            }

            foreach (GFolder item in folder.Folders)
            {
                if (predicate(item))
                {
                    return(item);
                }

                GFile r = FindFileOrFolderInFolder(item, predicate);
                if (r != null)
                {
                    return(r);
                }
            }

            return(null);
        }
Esempio n. 2
0
        public void CreateFolder(GFolder destination, string newFolderName)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }
            if (string.IsNullOrEmpty(newFolderName))
            {
                throw new ArgumentNullException(nameof(newFolderName));
            }

            var folderCreateRequest = this.Service.Files.Create(new File()
            {
                Parents  = new string [] { destination?.FileInfo?.Id },
                Name     = newFolderName,
                MimeType = MimeTypes.GoogleFolder
            });

            if (!string.IsNullOrEmpty(DriveId))
            {
                folderCreateRequest.SupportsTeamDrives = true;
                folderCreateRequest.SupportsAllDrives  = false;
            }
            else
            {
                folderCreateRequest.SupportsTeamDrives = true;
                folderCreateRequest.SupportsAllDrives  = true;
            }

            folderCreateRequest.Execute();
        }
Esempio n. 3
0
        public void CopyFile(GFile source, GFolder destination, string newFileName)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            var fileCopyRequest = this.Service.Files.Copy(new File()
            {
                Parents = new string[] { destination?.FileInfo?.Id },
                Name    = newFileName
            }, source.FileInfo.Id);

            if (!string.IsNullOrEmpty(DriveId))
            {
                fileCopyRequest.SupportsTeamDrives = true;
                fileCopyRequest.SupportsAllDrives  = false;
            }
            else
            {
                fileCopyRequest.SupportsTeamDrives = true;
                fileCopyRequest.SupportsAllDrives  = true;
            }

            //var fileCopyRequest = this.Service.Files.Copy(source.FileInfo, source.FileInfo.Id);
            fileCopyRequest.Execute();
        }
        public void UpdateAllFilesAndFoldersInFolder(GFolder folder, Action <GFile> activity, Func <GFile, bool> predicate = null)
        {
            if (predicate == null || predicate(folder))
            {
                activity(folder);
            }

            folder.Folders.ToList().ForEach(f => UpdateAllFilesAndFoldersInFolder(f, activity, predicate));
            folder.Files.Where(f => predicate == null || predicate(f)).ToList().ForEach(f => activity(f));
        }