using System; using System.IO.Abstractions; using API.Extensions; namespace API.Services; public interface IFileService { IFileSystem GetFileSystem(); bool HasFileBeenModifiedSince(string filePath, DateTime time); bool Exists(string filePath); } public class FileService : IFileService { private readonly IFileSystem _fileSystem; public FileService(IFileSystem fileSystem) { _fileSystem = fileSystem; } public FileService() : this(fileSystem: new FileSystem()) { } public IFileSystem GetFileSystem() { return _fileSystem; } /// /// If the File on disk's last modified time is after passed time /// /// This has a resolution to the minute. Will ignore seconds and milliseconds /// Full qualified path of file /// /// public bool HasFileBeenModifiedSince(string filePath, DateTime time) { return !string.IsNullOrEmpty(filePath) && _fileSystem.File.GetLastWriteTime(filePath).Truncate(TimeSpan.TicksPerMinute) > time.Truncate(TimeSpan.TicksPerMinute); } public bool Exists(string filePath) { return _fileSystem.File.Exists(filePath); } }