public async Task <DriveFile> UploadFileAsync(string pathName, DriveFile destFolder, string storageFileId, CancellationToken token) { using (var stream = File.OpenRead(pathName)) { return(await UploadFileAsync(stream, Path.GetFileName(pathName), destFolder, storageFileId, token)); } }
public override async Task<DriveFile> UploadFileAsync(Stream fileStream, string fileName, DriveFile destFolder, string storageFileId, CancellationToken token) { var file = new MockDriveFile(this, fileName, false); file.content = new byte[fileStream.Length]; fileStream.Read(file.content, 0, (int)fileStream.Length); MockDriveFile folder = (MockDriveFile)destFolder; folder.Add(file); return file; }
private static string GetFileName(DriveFile file, bool isLantinOnlySupport) { if (file == null) { return(null); } if (isLantinOnlySupport) { return(file.Name.Unidecode()); } return(file.Name); }
public virtual async Task <Image> GetImageAsync(DriveFile file, CancellationToken token) { using (var stream = await ReadFileAsync(file, token)) { try { return(await Task.Run(() => Image.FromStream(stream))); } catch (Exception) { throw new BadImageFormatException(); } } }
private void PutFileTo(DriveFile file, IDictionary <string, DriveFileCollection> fileCollections) { DriveFileCollection collection; if (file.StorageFileId == null) { if (!TryFindFileByName(file.Name, file.Drive.IsLantinOnlySupport, fileCollections.Values, out collection)) { collection = new DriveFileCollection(); fileCollections.Add(file.StorageFileId ?? Guid.NewGuid().ToString(), collection); } } else if (!fileCollections.TryGetValue(file.StorageFileId, out collection)) { collection = new DriveFileCollection(); fileCollections.Add(file.StorageFileId ?? Guid.NewGuid().ToString(), collection); } collection.Add(file); }
internal bool DeleteFileRecursive(DriveFile driveFile) { var y = files.FirstOrDefault(x => x.Name == driveFile.Name); if (y != null) { return files.Remove(y); } else { foreach (var x in files.Where(x=>x.IsFolder && x.files.Count > 0)) { if (x.DeleteFileRecursive(driveFile)) { return true; } } return false; } }
public abstract Task DeleteFolderAsync(DriveFile driveFolder, CancellationToken token);
public override async Task DeleteFolderAsync(DriveFile driveFolder, CancellationToken token) { rootFolder.DeleteFileRecursive(driveFolder); }
public abstract Task<ICollection<DriveFile>> GetSubfoldersAsync(DriveFile folder, CancellationToken token);
public abstract Task<Image> GetThumbnailAsync(DriveFile file, CancellationToken token);
public abstract Task<DriveFile> UploadFileAsync(Stream fileStream, string fileName, DriveFile destFolder, string storageFileId, CancellationToken token);
public override Task<System.Drawing.Image> GetThumbnailAsync(DriveFile file, CancellationToken token) { throw new NotImplementedException(); }
private static string GetFileName(DriveFile file, bool isLantinOnlySupport) { if (file == null) { return null; } if (isLantinOnlySupport) { return file.Name.Unidecode(); } return file.Name; }
public override async Task DownloadFileAsync(DriveFile driveFile, Stream output, CancellationToken token) { await output.WriteAsync(((MockDriveFile)driveFile).content, 0, ((MockDriveFile)driveFile).content.Length); }
public abstract Task DownloadFileAsync(DriveFile driveFile, string destFolder, ActionIfFileExists actionIfFileExists, CancellationToken token);
public abstract Task EnumerateFilesRecursive(DriveFile driveFolder, Action <DriveFile> action, CancellationToken token);
public override async Task DownloadFileAsync(DriveFile driveFile, string destFolder, ActionIfFileExists actionIfFileExists, CancellationToken token) { throw new NotImplementedException(); }
public override async Task EnumerateFilesRecursive(DriveFile driveFolder, Action<DriveFile> action, CancellationToken token) { throw new NotImplementedException(); }
public override async Task<Stream> ReadFileAsync(DriveFile file, CancellationToken token) { return new MemoryStream(((MockDriveFile)file).content); }
public abstract Task EnumerateFilesRecursive(DriveFile driveFolder, Action<DriveFile> action, CancellationToken token);
private void PutFileTo(DriveFile file, IDictionary<string, DriveFileCollection> fileCollections) { DriveFileCollection collection; if (file.StorageFileId == null) { if (!TryFindFileByName(file.Name, file.Drive.IsLantinOnlySupport, fileCollections.Values, out collection)) { collection = new DriveFileCollection(); fileCollections.Add(file.StorageFileId ?? Guid.NewGuid().ToString(), collection); } } else if (!fileCollections.TryGetValue(file.StorageFileId, out collection)) { collection = new DriveFileCollection(); fileCollections.Add(file.StorageFileId ?? Guid.NewGuid().ToString(), collection); } collection.Add(file); }
public abstract Task DownloadFileAsync(DriveFile driveFile, Stream output, CancellationToken token);
public override async Task<ICollection<DriveFile>> GetSubfoldersAsync(DriveFile folder, CancellationToken token) { return ((MockDriveFile)folder).files.Where(x => x.IsFolder).Cast<DriveFile>().ToList(); }
public virtual async Task<Image> GetImageAsync(DriveFile file, CancellationToken token) { using (var stream = await ReadFileAsync(file, token)) { try { return await Task.Run(() => Image.FromStream(stream)); } catch(Exception) { throw new BadImageFormatException(); } } }
public abstract Task <DriveFile> UploadFileAsync(Stream fileStream, string fileName, DriveFile destFolder, string storageFileId, CancellationToken token);
public abstract Task <Stream> ReadFileAsync(DriveFile file, CancellationToken token);
public async Task<DriveFile> UploadFileAsync(string pathName, DriveFile destFolder, string storageFileId, CancellationToken token) { using (var stream = File.OpenRead(pathName)) { return await UploadFileAsync(stream, Path.GetFileName(pathName), destFolder, storageFileId, token); } }
public abstract Task <Image> GetThumbnailAsync(DriveFile file, CancellationToken token);
public abstract Task<Stream> ReadFileAsync(DriveFile file, CancellationToken token);
public abstract Task <DriveFile> CreateFolderAsync(string folderName, DriveFile destFolder, CancellationToken token);
public abstract Task<DriveFile> CreateFolderAsync(string folderName, DriveFile destFolder, CancellationToken token);
public abstract Task <ICollection <DriveFile> > GetSubfoldersAsync(DriveFile folder, CancellationToken token);
public override async Task<DriveFile> CreateFolderAsync(string folderName, DriveFile destFolder, CancellationToken token) { return ((MockDriveFile)destFolder).CreateFolder(folderName); }