Winify – Diff between revs 20 and 21
?pathlinks?
Rev 20 | Rev 21 | |||
---|---|---|---|---|
Line 20... | Line 20... | |||
20 | { |
20 | { |
|
21 | public partial class Form1 : Form |
21 | public partial class Form1 : Form |
|
22 | { |
22 | { |
|
23 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
23 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
|
Line 24... | Line 24... | |||
24 | |
24 | |
|
Line 25... | Line 25... | |||
25 | private readonly Announcements.Announcements _notifications; |
25 | private readonly Announcements.Announcements _announcements; |
|
Line 26... | Line 26... | |||
26 | |
26 | |
|
Line 72... | Line 72... | |||
72 | Settings.Default.SettingsSaving += Default_SettingsSaving; |
72 | Settings.Default.SettingsSaving += Default_SettingsSaving; |
|
73 | Settings.Default.PropertyChanged += Default_PropertyChanged; |
73 | Settings.Default.PropertyChanged += Default_PropertyChanged; |
|
Line 74... | Line 74... | |||
74 | |
74 | |
|
75 | _servers = new global::Servers.Servers(); |
75 | _servers = new global::Servers.Servers(); |
|
- | 76 | _servers.Server.CollectionChanged += Server_CollectionChanged; |
||
76 | _servers.Server.CollectionChanged += Server_CollectionChanged; |
77 | _servers.Server.ListChanged += Server_ListChanged; |
|
77 | _notifications = new Announcements.Announcements(); |
78 | _announcements = new Announcements.Announcements(); |
|
- | 79 | _announcements.Announcement.CollectionChanged += Announcements_CollectionChanged; |
||
Line 78... | Line 80... | |||
78 | _notifications.Announcement.CollectionChanged += Announcements_CollectionChanged; |
80 | _announcements.Announcement.ListChanged += Announcement_ListChanged; |
|
Line 79... | Line 81... | |||
79 | |
81 | |
|
Line 98... | Line 100... | |||
98 | { |
100 | { |
|
99 | var restoreAnnouncements = await task; |
101 | var restoreAnnouncements = await task; |
|
Line 100... | Line 102... | |||
100 | |
102 | |
|
101 | foreach (var announcement in restoreAnnouncements.Announcement) |
103 | foreach (var announcement in restoreAnnouncements.Announcement) |
|
102 | { |
104 | { |
|
103 | _notifications.Announcement.Add(announcement); |
105 | _announcements.Announcement.Add(announcement); |
|
104 | } |
106 | } |
|
Line 105... | Line 107... | |||
105 | }); |
107 | }); |
|
106 | |
108 | |
|
Line 115... | Line 117... | |||
115 | protected override void Dispose(bool disposing) |
117 | protected override void Dispose(bool disposing) |
|
116 | { |
118 | { |
|
117 | if (disposing && components != null) |
119 | if (disposing && components != null) |
|
118 | { |
120 | { |
|
119 | _servers.Server.CollectionChanged -= Server_CollectionChanged; |
121 | _servers.Server.CollectionChanged -= Server_CollectionChanged; |
|
120 | _notifications.Announcement.CollectionChanged -= Announcements_CollectionChanged; |
122 | _announcements.Announcement.CollectionChanged -= Announcements_CollectionChanged; |
|
Line 121... | Line 123... | |||
121 | |
123 | |
|
122 | Settings.Default.SettingsLoaded -= Default_SettingsLoaded; |
124 | Settings.Default.SettingsLoaded -= Default_SettingsLoaded; |
|
123 | Settings.Default.SettingsSaving -= Default_SettingsSaving; |
125 | Settings.Default.SettingsSaving -= Default_SettingsSaving; |
|
Line 138... | Line 140... | |||
138 | |
140 | |
|
Line 139... | Line 141... | |||
139 | #endregion |
141 | #endregion |
|
Line -... | Line 142... | |||
- | 142 | |
||
- | 143 | #region Event Handlers |
||
- | 144 | |
||
- | 145 | private async void Announcement_ListChanged(object sender, ListChangedEventArgs e) |
||
- | 146 | { |
||
- | 147 | await SaveAnnouncements(); |
||
- | 148 | } |
||
- | 149 | |
||
- | 150 | private async void Server_ListChanged(object sender, ListChangedEventArgs e) |
||
- | 151 | { |
||
140 | |
152 | await SaveServers(); |
|
141 | #region Event Handlers |
153 | } |
|
142 | |
- | ||
143 | private async void Announcements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
- | ||
144 | { |
- | ||
145 | switch (await ServersSerialization.Serialize(_notifications, Constants.NotificationsFile, "Announcements", |
- | ||
146 | "<!ATTLIST Announcements xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>")) |
- | ||
147 | { |
154 | |
|
148 | case SerializationFailure serializationFailure: |
- | ||
149 | Log.Warning(serializationFailure.Exception, "Unable to serialize announcements."); |
155 | private async void Announcements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
|
Line 150... | Line 156... | |||
150 | break; |
156 | { |
|
151 | } |
157 | await SaveAnnouncements(); |
|
152 | } |
158 | } |
|
153 | |
159 | |
|
Line 154... | Line 160... | |||
154 | private void GotifyConnectionManager_GotifyNotification(object sender, GotifyNotificationEventArgs e) |
160 | private void GotifyConnectionManager_GotifyNotification(object sender, GotifyNotificationEventArgs e) |
|
155 | { |
161 | { |
|
156 | _notificationManager.ShowNotification(e, _notifications); |
- | ||
157 | } |
- | ||
158 | |
- | ||
159 | private async void Server_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
- | ||
160 | { |
- | ||
161 | // Encrypt password for all servers. |
- | ||
162 | var deviceId = Miscellaneous.GetMachineGuid(); |
- | ||
163 | var @protected = new global::Servers.Servers |
- | ||
164 | { |
- | ||
165 | Server = new BindingListWithCollectionChanged<Server>() |
- | ||
166 | }; |
- | ||
167 | foreach (var server in _servers.Server) |
- | ||
168 | { |
- | ||
169 | var encrypted = AES.Encrypt(Encoding.UTF8.GetBytes(server.Password), deviceId); |
- | ||
170 | var armored = Convert.ToBase64String(encrypted); |
- | ||
171 | |
- | ||
172 | @protected.Server.Add(new Server(server.Name, server.Url, server.Username, armored)); |
- | ||
173 | } |
- | ||
174 | |
- | ||
175 | switch (await ServersSerialization.Serialize(@protected, Constants.ServersFile, "Servers", |
162 | _notificationManager.ShowNotification(e, _announcements); |
|
176 | "<!ATTLIST Servers xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>")) |
- | ||
177 | { |
163 | } |
|
Line 178... | Line 164... | |||
178 | case SerializationFailure serializationFailure: |
164 | |
|
179 | Log.Warning(serializationFailure.Exception, "Unable to serialize servers."); |
165 | private async void Server_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
|
180 | break; |
166 | { |
|
Line 199... | Line 185... | |||
199 | if (_settingsForm != null) |
185 | if (_settingsForm != null) |
|
200 | { |
186 | { |
|
201 | return; |
187 | return; |
|
202 | } |
188 | } |
|
Line 203... | Line 189... | |||
203 | |
189 | |
|
204 | _settingsForm = new SettingsForm(_servers, _notifications); |
190 | _settingsForm = new SettingsForm(_servers, _announcements); |
|
205 | _settingsForm.Closing += SettingsForm_Closing; |
191 | _settingsForm.Closing += SettingsForm_Closing; |
|
206 | _settingsForm.Show(); |
192 | _settingsForm.Show(); |
|
Line 207... | Line 193... | |||
207 | } |
193 | } |
|
Line 256... | Line 242... | |||
256 | |
242 | |
|
Line 257... | Line 243... | |||
257 | #endregion |
243 | #endregion |
|
Line -... | Line 244... | |||
- | 244 | |
||
- | 245 | #region Private Methods |
||
- | 246 | |
||
- | 247 | private async Task SaveAnnouncements() |
||
- | 248 | { |
||
- | 249 | switch (await ServersSerialization.Serialize(_announcements, Constants.NotificationsFile, "Announcements", |
||
- | 250 | "<!ATTLIST Announcements xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>")) |
||
- | 251 | { |
||
- | 252 | case SerializationFailure serializationFailure: |
||
- | 253 | Log.Warning(serializationFailure.Exception, "Unable to serialize announcements."); |
||
- | 254 | break; |
||
- | 255 | } |
||
- | 256 | } |
||
- | 257 | |
||
- | 258 | private async Task SaveServers() |
||
- | 259 | { |
||
- | 260 | // Encrypt password for all servers. |
||
- | 261 | var deviceId = Miscellaneous.GetMachineGuid(); |
||
- | 262 | var @protected = new global::Servers.Servers |
||
- | 263 | { |
||
- | 264 | Server = new BindingListWithCollectionChanged<Server>() |
||
- | 265 | }; |
||
- | 266 | foreach (var server in _servers.Server) |
||
- | 267 | { |
||
- | 268 | var encrypted = AES.Encrypt(Encoding.UTF8.GetBytes(server.Password), deviceId); |
||
- | 269 | var armored = Convert.ToBase64String(encrypted); |
||
- | 270 | |
||
- | 271 | @protected.Server.Add(new Server(server.Name, server.Url, server.Username, armored)); |
||
- | 272 | } |
||
- | 273 | |
||
- | 274 | switch (await ServersSerialization.Serialize(@protected, Constants.ServersFile, "Servers", |
||
- | 275 | "<!ATTLIST Servers xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>")) |
||
- | 276 | { |
||
- | 277 | case SerializationFailure serializationFailure: |
||
- | 278 | Log.Warning(serializationFailure.Exception, "Unable to serialize servers."); |
||
- | 279 | break; |
||
258 | |
280 | } |
|
259 | #region Private Methods |
281 | } |
|
260 | |
282 | |
|
261 | private static async Task<Announcements.Announcements> LoadAnnouncements() |
283 | private static async Task<Announcements.Announcements> LoadAnnouncements() |
|
262 | { |
284 | { |
|
Line 271... | Line 293... | |||
271 | |
293 | |
|
272 | switch (deserializationResult) |
294 | switch (deserializationResult) |
|
273 | { |
295 | { |
|
274 | case SerializationSuccess<Announcements.Announcements> serializationSuccess: |
296 | case SerializationSuccess<Announcements.Announcements> serializationSuccess: |
|
- | 297 | return serializationSuccess.Result; |
||
- | 298 | case SerializationFailure serializationFailure: |
||
- | 299 | Log.Warning(serializationFailure.Exception, "Unable to load announcements."); |
||
275 | return serializationSuccess.Result; |
300 | return new Announcements.Announcements(); |
|
276 | default: |
301 | default: |
|
277 | return new Announcements.Announcements(); |
302 | return new Announcements.Announcements(); |
|
278 | } |
303 | } |
|
Line 306... | Line 331... | |||
306 | @protected.Server.Add(new Server(server.Name, server.Url, server.Username, decrypted)); |
331 | @protected.Server.Add(new Server(server.Name, server.Url, server.Username, decrypted)); |
|
307 | } |
332 | } |
|
Line 308... | Line 333... | |||
308 | |
333 | |
|
Line -... | Line 334... | |||
- | 334 | return @protected; |
||
- | 335 | |
||
- | 336 | case SerializationFailure serializationFailure: |
||
- | 337 | Log.Warning(serializationFailure.Exception, "Unable to load servers."); |
||
309 | return @protected; |
338 | return new global::Servers.Servers(); |
|
310 | |
339 | |
|
311 | default: |
340 | default: |
|
312 | return new global::Servers.Servers(); |
341 | return new global::Servers.Servers(); |