Skip to content

Commit

Permalink
Removed Storage.cs
Browse files Browse the repository at this point in the history
Aded non async operations, this isn't bad amrite?
  • Loading branch information
Aragas committed Mar 30, 2017
1 parent 9c0ccb5 commit 288a4b9
Show file tree
Hide file tree
Showing 14 changed files with 653 additions and 171 deletions.
6 changes: 2 additions & 4 deletions common/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System.Reflection;

//[assembly: AssemblyTitle("PCLExt.FileStorage")]
//[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PCLExt.FileStorage")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyVersion("1.0.9.0")]
[assembly: AssemblyFileVersion("1.0.9.0")]
2 changes: 1 addition & 1 deletion common/PCLExt.FileStorage.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>PCLExt.FileStorage</id>
<version>1.0.5</version>
<version>1.0.9</version>
<title>PCL Extension - File Storage API</title>
<authors>Daniel Plaisted,Aragas</authors>
<owners>Aragas</owners>
Expand Down
46 changes: 43 additions & 3 deletions src/PCLExt.FileStorage.Abstractions/IFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public interface IFile
/// </summary>
string Path { get; }

/// <summary>
/// Opens the file
/// </summary>
/// <param name="fileAccess">Specifies whether the file should be opened in read-only or read/write mode</param>
/// <returns>A <see cref="Stream"/> which can be used to read from or write to the file</returns>
Stream Open(FileAccess fileAccess);

/// <summary>
/// Opens the file
/// </summary>
Expand All @@ -50,6 +57,14 @@ public interface IFile
/// <returns>A <see cref="Stream"/> which can be used to read from or write to the file</returns>
Task<Stream> OpenAsync(FileAccess fileAccess, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Deletes the file
/// </summary>
/// <returns>
/// A task which will complete after the file is deleted.
/// </returns>
void Delete();

/// <summary>
/// Deletes the file
/// </summary>
Expand All @@ -64,12 +79,29 @@ public interface IFile
/// </summary>
/// <param name="newName">The new leaf name of the file.</param>
/// <param name="collisionOption">How to deal with collisions with existing files.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task which will complete after the file is renamed.
/// </returns>
void Rename(string newName, NameCollisionOption collisionOption = NameCollisionOption.FailIfExists);

/// <summary>
/// Renames a file without changing its location.
/// </summary>
/// <param name="newName">The new leaf name of the file.</param>
/// <param name="collisionOption">How to deal with collisions with existing files.</param>
/// <returns>
/// A task which will complete after the file is renamed.
/// </returns>
Task RenameAsync(string newName, NameCollisionOption collisionOption = NameCollisionOption.FailIfExists, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Moves a file.
/// </summary>
/// <param name="newPath">The new full path of the file.</param>
/// <param name="collisionOption">How to deal with collisions with existing files.</param>
/// <returns>A task which will complete after the file is moved.</returns>
void Move(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting);

/// <summary>
/// Moves a file.
/// </summary>
Expand All @@ -84,8 +116,16 @@ public interface IFile
/// </summary>
/// <param name="newPath">The new full path of the file.</param>
/// <param name="collisionOption">How to deal with collisions with existing files.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task which will complete after the file is moved.</returns>
Task CopyAsync(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken));
void Copy(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting);

/// <summary>
/// Copies a file.
/// </summary>
/// <param name="newPath">The new full path of the file.</param>
/// <param name="collisionOption">How to deal with collisions with existing files.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task which will complete after the file is moved.</returns>
Task CopyAsync(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken));
}
}
14 changes: 14 additions & 0 deletions src/PCLExt.FileStorage.Abstractions/IFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public interface IFileSystem
/// </summary>
IFolder RoamingStorage { get; }

/// <summary>
/// Gets a file, given its path. Returns null if the file does not exist.
/// </summary>
/// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
/// <returns>A file for the given path, or null if it does not exist.</returns>
IFile GetFileFromPath(string path);

