/
SettingsPage.cs
121 lines (96 loc) · 3.36 KB
/
SettingsPage.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
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows.Forms;
using SirenOfShame.Extruder.Models;
using SirenOfShame.Extruder.Services;
namespace SirenOfShame.Extruder
{
public partial class SettingsPage : UserControl
{
public ExtruderSettings Settings;
private readonly TripleDesStringEncryptor _encryptor;
public SettingsPage()
{
InitializeComponent();
_encryptor = new TripleDesStringEncryptor();
}
public event CloseSettingsEvent OnCloseSettings;
protected virtual void InvokeOnCloseSettings()
{
var handler = OnCloseSettings;
if (handler != null) handler(this, new CloseSettingsEventArgs());
}
public event ToggleConnectionEvent OnToggleConnection;
public event TestSirenEvent OnTestSiren;
protected virtual void InvokeOnTestSiren()
{
var handler = OnTestSiren;
if (handler != null) handler(this, new TestSirenEventArgs());
}
private void RetrieveSettings()
{
if (Settings == null) return;
_username.Text = Settings.UserName;
_password.Text = _encryptor.DecryptString(Settings.EncryptedPassword);
_myname.Text = Settings.MyName ?? Environment.MachineName;
}
private void Settings_Load(object sender, EventArgs e)
{
RetrieveSettings();
}
private async void Connect_Click(object sender, EventArgs e)
{
if (OnToggleConnection == null) return;
var toggleConnectionEventArgs = new ToggleConnectionEventArgs
{
UserName = _username.Text,
PlainTextPassword = _password.Text,
Name = _myname.Text,
};
await OnToggleConnection(this, toggleConnectionEventArgs);
}
public void RefreshIsConnected(bool connectedToServer)
{
_connectButton.Text = connectedToServer ? "Disconnect" : "Connect";
}
public void DeviceConnected(bool connected)
{
_testSiren.Enabled = connected;
}
public void UpdateNetworkStatus(bool? isBusy, string statusText)
{
if (isBusy.HasValue)
{
_connectButton.Enabled = !isBusy.Value;
}
}
private void TestSiren_Click(object sender, EventArgs e)
{
InvokeOnTestSiren();
}
private void _close_Click(object sender, EventArgs e)
{
InvokeOnCloseSettings();
}
private void CreateAccount_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("http://sirenofshame.com/Account/Register");
}
}
public delegate void CloseSettingsEvent(object sender, CloseSettingsEventArgs args);
public class CloseSettingsEventArgs
{
}
public delegate void TestSirenEvent(object sender, TestSirenEventArgs args);
public class TestSirenEventArgs
{
}
public delegate Task ToggleConnectionEvent(object sender, ToggleConnectionEventArgs args);
public class ToggleConnectionEventArgs
{
public string UserName { get; set; }
public string PlainTextPassword { get; set; }
public string Name { get; set; }
}
}