diff --git a/PhotoRenamer.Base/FilesHelper.cs b/PhotoRenamer.Base/FilesHelper.cs index 1f8c161..5aba6ea 100644 --- a/PhotoRenamer.Base/FilesHelper.cs +++ b/PhotoRenamer.Base/FilesHelper.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; +using ExifLibrary; +using JetBrains.Annotations; namespace PhotoRenamer.Base { @@ -22,5 +25,31 @@ namespace PhotoRenamer.Base } } } + + public static IEnumerable GetMediaFiles([NotNull] IEnumerable files) + { + if (files == null) throw new ArgumentNullException(nameof(files)); + + foreach (var file in files) + { + var imageFile = ImageFile.FromFile(file); + var dateTime = imageFile.Properties.Get(ExifTag.DateTimeOriginal); + var mediaFile = new MediaFile(file, dateTime.Value); + yield return mediaFile; + } + } + } + + + public class MediaFile + { + public string Path { get; } + public DateTime CreationDate { get; } + + public MediaFile(string path, DateTime creationDate) + { + Path = path; + CreationDate = creationDate; + } } } diff --git a/PhotoRenamer.Test/FilesTest.cs b/PhotoRenamer.Test/FilesTest.cs index 22d35df..9bb76aa 100644 --- a/PhotoRenamer.Test/FilesTest.cs +++ b/PhotoRenamer.Test/FilesTest.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; +using PhotoRenamer.Base; namespace PhotoRenamer.Test { @@ -13,7 +14,7 @@ namespace PhotoRenamer.Test public FilesTest() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets"); - _files = Base.FilesHelper.FindSupportedFilesRecursively(path).ToArray(); + _files = FilesHelper.FindSupportedFilesRecursively(path).ToArray(); } [TestMethod, Priority(0)] @@ -27,7 +28,8 @@ namespace PhotoRenamer.Test [TestMethod, Priority(1)] public void GetMetaData() { - + var expected = new[] {new MediaFile("r", DateTime.Now), new MediaFile("r", DateTime.Now)}; + var actual = FilesHelper.GetMediaFiles(_files); } } -} +} \ No newline at end of file