/// <summary> /// Move the given file /// </summary> /// <param name="library">The library th file is in</param> /// <param name="filePath">The full path of the file</param> /// <param name="targetLibrary">The library to move this file to</param> /// <param name="targetDirectory">The directory to move this file to</param> /// <returns>A value which indicates if the action was successful</returns> public async Task <bool> MoveFile(SeafLibrary library, string filePath, SeafLibrary targetLibrary, string targetDirectory) { library.ThrowOnNull(nameof(library)); targetLibrary.ThrowOnNull(nameof(targetLibrary)); return(await MoveFile(library.Id, filePath, targetLibrary.Id, targetDirectory)); }
/// <summary> /// Move the given file /// </summary> /// <param name="dirEntry">The directory entry of the file to move</param> /// <param name="targetLibrary">The library to move this file to</param> /// <param name="targetDirectory">The directory to move this file to</param> /// <returns>A value which indicates if the action was successful</returns> public async Task <bool> MoveFile(SeafDirEntry dirEntry, SeafLibrary targetLibrary, string targetDirectory) { dirEntry.ThrowOnNull(nameof(dirEntry)); if (dirEntry.Type != DirEntryType.File) { throw new ArgumentException("The given directory entry is not a file."); } return(await MoveFile(dirEntry.LibraryId, dirEntry.Path, targetLibrary.Id, targetDirectory)); }
/// <summary> /// Checks if the given directory exists. /// </summary> /// <param name="session">The seafile session.</param> /// <param name="library">The library, which will searched for the directory.</param> /// <param name="path">The directory to check for existence.</param> public static async Task <bool> ExistsDirectory(this SeafSession session, SeafLibrary library, string path) { try { var dirs = await session.ListDirectory(library, path); return(dirs != null); } catch (Exception) { return(false); } }
/// <summary> /// Get a thumbnail for the given file /// </summary> /// <param name="library">The library the file is in</param> /// <param name="path">Path to the file</param> /// <param name="size">The size of the thumbnail (vertical and horizontal pixel count)</param> /// <returns></returns> public async Task <byte[]> GetThumbnailImage(SeafLibrary library, string path, int size) { library.ThrowOnNull(nameof(library)); return(await GetThumbnailImage(library.Id, path, size)); }
/// <summary> /// Get a download link for the given file /// </summary> /// <param name="library">The library the file is in</param> /// <param name="path">The path to the file</param> /// <returns>The download link which is valid once</returns> public async Task <string> GetFileDownloadLink(SeafLibrary library, string path) { library.ThrowOnNull(nameof(library)); return(await GetFileDownloadLink(library.Id, path)); }
/// <summary> /// Delete the given file in the given library /// </summary> /// <param name="library">The library the file is in</param> /// <param name="filePath">Path of the file</param> /// <returns>A value which indicates if the deletion was successful</returns> public async Task <bool> DeleteFile(SeafLibrary library, string filePath) { library.ThrowOnNull(nameof(library)); return(await DeleteFile(library.Id, filePath)); }
/// <summary> /// Uploads a single file /// Does not replace already existing files, instead the file will be renamed (e.g. test(1).txt if test.txt already exists) /// Use UpdateSingle to replace the contents of an already existing file /// </summary> /// <param name="library">The library the file should be uploaded to</param> /// <param name="targetDirectory">The directory the file should be uploaded to</param> /// <param name="targetFilename">The name of the file</param> /// <param name="fileContent">The new content of the file</param> /// <param name="progressCallback">Optional progress callback (will report percentage of upload)</param> public async Task <string> UploadSingle(SeafLibrary library, string targetDirectory, string targetFilename, Stream fileContent, CancellationToken cancelToken, Action <float> progressCallback = null) { library.ThrowOnNull(nameof(library)); return(await UploadSingle(library.Id, targetDirectory, targetFilename, fileContent, cancelToken, progressCallback)); }
/// <summary> /// Delete the given directory in the given library /// </summary> /// <param name="library">The library the directory is in</param> /// <param name="directoryPath">The path of the directory to delete</param> /// <returns>A value which indicates if the action was successful</returns> public async Task <bool> DeleteDirectory(SeafLibrary library, string directoryPath) { library.ThrowOnNull(nameof(library)); return(await DeleteDirectory(library.Id, directoryPath)); }
/// <summary> /// Create a new directory in the given library /// </summary> /// <param name="library">Library to create the directory in</param> /// <param name="path">Path of the directory to create</param> /// <returns>A value which indicates if the creation was successful</returns> public async Task <bool> CreateDirectory(SeafLibrary library, string path) { library.ThrowOnNull(nameof(library)); return(await CreateDirectory(library.Id, path)); }
/// <summary> /// Rename the given directory /// </summary> /// <param name="library">The library the directory is in</param> /// <param name="directoryPath">The current path of the directory</param> /// <param name="newName">The new name of the directory</param> /// <returns>A value which indicates if the action was successful</returns> public async Task <bool> RenameDirectory(SeafLibrary library, string directoryPath, string newName) { library.ThrowOnNull(nameof(library)); return(await RenameDirectory(library.Id, directoryPath, newName)); }
/// <summary> /// List the content of the given directory of the given library /// </summary> public async Task <IList <SeafDirEntry> > ListDirectory(SeafLibrary library, string directory) { library.ThrowOnNull(nameof(library)); return(await ListDirectory(library.Id, directory)); }
/// <summary> /// List the content of the root directory ("/") of the given linrary /// </summary> public async Task <IList <SeafDirEntry> > ListDirectory(SeafLibrary library) { return(await ListDirectory(library, "/")); }
/// <summary> /// Provide the password for the given encrypted library /// in order to be able to access its contents /// (listing directory contents does NOT require the library to be decrypted) /// </summary> public async Task <bool> DecryptLibrary(SeafLibrary library, char[] password) { var request = new DecryptLibraryRequest(AuthToken, library.Id, password); return(await _webConnection.SendRequestAsync(ServerUri, request)); }
/// <summary> /// Retrieve a link to upload files for the given library /// </summary> /// <param name="library">The library the file should be uploaded to</param> public async Task <string> GetUploadLink(SeafLibrary library) { library.ThrowOnNull(nameof(library)); return(await GetUploadLink(library.Id)); }
/// <summary> /// Retrieve information about the given file in the given library /// </summary> /// <param name="library">The library the file belongs to</param> /// <param name="filePath">Path to the file</param> /// <returns>The directory entry of the file</returns> public async Task <SeafDirEntry> GetFileDetail(SeafLibrary library, string filePath) { library.ThrowOnNull(nameof(library)); return(await GetFileDetail(library.Id, filePath)); }
/// <summary> /// Update the contents of the given, existing file /// </summary> /// <param name="library">The library the file is in</param> /// <param name="targetDirectory">The directory the file is in</param> /// <param name="targetFilename">The name of the file</param> /// <param name="fileContent">The new content of the file</param> /// <param name="progressCallback">Optional progress callback (will report percentage of upload)</param> public async Task <bool> UpdateSingle(SeafLibrary library, string targetDirectory, string targetFilename, Stream fileContent, Action <float> progressCallback = null) { library.ThrowOnNull(nameof(library)); return(await UpdateSingle(library.Id, targetDirectory, targetFilename, fileContent, progressCallback)); }
/// <summary> /// Rename the given file /// </summary> /// <param name="library">The library the file is in</param> /// <param name="filePath">The full path of the file</param> /// <param name="newName">The new name of the file</param> /// <returns>A value which indicates if the action was successful</returns> public async Task <bool> RenameFile(SeafLibrary library, string filePath, string newName) { library.ThrowOnNull(nameof(library)); return(await RenameFile(library.Id, filePath, newName)); }
/// <summary> /// Creates the directory in the given library. The directory structure with all parents will be created as well. /// If the directory already exists, no error will be thrown. /// </summary> /// <param name="session">The seafile session.</param> /// <param name="library">The library, where the directory should be created in.</param> /// <param name="path">The directory to create.</param> public static async Task CreateDirectoryWithParents(this SeafSession session, SeafLibrary library, string path) { var currentPath = path; for (int i = 0; i <= path.Count(n => n == '/'); i++) { if (await ExistsDirectory(session, library, currentPath)) { break; } if (currentPath.Contains('/')) { currentPath = currentPath.Substring(0, currentPath.LastIndexOf('/')); } else { currentPath = string.Empty; } } var dirsToCreate = path.Substring(currentPath.Length) .Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (dirsToCreate.Length > 0) { foreach (string dir in dirsToCreate) { currentPath = $"{currentPath}/{dir}"; await session.CreateDirectory(library, currentPath); } } }
/// <summary> /// Retrieve information about the given file in the given library /// </summary> /// <param name="library">The library the file belongs to</param> /// <param name="filePath">Path to the file</param> /// <returns>The directory entry of the file</returns> public async Task <SeafDirEntry> GetFileDetail(SeafLibrary library, string filePath, CancellationToken cancelToken) { library.ThrowOnNull(nameof(library)); return(await GetFileDetail(library.Id, filePath, cancelToken)); }