﻿namespace Muffin.Pictures.Archiver

open System

open Muffin.Pictures.Archiver.Domain
open Muffin.Pictures.Archiver.Rop

module Pictures =

    let toPicture timeTakenRetriever file =
        let timeTaken = timeTakenRetriever file
        match timeTaken with
        | Some t -> Success { File = file; TakenOn = t }
        | None -> Failure <| Skip.FileHasNoTimeTaken file

    let isOld timeProvider picture =
        // todo: replace this with single time at start of the program,
        // ie: not a function but a DT value
        let { File=_; TakenOn=takenOn } = picture
        let currentTime : DateTimeOffset = timeProvider ()
        if currentTime.AddMonths(-1) > takenOn then
            Success picture
        else
            Failure <| Skip.PictureWasNotOldEnough picture

    let getOldPictures timeTakenRetriever timeProvider filesProvider path =
        use wrapper = new BBCSharp.ExifToolWrapper("exiftool.exe")
        wrapper.Start()
        let tagProvider =
            (function path ->
                            wrapper.FetchExifFrom path
                            |> Seq.map (fun kvp -> (kvp.Key, kvp.Value)))

        let toOldPicture =
            toPicture (timeTakenRetriever tagProvider)
            >=> (isOld timeProvider)

        filesProvider path
        |> List.ofSeq
        |> List.map toOldPicture

﻿namespace Muffin.Pictures.Archiver

open System

open Muffin.Pictures.Archiver.Domain
open Muffin.Pictures.Archiver.Rop

module Pictures =

    let toPicture timeTakenRetriever file =
        let timeTaken = timeTakenRetriever file
        match timeTaken with
        | Some t -> Success { File = file; TakenOn = t }
        | None -> Failure <| Skip.FileHasNoTimeTaken file

    let isOld timeProvider picture =
        // todo: replace this with single time at start of the program,
        // ie: not a function but a DT value
        let { File=_; TakenOn=takenOn } = picture
        let currentTime : DateTimeOffset = timeProvider ()
        if currentTime.AddMonths(-1) > takenOn then
            Success picture
        else
            Failure <| Skip.PictureWasNotOldEnough picture

    let getOldPictures timeTakenRetriever timeProvider filesProvider path =
        let assembly = System.Reflection.Assembly.GetExecutingAssembly()
        let binLocation = System.IO.Path.GetDirectoryName(assembly.FullName)
        use wrapper = new BBCSharp.ExifToolWrapper(System.IO.Path.Combine(binLocation, "exiftool.exe"))
        wrapper.Start()
        let tagProvider =
            (function path ->
                            wrapper.FetchExifFrom path
                            |> Seq.map (fun kvp -> (kvp.Key, kvp.Value)))

        let toOldPicture =
            toPicture (timeTakenRetriever tagProvider)
            >=> (isOld timeProvider)

        filesProvider path
        |> List.ofSeq
        |> List.map toOldPicture

Use executingAssembly to define location of exiftools
Use executingAssembly to define location of exiftools
