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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Misc;
using System.IO;
using Newtonsoft.Json;
using System.Threading.Tasks;
namespace Flyad7_WPF
{
public class DebugAppParam : INotifyPropertyChanged
{
public bool HasTimeGrid { get; set; }
public bool HasGrid { get; set; }
public bool HasGridAdv { get; set; }
public int FB_Pos1 { get; set; } = 1000;
public int FB_Pos2 { get; set; } = 3000;
public int PosLen { get; set; } = 8900;
public event PropertyChangedEventHandler PropertyChanged;
public DebugAppParam()
{
Load();
this.PropertyChanged += AutoSave;
}
private bool isIgnoreSave;
private async void AutoSave(object sender, PropertyChangedEventArgs e)
{
if (isIgnoreSave)
return;
//if (this.GetType().GetProperty(e.PropertyName).GetCustomAttributes(typeof(JsonPropertyAttribute), false).Count() > 0)
{
isIgnoreSave = true;
await Task.Delay(5000);//Task.Yield();
Save();
isIgnoreSave = false;
}
}
public void Save()
{
try
{
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText("param.json", json);
}
catch {
}
}
public void Load()
{
try
{
string json = File.ReadAllText("param.json");
isIgnoreSave = true;
JsonConvert.PopulateObject(json, this);
isIgnoreSave = false;
}
catch {
}
}
}
}