-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.fs
88 lines (68 loc) · 3.06 KB
/
View.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
module View
open LiteDB
open WunderlistBackup
open Serialization
open MaybeBuilder
open System
type DiskFile =
IO.File
type Path =
IO.Path
type TaskItem =
Subtask of Subtask | Note of Note | File of File
type TaskItemDisplayable =
TaskItem * string
let pickDisplay() =
use db = new LiteDatabase("wunderlist.db")
let allBackUps =
db.GetCollection("BackUp")
.FindAll() |>
Seq.map toBackUp |>
Seq.toList
maybe {
let! backup = CommandLine.pick allBackUps (fun b -> b.timestamp)
let folders = None :: (backup.folders |> List.map Some)
let! folder = CommandLine.pick folders (fun f -> match f with
| Some f -> f.Title
| None -> "No folder")
let folderLists =
backup.lists |> List.filter (fun list -> match folder with
| Some folder -> folder.ListIds |>
Array.contains list.Id
| None -> backup.folders |>
Seq.collect (fun f -> f.ListIds) |>
Seq.contains list.Id |>
not)
let! list = CommandLine.pick folderLists (fun l -> l.Title)
let listTasks =
backup.tasks |> List.filter (fun task -> task.ListId = list.Id)
let! task = CommandLine.pick listTasks (fun t -> t.Title)
let subtasks =
backup.subtasks |>
List.filter (fun subtask -> subtask.TaskId = task.Id) |>
List.map Subtask
let notes =
backup.notes |>
List.filter (fun note -> note.TaskId = task.Id) |>
List.map Note
let files =
backup.files |>
List.filter (fun file -> file.TaskId = task.Id) |>
List.map File
let items =
[ subtasks; files; notes ] |> List.concat
let! item =
CommandLine.pick items (fun i -> match i with
| Subtask s -> sprintf "Subtask: %s" s.Title
| Note n -> sprintf "Note: %s" n.Content
| File f -> sprintf "File: %s" f.FileName)
return match item with
| File f -> let tempPath = sprintf "%s.%s" (Path.GetTempFileName()) f.FileName
let fileStream = DiskFile.OpenWrite(tempPath)
db.FileStorage.Download(f.Id.ToString(), fileStream) |> ignore
fileStream.Flush()
fileStream.Dispose()
//Diagnostics.Process.Start(tempPath) |> ignore
Console.WriteLine tempPath
| _ -> ignore()
}