Winify – Diff between revs 14 and 15
?pathlinks?
Rev 14 | Rev 15 | |||
---|---|---|---|---|
Line 2... | Line 2... | |||
2 | using System.Collections.Specialized; |
2 | using System.Collections.Specialized; |
|
3 | using System.ComponentModel; |
3 | using System.ComponentModel; |
|
4 | using System.Configuration; |
4 | using System.Configuration; |
|
5 | using System.Diagnostics; |
5 | using System.Diagnostics; |
|
6 | using System.IO; |
6 | using System.IO; |
|
- | 7 | using System.Text; |
||
7 | using System.Threading.Tasks; |
8 | using System.Threading.Tasks; |
|
8 | using System.Windows.Forms; |
9 | using System.Windows.Forms; |
|
9 | using AutoUpdaterDotNET; |
10 | using AutoUpdaterDotNET; |
|
- | 11 | using Servers; |
||
10 | using Winify.Gotify; |
12 | using Winify.Gotify; |
|
11 | using Winify.Properties; |
13 | using Winify.Properties; |
|
12 | using Winify.Servers.Serialization; |
14 | using Winify.Servers.Serialization; |
|
- | 15 | using Winify.Utilities; |
||
Line 13... | Line 16... | |||
13 | |
16 | |
|
14 | namespace Winify |
17 | namespace Winify |
|
15 | { |
18 | { |
|
16 | public partial class Form1 : Form |
19 | public partial class Form1 : Form |
|
17 | { |
20 | { |
|
Line -... | Line 21... | |||
- | 21 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
||
- | 22 | |
||
18 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
23 | private readonly Announcements.Announcements _notifications; |
|
Line 19... | Line 24... | |||
19 | |
24 | |
|
Line 20... | Line 25... | |||
20 | private readonly global::Servers.Servers _servers; |
25 | private readonly global::Servers.Servers _servers; |
|
Line 50... | Line 55... | |||
50 | Settings.Default.SettingsSaving += Default_SettingsSaving; |
55 | Settings.Default.SettingsSaving += Default_SettingsSaving; |
|
51 | Settings.Default.PropertyChanged += Default_PropertyChanged; |
56 | Settings.Default.PropertyChanged += Default_PropertyChanged; |
|
Line 52... | Line 57... | |||
52 | |
57 | |
|
53 | _servers = new global::Servers.Servers(); |
58 | _servers = new global::Servers.Servers(); |
|
- | 59 | _servers.Server.CollectionChanged += Server_CollectionChanged; |
||
- | 60 | _notifications = new Announcements.Announcements(); |
||
Line 54... | Line 61... | |||
54 | _servers.Server.CollectionChanged += Server_CollectionChanged; |
61 | _notifications.Announcement.CollectionChanged += Announcements_CollectionChanged; |
|
Line 55... | Line 62... | |||
55 | |
62 | |
|
Line 67... | Line 74... | |||
67 | foreach (var server in restoredServers.Server) |
74 | foreach (var server in restoredServers.Server) |
|
68 | { |
75 | { |
|
69 | _servers.Server.Add(server); |
76 | _servers.Server.Add(server); |
|
70 | } |
77 | } |
|
71 | }); |
78 | }); |
|
- | 79 | |
||
- | 80 | LoadAnnouncements().ContinueWith(async task => |
||
- | 81 | { |
||
- | 82 | var restoreAnnouncements = await task; |
||
- | 83 | |
||
- | 84 | foreach (var announcement in restoreAnnouncements.Announcement) |
||
- | 85 | { |
||
- | 86 | _notifications.Announcement.Add(announcement); |
||
- | 87 | } |
||
- | 88 | }); |
||
72 | } |
89 | } |
|
Line 73... | Line 90... | |||
73 | |
90 | |
|
74 | /// <summary> |
91 | /// <summary> |
|
75 | /// Clean up any resources being used. |
92 | /// Clean up any resources being used. |
|
Line 78... | Line 95... | |||
78 | protected override void Dispose(bool disposing) |
95 | protected override void Dispose(bool disposing) |
|
79 | { |
96 | { |
|
80 | if (disposing && components != null) |
97 | if (disposing && components != null) |
|
81 | { |
98 | { |
|
82 | _servers.Server.CollectionChanged -= Server_CollectionChanged; |
99 | _servers.Server.CollectionChanged -= Server_CollectionChanged; |
|
- | 100 | _notifications.Announcement.CollectionChanged -= Announcements_CollectionChanged; |
||
Line 83... | Line 101... | |||
83 | |
101 | |
|
84 | Settings.Default.SettingsLoaded -= Default_SettingsLoaded; |
102 | Settings.Default.SettingsLoaded -= Default_SettingsLoaded; |
|
85 | Settings.Default.SettingsSaving -= Default_SettingsSaving; |
103 | Settings.Default.SettingsSaving -= Default_SettingsSaving; |
|
Line 100... | Line 118... | |||
100 | |
118 | |
|
Line 101... | Line 119... | |||
101 | #endregion |
119 | #endregion |
|
Line -... | Line 120... | |||
- | 120 | |
||
- | 121 | #region Event Handlers |
||
- | 122 | |
||
- | 123 | private async void Announcements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
||
- | 124 | { |
||
- | 125 | switch (await ServersSerialization.Serialize(_notifications, Constants.NotificationsFile, "Announcements", |
||
- | 126 | "<!ATTLIST Announcements xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>")) |
||
- | 127 | { |
||
- | 128 | case SerializationFailure serializationFailure: |
||
- | 129 | Debug.WriteLine(serializationFailure.Exception.Message); |
||
- | 130 | break; |
||
102 | |
131 | } |
|
103 | #region Event Handlers |
132 | } |
|
104 | |
133 | |
|
105 | private void GotifyConnectionManager_GotifyNotification(object sender, GotifyNotificationEventArgs e) |
134 | private void GotifyConnectionManager_GotifyNotification(object sender, GotifyNotificationEventArgs e) |
|
Line 106... | Line 135... | |||
106 | { |
135 | { |
|
107 | _notificationManager.ShowNotification(e); |
136 | _notificationManager.ShowNotification(e, _notifications); |
|
- | 137 | } |
||
- | 138 | |
||
- | 139 | private async void Server_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
||
- | 140 | { |
||
- | 141 | // Encrypt password for all servers. |
||
- | 142 | var deviceId = Miscellaneous.GetMachineGuid(); |
||
- | 143 | var @protected = new global::Servers.Servers |
||
- | 144 | { |
||
- | 145 | Server = new BindingListWithCollectionChanged<Server>() |
||
- | 146 | }; |
||
- | 147 | foreach (var server in _servers.Server) |
||
- | 148 | { |
||
- | 149 | var encrypted = AES.Encrypt(Encoding.UTF8.GetBytes(server.Password), deviceId); |
||
- | 150 | var armored = Convert.ToBase64String(encrypted); |
||
108 | } |
151 | |
|
- | 152 | @protected.Server.Add(new Server(server.Name, server.Url, server.Username, armored)); |
||
109 | |
153 | } |
|
110 | private async void Server_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
154 | |
|
111 | { |
155 | switch (await ServersSerialization.Serialize(@protected, Constants.ServersFile, "Servers", |
|
112 | switch (await ServersSerialization.Serialize(_servers, Constants.ServersFile)) |
156 | "<!ATTLIST Servers xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>")) |
|
113 | { |
157 | { |
|
114 | case ServersSerializationFailure serializationFailure: |
158 | case SerializationFailure serializationFailure: |
|
Line 135... | Line 179... | |||
135 | if (_settingsForm != null) |
179 | if (_settingsForm != null) |
|
136 | { |
180 | { |
|
137 | return; |
181 | return; |
|
138 | } |
182 | } |
|
Line 139... | Line 183... | |||
139 | |
183 | |
|
140 | _settingsForm = new SettingsForm(_servers); |
184 | _settingsForm = new SettingsForm(_servers, _notifications); |
|
141 | _settingsForm.Closing += SettingsForm_Closing; |
185 | _settingsForm.Closing += SettingsForm_Closing; |
|
142 | _settingsForm.Show(); |
186 | _settingsForm.Show(); |
|
Line 143... | Line 187... | |||
143 | } |
187 | } |
|
Line 190... | Line 234... | |||
190 | |
234 | |
|
Line 191... | Line 235... | |||
191 | #endregion |
235 | #endregion |
|
Line -... | Line 236... | |||
- | 236 | |
||
- | 237 | #region Private Methods |
||
- | 238 | |
||
- | 239 | private static async Task<Announcements.Announcements> LoadAnnouncements() |
||
- | 240 | { |
||
- | 241 | if (!Directory.Exists(Constants.UserApplicationDirectory)) |
||
- | 242 | { |
||
- | 243 | Directory.CreateDirectory(Constants.UserApplicationDirectory); |
||
- | 244 | } |
||
- | 245 | |
||
- | 246 | var deserializationResult = |
||
- | 247 | await ServersSerialization.Deserialize<Announcements.Announcements>(Constants.NotificationsFile, |
||
- | 248 | "urn:winify-announcements-schema", "Announcements.xsd"); |
||
- | 249 | |
||
- | 250 | switch (deserializationResult) |
||
- | 251 | { |
||
- | 252 | case SerializationSuccess<Announcements.Announcements> serializationSuccess: |
||
- | 253 | return serializationSuccess.Result; |
||
- | 254 | default: |
||
- | 255 | return new Announcements.Announcements(); |
||
192 | |
256 | } |
|
193 | #region Private Methods |
257 | } |
|
194 | |
258 | |
|
195 | private static async Task<global::Servers.Servers> LoadServers() |
259 | private static async Task<global::Servers.Servers> LoadServers() |
|
196 | { |
260 | { |
|
197 | if (!Directory.Exists(Constants.UserApplicationDirectory)) |
261 | if (!Directory.Exists(Constants.UserApplicationDirectory)) |
|
Line -... | Line 262... | |||
- | 262 | { |
||
198 | { |
263 | Directory.CreateDirectory(Constants.UserApplicationDirectory); |
|
- | 264 | } |
||
Line 199... | Line 265... | |||
199 | Directory.CreateDirectory(Constants.UserApplicationDirectory); |
265 | |
|
200 | } |
266 | var deserializationResult = |
|
201 | |
267 | await ServersSerialization.Deserialize<global::Servers.Servers>(Constants.ServersFile, |
|
- | 268 | "urn:winify-servers-schema", "Servers.xsd"); |
||
- | 269 | |
||
- | 270 | switch (deserializationResult) |
||
- | 271 | { |
||
- | 272 | case SerializationSuccess<global::Servers.Servers> serializationSuccess: |
||
- | 273 | // Decrypt password. |
||
202 | var deserializationResult = await ServersSerialization.Deserialize(Constants.ServersFile); |
274 | var deviceId = Miscellaneous.GetMachineGuid(); |
|
- | 275 | var @protected = new global::Servers.Servers |
||
- | 276 | { |
||
- | 277 | Server = new BindingListWithCollectionChanged<Server>() |
||
- | 278 | }; |
||
- | 279 | foreach (var server in serializationSuccess.Result.Server) |
||
- | 280 | { |
||
- | 281 | var unarmored = Convert.FromBase64String(server.Password); |
||
- | 282 | var decrypted = Encoding.UTF8.GetString(AES.Decrypt(unarmored, deviceId)); |
||
Line 203... | Line 283... | |||
203 | |
283 | |
|
204 | switch (deserializationResult) |
284 | @protected.Server.Add(new Server(server.Name, server.Url, server.Username, decrypted)); |
|
205 | { |
285 | } |
|
206 | case ServersSerializationSuccess serializationSuccess: |
286 | |