Example #1
0
        public override IEnumerable <File> GetAllFiles(string[] exclusions = null)
        {
            GoogleDriveDirectory[] directories = GetAllDirectories(exclusions).OfType <GoogleDriveDirectory>().ToArray();
            string parentsQuery = string.Join(" or ", directories.Select(d => string.Format("'{0}' in parents", d.folder.Id)));

            // Retrieve each directories files
            FilesResource.ListRequest request = Service.Files.List();
            request.Q          = string.Format("trashed = false and mimeType != '{0}' and ({1})", GoogleDriveDirectory.MimeType, parentsQuery);
            request.Fields     = "items(id,title,parents,fileSize,modifiedDate,md5Checksum,downloadUrl)";
            request.MaxResults = 1000;

            Google.Apis.Drive.v2.Data.File[] files = request.Execute().Items.ToArray();

            // Return each directory
            foreach (Google.Apis.Drive.v2.Data.File file in files)
            {
                GoogleDriveFile googleDriveFile = new GoogleDriveFile(this, directories.First(d => d.folder.Id == file.Parents.Single().Id), file);
                if (exclusions != null && exclusions.Any(e => MatchPattern(googleDriveFile.Path, e)))
                {
                    continue;
                }

                yield return(googleDriveFile);
            }
        }
Example #2
0
        public override void DeleteFile(File file)
        {
            if (!file.Parent.Equals(this))
            {
                throw new ArgumentException("The specified directory could not be found");
            }

            GoogleDriveFile googleDriveFile = file as GoogleDriveFile;

            if (storage.UseTrash)
            {
                FilesResource.TrashRequest request = storage.Service.Files.Trash(googleDriveFile.file.Id);
                request.Execute();
            }
            else
            {
                FilesResource.DeleteRequest request = storage.Service.Files.Delete(googleDriveFile.file.Id);
                request.Execute();
            }
        }