-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cs
109 lines (85 loc) · 3.03 KB
/
Config.cs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Threading.Tasks;
using Windows.Storage;
using Newtonsoft.Json;
namespace IPWatcher
{
internal class Config
{
#region Config items
/// <summary>
/// The name of the device the app runs on (preconfigured)
/// </summary>
public string DeviceName { get; set; }
/// <summary>
/// Period of checking external IP (preconfigured)
/// </summary>
public int UpdateHours { get; set; }
/// <summary>
/// The site to check external IP on (preconfigured)
/// </summary>
public string ExternalIPCheckAddress { get; set; }
/// <summary>
/// Recipient e-mail where the updates are sent (preconfigured)
/// </summary>
public string Recipient { get; set; }
/// <summary>
/// SMTP server address (preconfigured)
/// </summary>
public string SmtpServer { get; set; }
/// <summary>
/// Port number (preconfigured)
/// </summary>
public int Port { get; set; }
/// <summary>
/// Use SSL (preconfigured)
/// </summary>
public bool Ssl { get; set; }
/// <summary>
/// SMTP username (preconfigured)
/// </summary>
public string Username { get; set; }
/// <summary>
/// SMTP password (preconfigured)
/// </summary>
public string Password { get; set; }
/// <summary>
/// Subject of notification email (preconfigured)
/// </summary>
public string EmailSubject { get; set; }
/// <summary>
/// Formatted string of email body with DeviceName and IP placeholders (preconfigured)
/// e.g. "The IP address of {0} has changed to {1}"
/// </summary>
public string EmailBodyFormat { get; set; }
/// <summary>
/// Exponential backoff retry count
/// </summary>
public int RetryCount { get; set; }
/// <summary>
/// Exponential backoff base
/// e. g. if you set this to 2 and there is a connection exception, retry comes in
/// 2, 4, 8, ..., 2 ^ RetryCount seconds
/// </summary>
public int RetryBaseSeconds { get; set; }
/// <summary>
/// External ip of the device
/// </summary>
public string IpAddress { get; set; }
#endregion
public static Config Instance { get; private set; }
private const string fileName = "config.json";
private static StorageFile file;
public static async Task CreateInstance()
{
file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
var content = await FileIO.ReadTextAsync(file);
Instance = JsonConvert.DeserializeObject<Config>(content);
}
public static async Task SaveInstance()
{
var content = JsonConvert.SerializeObject(Instance, Formatting.Indented);
await FileIO.WriteTextAsync(file, content);
}
}
}