/// <summary>
/// Gets a file, given its path. Returns null if the file does not exist.
/// </summary>
Expand All @@ -38,6 +45,13 @@ public interface IFileSystem
/// <returns>A file for the given path, or null if it does not exist.</returns>
Task<IFile> GetFileFromPathAsync(string path, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Gets a folder, given its path. Returns null if the folder does not exist.
/// </summary>
/// <param name="path">The path to a folder, as returned from the <see cref="IFolder.Path"/> property.</param>
/// <returns>A folder for the specified path, or null if it does not exist.</returns>
IFolder GetFolderFromPath(string path);

/// <summary>
/// Gets a folder, given its path. Returns null if the folder does not exist.
/// </summary>
Expand Down
72 changes: 72 additions & 0 deletions src/PCLExt.FileStorage.Abstractions/IFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public interface IFolder
/// </summary>
string Path { get; }

/// <summary>
/// Creates a file in this folder
/// </summary>
/// <param name="desiredName">The name of the file to create</param>
/// <param name="option">Specifies how to behave if the specified file already exists</param>
/// <returns>The newly created file</returns>
IFile CreateFile(string desiredName, CreationCollisionOption option);

/// <summary>
/// Creates a file in this folder
/// </summary>
Expand All @@ -59,6 +67,13 @@ public interface IFolder
/// <returns>The newly created file</returns>
Task<IFile> CreateFileAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Gets a file in this folder
/// </summary>
/// <param name="name">The name of the file to get</param>
/// <returns>The requested file, or null if it does not exist</returns>
IFile GetFile(string name);

/// <summary>
/// Gets a file in this folder
/// </summary>
Expand All @@ -67,13 +82,27 @@ public interface IFolder
/// <returns>The requested file, or null if it does not exist</returns>
Task<IFile> GetFileAsync(string name, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Gets a list of the files in this folder
/// </summary>
/// <returns>A list of the files in the folder</returns>
IList<IFile> GetFiles();

/// <summary>
/// Gets a list of the files in this folder
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A list of the files in the folder</returns>
Task<IList<IFile>> GetFilesAsync(CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Creates a subfolder in this folder
/// </summary>
/// <param name="desiredName">The name of the folder to create</param>
/// <param name="option">Specifies how to behave if the specified folder already exists</param>
/// <returns>The newly created folder</returns>
IFolder CreateFolder(string desiredName, CreationCollisionOption option);

/// <summary>
/// Creates a subfolder in this folder
/// </summary>
Expand All @@ -83,6 +112,13 @@ public interface IFolder
/// <returns>The newly created folder</returns>
Task<IFolder> CreateFolderAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Gets a subfolder in this folder
/// </summary>
/// <param name="name">The name of the folder to get</param>
/// <returns>The requested folder, or null if it does not exist</returns>
IFolder GetFolder(string name);

/// <summary>
/// Gets a subfolder in this folder
/// </summary>
Expand All @@ -91,13 +127,26 @@ public interface IFolder
/// <returns>The requested folder, or null if it does not exist</returns>
Task<IFolder> GetFolderAsync(string name, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Gets a list of subfolders in this folder
/// </summary>
/// <returns>A list of subfolders in the folder</returns>
IList<IFolder> GetFolders();

/// <summary>
/// Gets a list of subfolders in this folder
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A list of subfolders in the folder</returns>
Task<IList<IFolder>> GetFoldersAsync(CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Checks whether a folder or file exists at the given location.
/// </summary>
/// <param name="name">The name of the file or folder to check for.</param>
/// <returns>A task whose result is the result of the existence check.</returns>
ExistenceCheckResult CheckExists(string name);

/// <summary>
/// Checks whether a folder or file exists at the given location.
/// </summary>
Expand All @@ -106,11 +155,34 @@ public interface IFolder
/// <returns>A task whose result is the result of the existence check.</returns>
Task<ExistenceCheckResult> CheckExistsAsync(string name, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Deletes this folder and all of its contents
/// </summary>
/// <returns>A task which will complete after the folder is deleted</returns>
void Delete();

/// <summary>
/// Deletes this folder and all of its contents
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task which will complete after the folder is deleted</returns>
Task DeleteAsync(CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Moves this folder and all of its contents to the given folder, current folder will be deleted.
/// </summary>
/// <param name="folder">The folder in which content will be moved</param>
/// <param name="option">Specifies how to behave if the specified folder/file already exists</param>
/// <returns>The folder with moved content.</returns>
IFolder Move(IFolder folder, NameCollisionOption option = NameCollisionOption.ReplaceExisting);

/// <summary>
/// Moves this folder and all of its contents to the given folder, current folder will be deleted.
/// </summary>
/// <param name="folder">The folder in which content will be moved</param>
/// <param name="option">Specifies how to behave if the specified folder/file already exists</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The folder with moved content.</returns>
Task<IFolder> MoveAsync(IFolder folder, NameCollisionOption option = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
<Compile Include="$(SolutionDir)\src\PCLExt.FileStorage\Requires.cs">
<Link>Requires.cs</Link>
</Compile>
<Compile Include="$(SolutionDir)\src\PCLExt.FileStorage\Storage.cs">
<Link>Storage.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="$(SolutionDir)\src\PCLExt.FileStorage\FileSystem.cs">
<Link>FileSystem.cs</Link>
Expand Down
74 changes: 52 additions & 22 deletions src/PCLExt.FileStorage.Desktop/DesktopFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,28 @@ public IFolder RoamingStorage
}
}

/// <summary>
/// Gets a file, given its path. Returns null if the file does not exist.
/// </summary>
/// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A file for the given path, or null if it does not exist.</returns>
public async Task<IFile> GetFileFromPathAsync(string path, CancellationToken cancellationToken)
/// <summary>
/// Gets a file, given its path. Returns null if the file does not exist.
/// </summary>
/// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
/// <returns>A file for the given path, or null if it does not exist.</returns>
public IFile GetFileFromPath(string path)
{
Requires.NotNullOrEmpty(path, "path");

if (System.IO.File.Exists(path))
return new FileSystemFile(path);

return null;
}

/// <summary>
/// Gets a file, given its path. Returns null if the file does not exist.
/// </summary>
/// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A file for the given path, or null if it does not exist.</returns>
public async Task<IFile> GetFileFromPathAsync(string path, CancellationToken cancellationToken)
{
Requires.NotNullOrEmpty(path, "path");

Expand All @@ -110,21 +125,36 @@ public async Task<IFile> GetFileFromPathAsync(string path, CancellationToken can
return null;
}

/// <summary>
/// Gets a folder, given its path. Returns null if the folder does not exist.
/// </summary>
/// <param name="path">The path to a folder, as returned from the <see cref="IFolder.Path"/> property.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A folder for the specified path, or null if it does not exist.</returns>
public async Task<IFolder> GetFolderFromPathAsync(string path, CancellationToken cancellationToken)
{
Requires.NotNullOrEmpty(path, "path");
/// <summary>
/// Gets a folder, given its path. Returns null if the folder does not exist.
/// </summary>
/// <param name="path">The path to a folder, as returned from the <see cref="IFolder.Path"/> property.</param>
/// <returns>A folder for the specified path, or null if it does not exist.</returns>
public IFolder GetFolderFromPath(string path)
{
Requires.NotNullOrEmpty(path, "path");

await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);
if (System.IO.Directory.Exists(path))
return new FileSystemFolder(path, true);
if (System.IO.Directory.Exists(path))
return new FileSystemFolder(path, true);

return null;
}
}
return null;
}

/// <summary>
/// Gets a folder, given its path. Returns null if the folder does not exist.
/// </summary>
/// <param name="path">The path to a folder, as returned from the <see cref="IFolder.Path"/> property.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A folder for the specified path, or null if it does not exist.</returns>
public async Task<IFolder> GetFolderFromPathAsync(string path, CancellationToken cancellationToken)
{
Requires.NotNullOrEmpty(path, "path");

await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);
if (System.IO.Directory.Exists(path))
return new FileSystemFolder(path, true);

return null;
}
}
}
Loading

0 comments on commit 288a4b9

Please sign in to comment.