diff --git a/src/PCLStorage.Abstractions.NoSL/PCLStorage.Abstractions.NoSL.csproj b/src/PCLStorage.Abstractions.NoSL/PCLStorage.Abstractions.NoSL.csproj
index a03f940..147bf86 100644
--- a/src/PCLStorage.Abstractions.NoSL/PCLStorage.Abstractions.NoSL.csproj
+++ b/src/PCLStorage.Abstractions.NoSL/PCLStorage.Abstractions.NoSL.csproj
@@ -55,6 +55,9 @@
IFile.cs
+
+ IFileStats.cs
+
IFileSystem.cs
diff --git a/src/PCLStorage.Abstractions/IFile.cs b/src/PCLStorage.Abstractions/IFile.cs
index b706faf..ecd9aa9 100644
--- a/src/PCLStorage.Abstractions/IFile.cs
+++ b/src/PCLStorage.Abstractions/IFile.cs
@@ -73,5 +73,40 @@ public interface IFile
/// The cancellation token.
/// A task which will complete after the file is moved.
Task MoveAsync(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken));
+
+ ///
+ /// Gets the FileStats of this file
+ ///
+ /// The cancellation token.
+ /// A task which will return FileStats after completion.
+ Task GetFileStats(CancellationToken cancellationToken = default(CancellationToken));
+
+ ///
+ /// Writes creation time
+ ///
+ /// The time at which the file has been created
+ /// Set to true if you want to write utc time
+ /// The cancellation token.
+ /// A task which will complete after the creation time was written.
+ Task SetCreationTime(DateTime creationTime, bool utc = false, CancellationToken cancellationToken = default(CancellationToken));
+
+ ///
+ /// Writes last access time
+ ///
+ /// The time at which the file has been last accessed
+ /// Set to true if you want to write utc time
+ /// The cancellation token.
+ /// A task which will complete after the last access time was written.
+ Task SetLastAccessTime(DateTime lastAccessTime, bool utc = false, CancellationToken cancellationToken = default(CancellationToken));
+
+ ///
+ /// Writes last write time
+ ///
+ /// The time at which the file has been last written
+ /// Set to true if you want to write utc time
+ /// The cancellation token.
+ /// A task which will complete after the last write time was written.
+ Task SetLastWriteTime(DateTime lastWriteTime, bool utc = false, CancellationToken cancellationToken = default(CancellationToken));
+
}
}
diff --git a/src/PCLStorage.Abstractions/IFileStats.cs b/src/PCLStorage.Abstractions/IFileStats.cs
new file mode 100644
index 0000000..ae64867
--- /dev/null
+++ b/src/PCLStorage.Abstractions/IFileStats.cs
@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace PCLStorage
+{
+ ///
+ /// FileStats
+ ///
+ public interface IFileStats
+ {
+
+ ///
+ /// Name
+ ///
+ /// The name
+ string Name { get; }
+
+ ///
+ /// Extension
+ ///
+ /// The extension
+ string Extension { get; }
+
+ ///
+ /// Creation time.
+ ///
+ /// The creation time.
+ DateTime CreationTime { get; }
+
+ ///
+ /// Creation time UTC.
+ ///
+ /// The creation time UTC.
+ DateTime CreationTimeUTC { get; }
+
+ ///
+ /// Last access time.
+ ///
+ /// The last access time.
+ DateTime LastAccessTime { get;}
+
+ ///
+ /// Last access time UTC.
+ ///
+ /// The last access time UTC.
+ DateTime LastAccessTimeUTC { get; }
+
+ ///
+ /// Last write time.
+ ///
+ /// The last write time.
+ DateTime LastWriteTime { get; }
+
+ ///
+ /// Last write time UTC.
+ ///
+ /// The last write time UTC.
+ DateTime LastWriteTimeUTC { get; }
+
+
+
+ ///
+ /// Length of the data
+ ///
+ /// The length.
+ long Length { get; }
+
+ }
+}
diff --git a/src/PCLStorage.Abstractions/PCLStorage.Abstractions.csproj b/src/PCLStorage.Abstractions/PCLStorage.Abstractions.csproj
index a1e09ac..d12ebac 100644
--- a/src/PCLStorage.Abstractions/PCLStorage.Abstractions.csproj
+++ b/src/PCLStorage.Abstractions/PCLStorage.Abstractions.csproj
@@ -48,6 +48,7 @@
+
diff --git a/src/PCLStorage.Android/PCLStorage.Android.csproj b/src/PCLStorage.Android/PCLStorage.Android.csproj
index 126f521..ac539cc 100644
--- a/src/PCLStorage.Android/PCLStorage.Android.csproj
+++ b/src/PCLStorage.Android/PCLStorage.Android.csproj
@@ -52,6 +52,9 @@
FileSystemFile.cs
+
+ FileSystemFileStats.cs
+
FileSystemFolder.cs
diff --git a/src/PCLStorage.Android/Resources/Resource.Designer.cs b/src/PCLStorage.Android/Resources/Resource.Designer.cs
index 124c172..0124b82 100644
--- a/src/PCLStorage.Android/Resources/Resource.Designer.cs
+++ b/src/PCLStorage.Android/Resources/Resource.Designer.cs
@@ -1,11 +1,11 @@
#pragma warning disable 1591
//------------------------------------------------------------------------------
//
-// This code was generated by a tool.
-// Runtime Version:4.0.30319.34014
+// Dieser Code wurde von einem Tool generiert.
+// Laufzeitversion:4.0.30319.42000
//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
+// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
+// der Code erneut generiert wird.
//
//------------------------------------------------------------------------------
diff --git a/src/PCLStorage.FileSystem.Desktop/FileSystemFile.cs b/src/PCLStorage.FileSystem.Desktop/FileSystemFile.cs
index 720316e..34752d4 100644
--- a/src/PCLStorage.FileSystem.Desktop/FileSystemFile.cs
+++ b/src/PCLStorage.FileSystem.Desktop/FileSystemFile.cs
@@ -155,5 +155,50 @@ public async Task MoveAsync(string newPath, NameCollisionOption collisionOption,
return;
}
}
+
+ public async Task GetFileStats(CancellationToken cancellationToken = new CancellationToken())
+ {
+
+ await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);
+
+ return FileSystemFileStats.FromPath(Path);
+
+ }
+
+ public async Task SetCreationTime(DateTime creationTime, bool utc = false, CancellationToken cancellationToken = new CancellationToken())
+ {
+
+ await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);
+
+ if (utc)
+ File.SetCreationTimeUtc(Path, creationTime);
+ else
+ File.SetCreationTime(Path, creationTime);
+
+ }
+
+ public async Task SetLastAccessTime(DateTime lastAccessTime, bool utc = false, CancellationToken cancellationToken = new CancellationToken())
+ {
+
+ await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);
+
+ if (utc)
+ File.SetLastAccessTimeUtc(Path, lastAccessTime);
+ else
+ File.SetLastAccessTime(Path, lastAccessTime);
+
+ }
+
+ public async Task SetLastWriteTime(DateTime lastWriteTime, bool utc = false, CancellationToken cancellationToken = new CancellationToken())
+ {
+
+ await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);
+
+ if (utc)
+ File.SetLastWriteTimeUtc(Path, lastWriteTime);
+ else
+ File.SetLastWriteTime(Path, lastWriteTime);
+
+ }
}
}
diff --git a/src/PCLStorage.FileSystem.Desktop/FileSystemFileStats.cs b/src/PCLStorage.FileSystem.Desktop/FileSystemFileStats.cs
new file mode 100644
index 0000000..f7ca12e
--- /dev/null
+++ b/src/PCLStorage.FileSystem.Desktop/FileSystemFileStats.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PCLStorage
+{
+ class FileSystemFileStats : IFileStats
+ {
+ #region IFileStats Member
+
+ public string Name { get; internal set; }
+ public string Extension { get; internal set; }
+ public DateTime CreationTime { get; internal set; }
+ public DateTime CreationTimeUTC { get; internal set; }
+
+ public DateTime LastAccessTime { get; internal set; }
+ public DateTime LastAccessTimeUTC { get; internal set; }
+
+ public DateTime LastWriteTime { get; internal set; }
+ public DateTime LastWriteTimeUTC { get; internal set; }
+
+ public long Length { get; internal set; }
+
+ #endregion
+
+#if !WINDOWS_PHONE
+
+ internal static FileSystemFileStats FromPath(string path)
+ {
+
+
+
+ var fileInfo = new FileInfo(path);
+
+ var fileStats = new FileSystemFileStats()
+ {
+ Name = fileInfo.Name,
+ Extension = fileInfo.Extension,
+ CreationTime = fileInfo.CreationTime,
+ LastWriteTime = fileInfo.LastWriteTime,
+ LastAccessTime = fileInfo.LastAccessTime,
+ Length = fileInfo.Length
+ };
+
+#if !SILVERLIGHT
+ fileStats.CreationTimeUTC = fileInfo.CreationTimeUtc;
+ fileStats.LastWriteTimeUTC = fileInfo.LastWriteTimeUtc;
+ fileStats.LastAccessTimeUTC = fileInfo.LastAccessTimeUtc;
+#endif
+
+ return fileStats;
+
+
+
+ }
+#endif
+
+ }
+
+}
diff --git a/src/PCLStorage.FileSystem.Desktop/PCLStorage.FileSystem.Desktop.csproj b/src/PCLStorage.FileSystem.Desktop/PCLStorage.FileSystem.Desktop.csproj
index e5186db..2d141ab 100644
--- a/src/PCLStorage.FileSystem.Desktop/PCLStorage.FileSystem.Desktop.csproj
+++ b/src/PCLStorage.FileSystem.Desktop/PCLStorage.FileSystem.Desktop.csproj
@@ -73,6 +73,7 @@
+
diff --git a/src/PCLStorage.IsoStore.SL/IsoStoreFile.cs b/src/PCLStorage.IsoStore.SL/IsoStoreFile.cs
index 9b3d814..5ff4e69 100644
--- a/src/PCLStorage.IsoStore.SL/IsoStoreFile.cs
+++ b/src/PCLStorage.IsoStore.SL/IsoStoreFile.cs
@@ -95,6 +95,7 @@ public async Task OpenAsync(FileAccess fileAccess, CancellationToken can
try
{
+
IsolatedStorageFileStream stream = _root.OpenFile(Path, FileMode.Open, nativeFileAccess, FileShare.Read);
return stream;
}
@@ -234,5 +235,48 @@ public async Task MoveAsync(string newPath, NameCollisionOption collisionOption,
return;
}
}
+
+ public async Task GetFileStats(CancellationToken cancellationToken = new CancellationToken())
+ {
+
+ await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);
+
+ var localCreationTime = _root.GetCreationTime(_path);
+ var localLastWriteTime = _root.GetLastWriteTime(_path);
+ var localLastAccessTime = _root.GetLastAccessTime(_path);
+
+ var fileStats = new FileSystemFileStats()
+ {
+ Name = _name,
+ Extension = System.IO.Path.GetExtension(_name),
+ CreationTime = localCreationTime.DateTime,
+ CreationTimeUTC = localCreationTime.UtcDateTime,
+ LastWriteTime = localLastWriteTime.DateTime,
+ LastWriteTimeUTC = localLastWriteTime.UtcDateTime,
+ LastAccessTime = localLastAccessTime.DateTime,
+ LastAccessTimeUTC = localLastAccessTime.UtcDateTime
+ };
+
+ return fileStats;
+
+ }
+
+ public Task SetCreationTime(DateTime creationTime, bool utc = false,
+ CancellationToken cancellationToken = new CancellationToken())
+ {
+ throw new NotSupportedException();
+ }
+
+ public Task SetLastAccessTime(DateTime lastAccessTime, bool utc = false,
+ CancellationToken cancellationToken = new CancellationToken())
+ {
+ throw new NotSupportedException();
+ }
+
+ public Task SetLastWriteTime(DateTime lastWriteTime, bool utc = false,
+ CancellationToken cancellationToken = new CancellationToken())
+ {
+ throw new NotSupportedException();
+ }
}
}
diff --git a/src/PCLStorage.IsoStore.SL/PCLStorage.IsoStore.SL.csproj b/src/PCLStorage.IsoStore.SL/PCLStorage.IsoStore.SL.csproj
index b39cbaa..a89deab 100644
--- a/src/PCLStorage.IsoStore.SL/PCLStorage.IsoStore.SL.csproj
+++ b/src/PCLStorage.IsoStore.SL/PCLStorage.IsoStore.SL.csproj
@@ -97,6 +97,9 @@
Properties\CommonAssemblyInfo.cs
+
+ FileSystemFileStats.cs
+
AwaitExtensions.cs
diff --git a/src/PCLStorage.iOS-Unified/PCLStorage.iOS-Unified.csproj b/src/PCLStorage.iOS-Unified/PCLStorage.iOS-Unified.csproj
index c1f0f0f..b5a2ebd 100644
--- a/src/PCLStorage.iOS-Unified/PCLStorage.iOS-Unified.csproj
+++ b/src/PCLStorage.iOS-Unified/PCLStorage.iOS-Unified.csproj
@@ -53,6 +53,9 @@
FileSystemFile.cs
+
+ FileSystemFileStats.cs
+
FileSystemFolder.cs
diff --git a/src/PCLStorage.iOS/PCLStorage.iOS.csproj b/src/PCLStorage.iOS/PCLStorage.iOS.csproj
index 6c7c058..9d1f6f3 100644
--- a/src/PCLStorage.iOS/PCLStorage.iOS.csproj
+++ b/src/PCLStorage.iOS/PCLStorage.iOS.csproj
@@ -46,6 +46,9 @@
FileSystemFile.cs
+
+ FileSystemFileStats.cs
+
FileSystemFolder.cs
diff --git a/src/PCLStorage/FileSystem.cs b/src/PCLStorage/FileSystem.cs
index a724d21..486e553 100644
--- a/src/PCLStorage/FileSystem.cs
+++ b/src/PCLStorage/FileSystem.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
diff --git a/test/PCLStorage.Test.Android/PCLStorage.Test.Android.csproj b/test/PCLStorage.Test.Android/PCLStorage.Test.Android.csproj
index a4c09d6..8b15288 100644
--- a/test/PCLStorage.Test.Android/PCLStorage.Test.Android.csproj
+++ b/test/PCLStorage.Test.Android/PCLStorage.Test.Android.csproj
@@ -15,7 +15,7 @@
true
Resources\Resource.Designer.cs
Off
- v3.1
+ v4.0.3
Properties\AndroidManifest.xml
diff --git a/test/PCLStorage.Test.Android/Resources/Resource.Designer.cs b/test/PCLStorage.Test.Android/Resources/Resource.Designer.cs
index bbe8ac5..9c06823 100644
--- a/test/PCLStorage.Test.Android/Resources/Resource.Designer.cs
+++ b/test/PCLStorage.Test.Android/Resources/Resource.Designer.cs
@@ -1,11 +1,11 @@
#pragma warning disable 1591
//------------------------------------------------------------------------------
//
-// This code was generated by a tool.
-// Runtime Version:4.0.30319.34014
+// Dieser Code wurde von einem Tool generiert.
+// Laufzeitversion:4.0.30319.42000
//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
+// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
+// der Code erneut generiert wird.
//
//------------------------------------------------------------------------------
diff --git a/test/PCLStorage.Test/FileTests.cs b/test/PCLStorage.Test/FileTests.cs
index b462eba..25b8586 100644
--- a/test/PCLStorage.Test/FileTests.cs
+++ b/test/PCLStorage.Test/FileTests.cs
@@ -589,5 +589,52 @@ public async Task MoveFile_BadArgs()
// Cleanup
await file.DeleteAsync();
}
+
+ [TestMethod]
+ public async Task GetFileStats()
+ {
+
+ IFolder folder = TestFileSystem.LocalStorage;
+ string fileName = "readfilestats";
+ string fileExtension = ".txt";
+ IFile file = await folder.CreateFileAsync(fileName + fileExtension, CreationCollisionOption.ReplaceExisting);
+
+ var stats = await file.GetFileStats();
+
+ Assert.AreEqual(0, stats.Length);
+ Assert.AreEqual(fileName+fileExtension, stats.Name);
+ Assert.AreEqual(fileExtension, stats.Extension);
+
+ await file.DeleteAsync();
+
+ }
+
+ [TestMethod]
+ public async Task WriteFileStats()
+ {
+
+ IFolder folder = TestFileSystem.LocalStorage;
+ var dateTime = DateTime.Parse("1.1.2000");
+ string fileName = "redfilestats";
+ string fileExtension = ".txt";
+ IFile file = await folder.CreateFileAsync(fileName + fileExtension, CreationCollisionOption.ReplaceExisting);
+
+ await file.SetCreationTime(dateTime);
+ await file.SetLastWriteTime(dateTime);
+ await file.SetLastAccessTime(dateTime);
+
+ var stats = await file.GetFileStats();
+
+ Assert.AreEqual(0, stats.Length);
+ Assert.AreEqual(fileName + fileExtension, stats.Name);
+ Assert.AreEqual(fileExtension, stats.Extension);
+ Assert.AreEqual(dateTime, stats.CreationTime);
+ Assert.AreEqual(dateTime, stats.LastWriteTime);
+ Assert.AreEqual(dateTime, stats.LastAccessTime);
+
+ await file.DeleteAsync();
+
+ }
+
}
}