Skip to content

Commit 939e6d8

Browse files
committed
Added DateTime properties for folders too.
Formatting Removed default implementations links fro UWP Changed version to 1.3.2
1 parent 5cac345 commit 939e6d8

File tree

11 files changed

+148
-61
lines changed

11 files changed

+148
-61
lines changed

common/CommonAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
[assembly: AssemblyTrademark("")]
88
[assembly: AssemblyCulture("")]
99

10-
[assembly: AssemblyVersion("1.3.1.0")]
11-
[assembly: AssemblyFileVersion("1.3.1.0")]
10+
[assembly: AssemblyVersion("1.3.2.0")]
11+
[assembly: AssemblyFileVersion("1.3.2.0")]

src/PCLExt.FileStorage.NetFX/DefaultFolderImplementation.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ internal class DefaultFolderImplementation : IFolder
3232
public string Path { get; }
3333
/// <inheritdoc />
3434
public bool Exists => Directory.Exists(Path);
35+
/// <inheritdoc />
36+
public DateTime CreationTime => Directory.GetCreationTime(Path);
37+
/// <inheritdoc />
38+
public DateTime CreationTimeUTC => Directory.GetCreationTimeUtc(Path);
39+
/// <inheritdoc />
40+
public DateTime LastAccessTime => Directory.GetLastAccessTime(Path);
41+
/// <inheritdoc />
42+
public DateTime LastAccessTimeUTC => Directory.GetLastAccessTimeUtc(Path);
43+
/// <inheritdoc />
44+
public DateTime LastWriteTime => Directory.GetLastWriteTime(Path);
45+
/// <inheritdoc />
46+
public DateTime LastWriteTimeUTC => Directory.GetLastWriteTimeUtc(Path);
3547

3648
/// <summary>
3749
/// Creates a new <see cref="IFolder" /> corresponding to a specified path.

src/PCLExt.FileStorage.Portable111/Extensions/FileExtensions.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
using System.Collections.Generic;
1111
using System.IO;
12+
using System.Threading;
1213
using System.Threading.Tasks;
1314

