154 lines
6.0 KiB
C#
154 lines
6.0 KiB
C#
![]() |
using BITKit;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace BITKit.IO
|
|||
|
{
|
|||
|
|
|||
|
public interface IStorageProvider
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Retrieves a file within the storage provider.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path">The relative path to the file within the storage provider.</param>
|
|||
|
/// <returns>The file.</returns>
|
|||
|
/// <exception cref="ArgumentException">If the file is not found.</exception>
|
|||
|
Task<IStorageFile> GetFile(string path);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Lists the files within a storage provider's path.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path">The relative path to the folder which files to list.</param>
|
|||
|
/// <returns>The list of files in the folder.</returns>
|
|||
|
Task<IEnumerable<IStorageFile>> ListFiles(string path);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Lists the folders within a storage provider's path.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path">The relative path to the folder which folders to list.</param>
|
|||
|
/// <returns>The list of folders in the folder.</returns>
|
|||
|
Task<IEnumerable<IStorageFolder>> ListFolders(string path);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Tries to create a folder in the storage provider.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path">The relative path to the folder to be created.</param>
|
|||
|
/// <returns>True if success; False otherwise.</returns>
|
|||
|
Task<bool> TryCreateFolder(string path);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Creates a folder in the storage provider.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path">The relative path to the folder to be created.</param>
|
|||
|
/// <exception cref="ArgumentException">If the folder already exists.</exception>
|
|||
|
void CreateFolder(string path);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Deletes a folder in the storage provider.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path">The relative path to the folder to be deleted.</param>
|
|||
|
/// <exception cref="ArgumentException">If the folder doesn't exist.</exception>
|
|||
|
void DeleteFolder(string path);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Renames a folder in the storage provider.
|
|||
|
/// </summary>
|
|||
|
/// <param name="oldPath">The relative path to the folder to be renamed.</param>
|
|||
|
/// <param name="newPath">The relative path to the new folder.</param>
|
|||
|
void RenameFolder(string oldPath, string newPath);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Deletes a file in the storage provider.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path">The relative path to the file to be deleted.</param>
|
|||
|
/// <exception cref="ArgumentException">If the file doesn't exist.</exception>
|
|||
|
void DeleteFile(string path);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Renames a file in the storage provider.
|
|||
|
/// </summary>
|
|||
|
/// <param name="oldPath">The relative path to the file to be renamed.</param>
|
|||
|
/// <param name="newPath">The relative path to the new file.</param>
|
|||
|
void RenameFile(string oldPath, string newPath);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Creates a file in the storage provider.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path">The relative path to the file to be created.</param>
|
|||
|
/// <exception cref="ArgumentException">If the file already exists.</exception>
|
|||
|
/// <returns>The created file.</returns>
|
|||
|
Task<IStorageFile> CreateFile(string path);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Tries to save a stream in the storage provider.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path">The relative path to the file to be created.</param>
|
|||
|
/// <param name="inputStream">The stream to be saved.</param>
|
|||
|
/// <returns>True if success; False otherwise.</returns>
|
|||
|
Task<bool> TrySaveStream(string path, Stream inputStream);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Saves a stream in the storage provider.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path">The relative path to the file to be created.</param>
|
|||
|
/// <param name="inputStream">The stream to be saved.</param>
|
|||
|
/// <exception cref="ArgumentException">If the stream can't be saved due to access permissions.</exception>
|
|||
|
void SaveStream(string path, Stream inputStream);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Combines to paths.
|
|||
|
/// </summary>
|
|||
|
/// <param name="path1">The parent path.</param>
|
|||
|
/// <param name="path2">The child path.</param>
|
|||
|
/// <returns>The combined path.</returns>
|
|||
|
Task<string> Combine(string path1, string path2);
|
|||
|
|
|||
|
Task<bool> FileExists(string path);
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gets or sets the default shared access expiration date.
|
|||
|
/// </summary>
|
|||
|
/// <value>
|
|||
|
/// The default shared access expiration date.
|
|||
|
/// </value>
|
|||
|
DateTimeOffset? DefaultSharedAccessExpiration { get; set; }
|
|||
|
}
|
|||
|
public abstract class StorageProvider : IStorageProvider
|
|||
|
{
|
|||
|
public DateTimeOffset? DefaultSharedAccessExpiration { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
|||
|
|
|||
|
public abstract Task<string> Combine(string path1, string path2);
|
|||
|
|
|||
|
public abstract Task<IStorageFile> CreateFile(string path);
|
|||
|
|
|||
|
public abstract void CreateFolder(string path);
|
|||
|
|
|||
|
public abstract void DeleteFile(string path);
|
|||
|
|
|||
|
public abstract void DeleteFolder(string path);
|
|||
|
|
|||
|
public abstract Task<bool> FileExists(string path);
|
|||
|
|
|||
|
public abstract Task<IStorageFile> GetFile(string path);
|
|||
|
|
|||
|
public abstract Task<IEnumerable<IStorageFile>> ListFiles(string path);
|
|||
|
|
|||
|
public abstract Task<IEnumerable<IStorageFolder>> ListFolders(string path);
|
|||
|
|
|||
|
public abstract void RenameFile(string oldPath, string newPath);
|
|||
|
|
|||
|
public abstract void RenameFolder(string oldPath, string newPath);
|
|||
|
|
|||
|
public abstract void SaveStream(string path, Stream inputStream);
|
|||
|
|
|||
|
public abstract Task<bool> TryCreateFolder(string path);
|
|||
|
|
|||
|
public abstract Task<bool> TrySaveStream(string path, Stream inputStream);
|
|||
|
}
|
|||
|
}
|