public bool CreateFolder(string name, string parentFolder) { var folder = DriveApi.createDirectory(_service, name, name, parentFolder); foreach (var user in _grantedUsers) { DriveApi.InsertPermission(_service, folder.Id, user, "user", "writer"); } return(true); }
public IEnumerable <string> List() { var fileList = DriveApi.GetFiles(_service, null); var stringList = new List <string>(); foreach (var file in fileList) { var fileString = $"[{file.Id}] [{file.MimeType}] -> {file.Name}, {file.ModifiedTime}"; stringList.Add(fileString); } return(stringList); }
public bool DeleteAgedFiles(int fileAgeInDays, string folder, int filesToKeepAtLeast, bool preview) { var folders = DriveApi.GetFilesByName(_service, folder, DriveApi.NameSearchOperators.Is); if (folders.Count != 1) { throw new ArgumentException($"{folder} not found or not unique in your store.", folder); } var time = DateTime.Now - new TimeSpan(fileAgeInDays, 0, 0, 0, 0); string timeString = time.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss", DateTimeFormatInfo.InvariantInfo); var files = DriveApi.GetFiles(_service, $"modifiedTime <= '{timeString}' and '{folders[0].Id}' in parents"); if (filesToKeepAtLeast > 1) { var newFiles = DriveApi.GetFiles(_service, $"modifiedTime > '{timeString}' and '{folders[0].Id}' in parents"); if (newFiles.Count < filesToKeepAtLeast) { Console.Write($"You wanted to keep at least {filesToKeepAtLeast} files in store, but if you go on there would just be {newFiles.Count} left"); return(false); } } foreach (var file in files) { if (preview) { Console.WriteLine($"This would delete {file.Name}, {file.ModifiedTime} (preview mode)."); } else { DeleteObject(file.Id); } } return(true); }
public bool UploadFile(string uploadFile, string uploadFolder) { File mySqlFolder; var mySqlFolderSearch = DriveApi.GetFiles(_service, $"name='{uploadFolder}'"); if (mySqlFolderSearch.Count == 1) { mySqlFolder = mySqlFolderSearch.FirstOrDefault(); } else { throw new ArgumentException("Folder not found.", "uploadFolder"); } var file = DriveApi.UploadFile(_service, uploadFile, mySqlFolder.Id); foreach (var user in _grantedUsers) { DriveApi.InsertPermission(_service, file.Id, user, "user", "writer"); } return(true); }
public bool DeleteObject(string objectId) { return(DriveApi.DeleteObject(_service, objectId)); }