-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataStore.fs
executable file
·53 lines (43 loc) · 1.6 KB
/
DataStore.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
namespace WSP.DataStore
open System
open FSharp.Data
open System.IO
module Helpers =
let csvPath file =
let wd = Directory.GetCurrentDirectory()
let file = Path.Combine(wd, file)
file
module WorkingGroups =
type Provider = CsvProvider<"WspWorkingGroups.csv">
type WorkingGroup = Provider.Row
let getWorkingGroups () =
use csv = Helpers.csvPath "WspWorkingGroups.csv" |> Provider.Load
csv.Rows |> Seq.toList
module Roles =
type Provider = CsvProvider<"WspRoles.csv">
type Role = Provider.Row
let getRoles () =
use csv = Helpers.csvPath "WspRoles.csv" |> Provider.Load
csv.Rows |> Seq.toList
module Entries =
type Provider = CsvProvider<"WspResponsesTemplate.csv">
type Entry = Provider.Row
let addEntry entry =
let wd = Directory.GetCurrentDirectory()
let bkp = Path.Combine(wd, "Backup")
let file = Path.Combine(wd, "WspResponses.csv")
if Directory.Exists bkp |> not then
Directory.CreateDirectory(bkp) |> ignore
let contents =
use entries =
if File.Exists file |> not then
Provider.GetSample()
else
Provider.Load file
let entries' = entries.Append([entry])
entries'.SaveToString()
File.WriteAllText(file, contents)
let bkpFile =
Path.Combine(bkp,
sprintf "WspResponses_%s.csv" (DateTime.Now.ToString("yyyy-MM-dd_HH-mm")))
File.WriteAllText(bkpFile, contents)