public List<string> Invoke(List<string> fileIds) { try { using (DriveService driveService = DriveService.Create()) { var trashedFileIds = new List<string>(); var trashStreams = new List<API.DriveService.TrashStream>(); foreach (string fileId in fileIds) { FileInfo fileInfo = driveService.GetFile(fileId); if (fileInfo != null) { var trashStream = new API.DriveService.TrashStream(); trashStream.Init(fileInfo); trashStream.Visible = false; trashStreams.Add(trashStream); } trashedFileIds.Add(fileId); } driveService.TrashFiles(trashStreams); while (true) { bool finished = true; for (int i = 0; i < trashStreams.Count; i++) { API.DriveService.TrashStream trashStream = trashStreams[i]; if (!trashStream.Finished) { finished = false; break; } } if (finished) { break; } System.Threading.Thread.Sleep(250); } foreach (DriveService.TrashStream trashStream in trashStreams) { if (!trashStream.Completed) { trashedFileIds.Remove(trashStream.FileId); } else if (trashStream.Cancelled) { } else if (trashStream.Failed) { throw new LogException("Trash could not complete - " + trashStream.ExceptionMessage, true, true); } } return trashedFileIds; } } catch (Exception exception) { Log.Error(exception); return null; } }
public List <string> Invoke(List <string> fileIds) { try { using (DriveService driveService = DriveService.Create()) { var trashedFileIds = new List <string>(); var trashStreams = new List <API.DriveService.TrashStream>(); foreach (string fileId in fileIds) { FileInfo fileInfo = driveService.GetFile(fileId); if (fileInfo != null) { var trashStream = new API.DriveService.TrashStream(); trashStream.Init(fileInfo); trashStream.Visible = false; trashStreams.Add(trashStream); } trashedFileIds.Add(fileId); } driveService.TrashFiles(trashStreams); while (true) { bool finished = true; for (int i = 0; i < trashStreams.Count; i++) { API.DriveService.TrashStream trashStream = trashStreams[i]; if (!trashStream.Finished) { finished = false; break; } } if (finished) { break; } System.Threading.Thread.Sleep(250); } foreach (DriveService.TrashStream trashStream in trashStreams) { if (!trashStream.Completed) { trashedFileIds.Remove(trashStream.FileId); } else if (trashStream.Cancelled) { } else if (trashStream.Failed) { throw new LogException("Trash could not complete - " + trashStream.ExceptionMessage, true, true); } } return(trashedFileIds); } } catch (Exception exception) { Log.Error(exception); return(null); } }