-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorage.fs
44 lines (32 loc) · 1.08 KB
/
Storage.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
module FScribe.Storage
open System.IO
open Util
open Scribe
open Newtonsoft.Json
type ScribeStatus = Map<uint, GroupContext>
let loadStatus path : ScribeStatus =
logInfo "Loading records from %s." path
use file =
File.Open(path, FileMode.OpenOrCreate)
use reader = new StreamReader(file)
let wholeRecords =
reader.ReadToEnd()
|> JsonConvert.DeserializeObject<Map<uint, PlainScribeRecord list>>
|> Map.map (fun _ records ->
{ GroupContext.Default with Records = records |> List.map (fun t -> t :> IScribeRecord) })
logInfo
"Loaded %d records."
(wholeRecords.Values
|> Seq.sumBy (fun group -> List.length group.Records))
wholeRecords
let saveStatus path (records: ScribeStatus) =
use file = File.Open(path, FileMode.Create)
use writer = new StreamWriter(file)
records
|> Map.map (fun _ ctx -> ctx.Records)
|> JsonConvert.SerializeObject
|> writer.Write
logInfo
"Saved %d records."
(records.Values
|> Seq.sumBy (fun group -> List.length group.Records))