1415
namespace PCLExt.FileStorage.Extensions
@@ -34,10 +35,11 @@ public static string ReadAllText(this IFile file)
3435
/// Reads the contents of a file as a string
3536
/// </summary>
3637
/// <param name="file">The file to read </param>
38+
/// <param name="cancellationToken">The cancellation token.</param>
3739
/// <returns>The contents of the file</returns>
38-
public static async Task<string> ReadAllTextAsync(this IFile file)
40+
public static async Task<string> ReadAllTextAsync(this IFile file, CancellationToken cancellationToken = default(CancellationToken))
3941
{
40-
using (var stream = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false))
42+
using (var stream = await file.OpenAsync(FileAccess.Read, cancellationToken).ConfigureAwait(false))
4143
using (var sr = new StreamReader(stream))
4244
return await sr.ReadToEndAsync().ConfigureAwait(false);
4345
}
@@ -63,10 +65,11 @@ public static void WriteAllText(this IFile file, string contents)
6365
/// </summary>
6466
/// <param name="file">The file to write to</param>
6567
/// <param name="contents">The content to write to the file</param>
68+
/// <param name="cancellationToken">The cancellation token.</param>
6669
/// <returns>A task which completes when the write operation finishes</returns>
67-
public static async Task WriteAllTextAsync(this IFile file, string contents)
70+
public static async Task WriteAllTextAsync(this IFile file, string contents, CancellationToken cancellationToken = default(CancellationToken))
6871
{
69-
using (var stream = await file.OpenAsync(FileAccess.ReadAndWrite).ConfigureAwait(false))
72+
using (var stream = await file.OpenAsync(FileAccess.ReadAndWrite, cancellationToken).ConfigureAwait(false))
7073
{
7174
stream.SetLength(0);
7275
using (var sw = new StreamWriter(stream))
@@ -96,10 +99,11 @@ public static string[] ReadAllLines(this IFile file)
9699
///
97100
/// </summary>
98101
/// <param name="file"></param>
102+
/// <param name="cancellationToken">The cancellation token.</param>
99103
/// <returns></returns>
100-
public static async Task<string[]> ReadAllLinesAsync(this IFile file)
104+
public static async Task<string[]> ReadAllLinesAsync(this IFile file, CancellationToken cancellationToken = default(CancellationToken))
101105
{
102-
using (var stream = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false))
106+
using (var stream = await file.OpenAsync(FileAccess.Read, cancellationToken).ConfigureAwait(false))
103107
using (var sr = new StreamReader(stream))
104108
{
105109
var lines = new List<string>();
@@ -130,9 +134,10 @@ public static void WriteAllLines(this IFile file, IEnumerable<string> lines)
130134
/// </summary>
131135
/// <param name="file"></param>
132136
/// <param name="lines"></param>
133-
public static async Task WriteAllLinesAsync(this IFile file, IEnumerable<string> lines)
137+
/// <param name="cancellationToken">The cancellation token.</param>
138+
public static async Task WriteAllLinesAsync(this IFile file, IEnumerable<string> lines, CancellationToken cancellationToken = default(CancellationToken))
134139
{
135-
using (var stream = await file.OpenAsync(FileAccess.ReadAndWrite).ConfigureAwait(false))
140+
using (var stream = await file.OpenAsync(FileAccess.ReadAndWrite, cancellationToken).ConfigureAwait(false))
136141
{
137142
stream.SetLength(0);
138143
using (var sw = new StreamWriter(stream))
@@ -162,10 +167,11 @@ public static void AppendText(this IFile file, string contents)
162167
/// </summary>
163168
/// <param name="file"></param>
164169
/// <param name="contents"></param>
170+
/// <param name="cancellationToken">The cancellation token.</param>
165171
/// <returns></returns>
166-
public static async Task AppendTextAsync(this IFile file, string contents)
172+
public static async Task AppendTextAsync(this IFile file, string contents, CancellationToken cancellationToken = default(CancellationToken))
167173
{
168-
using (var stream = await file.OpenAsync(FileAccess.ReadAndWrite).ConfigureAwait(false))
174+
using (var stream = await file.OpenAsync(FileAccess.ReadAndWrite, cancellationToken).ConfigureAwait(false))
169175
{
170176
stream.Seek(stream.Length, SeekOrigin.Begin);
171177
using (var sw = new StreamWriter(stream))
@@ -194,10 +200,11 @@ public static void AppendLines(this IFile file, IEnumerable<string> lines)
194200
/// </summary>
195201
/// <param name="file"></param>
196202
/// <param name="lines"></param>
203+
/// <param name="cancellationToken">The cancellation token.</param>
197204
/// <returns></returns>
198-
public static async Task AppendLinesAsync(this IFile file, IEnumerable<string> lines)
205+
public static async Task AppendLinesAsync(this IFile file, IEnumerable<string> lines, CancellationToken cancellationToken = default(CancellationToken))
199206
{
200-
using (var stream = await file.OpenAsync(FileAccess.ReadAndWrite).ConfigureAwait(false))
207+
using (var stream = await file.OpenAsync(FileAccess.ReadAndWrite, cancellationToken).ConfigureAwait(false))
201208
{
202209
stream.Seek(stream.Length, SeekOrigin.Begin);
203210
using (var sw = new StreamWriter(stream))

src/PCLExt.FileStorage.Portable111/Files/FileFromPath.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#if WINDOWS_UWP
2-
using PCLExt.FileStorage.UWP;
3-
#endif
4-
5-
namespace PCLExt.FileStorage.Files
1+
namespace PCLExt.FileStorage.Files
62
{
73
/// <summary>
84
/// Represents a folder created by a given path
@@ -24,7 +20,7 @@ private static IFile GetFileFromPath(string path)
2420
else
2521
throw new Exceptions.FileNotFoundException($"File does not exists on {path}");
2622
#elif WINDOWS_UWP
27-
var result = new StorageFileImplementation(path);
23+
var result = new UWP.StorageFileImplementation(path);
2824
if(!result.Exists)
2925
throw new Exceptions.FileNotFoundException($"File does not exists on {path}");
3026
return result;

src/PCLExt.FileStorage.Standard.Abstractions/BaseFolder.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Threading;
34
using System.Threading.Tasks;
45

@@ -15,6 +16,18 @@ public abstract class BaseFolder : IFolder
1516
public string Path => _folder.Path;
1617
/// <inheritdoc />
1718
public bool Exists => _folder != null;
19+
/// <inheritdoc />
20+
public DateTime CreationTime => _folder.CreationTime;
21+
/// <inheritdoc />
22+
public DateTime CreationTimeUTC => _folder.CreationTimeUTC;
23+
/// <inheritdoc />
24+
public DateTime LastAccessTime => _folder.LastAccessTime;
25+
/// <inheritdoc />
26+
public DateTime LastAccessTimeUTC => _folder.LastAccessTimeUTC;
27+
/// <inheritdoc />
28+
public DateTime LastWriteTime => _folder.LastWriteTime;
29+
/// <inheritdoc />
30+
public DateTime LastWriteTimeUTC => _folder.LastWriteTimeUTC;
1831

1932
/// <summary>
2033
/// Wraps an <see cref="IFolder"/>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace PCLExt.FileStorage
2+
{
3+
/// <summary>
4+
/// Specifies whether a file should be opened for write access or not
5+
/// </summary>
6+
public enum FileAccess
7+
{
8+
/// <summary>
9+
/// Specifies that a file should be opened for read-only access
10+
/// </summary>
11+
Read,
12+
/// <summary>
13+
/// Specifies that a file should be opened for read/write access
14+
/// </summary>
15+
ReadAndWrite
16+
}
17+
}

src/PCLExt.FileStorage.Standard.Abstractions/IFile.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@
1414

1515
namespace PCLExt.FileStorage
1616
{
17-
/// <summary>
18-
/// Specifies whether a file should be opened for write access or not
19-
/// </summary>
20-
public enum FileAccess
21-
{
22-
/// <summary>
23-
/// Specifies that a file should be opened for read-only access
24-
/// </summary>
25-
Read,
26-
/// <summary>
27-
/// Specifies that a file should be opened for read/write access
28-
/// </summary>
29-
ReadAndWrite
30-
}
31-
3217
/// <summary>
3318
/// Represents a file
3419
/// </summary>

src/PCLExt.FileStorage.Standard.Abstractions/IFolder.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// Which is released under the MS-PL license.
88
//-----------------------------------------------------------------------
99

10+
using System;
1011
using System.Collections.Generic;
1112
using System.Threading;
1213
using System.Threading.Tasks;
@@ -32,6 +33,42 @@ public interface IFolder
3233
/// </summary>
3334
bool Exists { get; }
3435

36+
/// <summary>
37+
/// Creation time.
38+
/// </summary>
39+
/// <value>The creation time.</value>
40+
DateTime CreationTime { get; }
41+
42+
/// <summary>
43+
/// Creation time UTC.
44+
/// </summary>
45+
/// <value>The creation time UTC.</value>
46+
DateTime CreationTimeUTC { get; }
47+
48+
/// <summary>
49+
/// Last access time.
50+
/// </summary>
51+
/// <value>The last access time.</value>
52+
DateTime LastAccessTime { get; }
53+
54+
/// <summary>
55+
/// Last access time UTC.
56+
/// </summary>
57+
/// <value>The last access time UTC.</value>
58+
DateTime LastAccessTimeUTC { get; }
59+
60+
/// <summary>
61+
/// Last write time.
62+
/// </summary>
63+
/// <value>The last write time.</value>
64+
DateTime LastWriteTime { get; }
65+
66+
/// <summary>
67+
/// Last write time UTC.
68+
/// </summary>
69+
/// <value>The last write time UTC.</value>
70+
DateTime LastWriteTimeUTC { get; }
71+
3572
/// <summary>
3673
/// Creates a file in this folder
3774
/// </summary>

src/PCLExt.FileStorage.UWP/PCLExt.FileStorage.UWP.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,6 @@
110110
<Compile Include="..\..\common\CommonAssemblyInfo.cs">
111111
<Link>Properties\CommonAssemblyInfo.cs</Link>
112112
</Compile>
113-
<Compile Include="..\PCLExt.FileStorage.NetFX\DefaultFileImplementation.cs">
114-
<Link>DefaultFileImplementation.cs</Link>
115-
</Compile>
116-
<Compile Include="..\PCLExt.FileStorage.NetFX\DefaultFolderImplementation.cs">
117-
<Link>DefaultFolderImplementation.cs</Link>
118-
</Compile>
119113
<Compile Include="..\pclext.filestorage.portable111\exceptions\ExceptionsHelper.cs">
120114
<Link>Exceptions\ExceptionsHelper.cs</Link>
121115
</Compile>

src/PCLExt.FileStorage.UWP/StorageFileImplementation.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
using PCLExt.FileStorage.Exceptions;
2-
using PCLExt.FileStorage.Extensions;
3-
using PCLExt.FileStorage.UWP.Extensions;
4-
using System;
1+
using System;
52
using System.IO;
6-
using System.Runtime.CompilerServices;
73
using System.Threading;
84
using System.Threading.Tasks;
5+
96
using Windows.Storage;
107
using Windows.Storage.FileProperties;
118

9+
using PCLExt.FileStorage.Exceptions;
10+
using PCLExt.FileStorage.Extensions;
11+
using PCLExt.FileStorage.UWP.Extensions;
12+
1213
namespace PCLExt.FileStorage.UWP
1314
{
1415
/// <inheritdoc />
@@ -35,7 +36,7 @@ public bool Exists
3536
}
3637
}
3738

38-
public long Size => (long)GetStorageFileProperties().Size;
39+
public long Size => (long) GetStorageFileProperties().Size;
3940

4041
public DateTime CreationTime =>
4142
_storageFile.DateCreated.ToLocalTime().DateTime;
@@ -166,12 +167,12 @@ await MoveAsync(
166167
var newFolder = await StorageFolder.GetFolderFromPathAsync(
167168
System.IO.Path.GetDirectoryName(newPath));
168169

169-
String newName;
170+
string newName;
170171
if (collisionOption == NameCollisionOption.GenerateUniqueName)
171172
{
172173
newName = $"{Guid.NewGuid()}";
173174
var extension = PortablePath.GetExtension(newPath);
174-
if (!String.IsNullOrEmpty(extension))
175+
if (!string.IsNullOrEmpty(extension))
175176
newName = newName + "." + extension;
176177
}
177178
else

0 commit comments

Comments
 (0)