Working on new method

This commit is contained in:
Holger Börchers 2019-12-16 21:18:54 +01:00
parent 9bf4b675e4
commit a17ea99642
2 changed files with 34 additions and 3 deletions

View File

@ -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<MediaFile> GetMediaFiles([NotNull] IEnumerable<string> files)
{
if (files == null) throw new ArgumentNullException(nameof(files));
foreach (var file in files)
{
var imageFile = ImageFile.FromFile(file);
var dateTime = imageFile.Properties.Get<ExifDateTime>(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;
}
}
}

View File

@ -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);
}
}
}
}