Winify – Diff between revs 3 and 4
?pathlinks?
Rev 3 | Rev 4 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | using System; |
1 | using System; |
|
2 | using System.ComponentModel; |
2 | using System.ComponentModel; |
|
3 | using System.Configuration; |
3 | using System.Configuration; |
|
- | 4 | using System.Diagnostics; |
||
- | 5 | using System.IO; |
||
- | 6 | using System.Threading.Tasks; |
||
4 | using System.Windows.Forms; |
7 | using System.Windows.Forms; |
|
5 | using AutoUpdaterDotNET; |
8 | using AutoUpdaterDotNET; |
|
- | 9 | using Winify.Connections; |
||
6 | using Winify.Gotify; |
10 | using Winify.Gotify; |
|
7 | using Winify.Properties; |
11 | using Winify.Properties; |
|
Line 8... | Line 12... | |||
8 | |
12 | |
|
9 | namespace Winify |
13 | namespace Winify |
|
10 | { |
14 | { |
|
11 | public partial class Form1 : Form |
15 | public partial class Form1 : Form |
|
12 | { |
16 | { |
|
Line 13... | Line 17... | |||
13 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
17 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
|
Line 14... | Line 18... | |||
14 | |
18 | |
|
Line 15... | Line 19... | |||
15 | private AboutForm _aboutForm; |
19 | private readonly GotifyConnectionManager _gotifyConnectionManager; |
|
Line 16... | Line 20... | |||
16 | |
20 | |
|
Line 17... | Line 21... | |||
17 | private GotifyConnection _gotifyConnection; |
21 | private AboutForm _aboutForm; |
|
Line 39... | Line 43... | |||
39 | // Bind to settings changed event. |
43 | // Bind to settings changed event. |
|
40 | Settings.Default.SettingsLoaded += Default_SettingsLoaded; |
44 | Settings.Default.SettingsLoaded += Default_SettingsLoaded; |
|
41 | Settings.Default.SettingsSaving += Default_SettingsSaving; |
45 | Settings.Default.SettingsSaving += Default_SettingsSaving; |
|
42 | Settings.Default.PropertyChanged += Default_PropertyChanged; |
46 | Settings.Default.PropertyChanged += Default_PropertyChanged; |
|
Line 43... | Line 47... | |||
43 | |
47 | |
|
Line 44... | Line 48... | |||
44 | Settings.Default.PropertyChanged += Default_PropertyChanged1; |
48 | _gotifyConnectionManager = new GotifyConnectionManager(); |
|
- | 49 | |
||
45 | |
50 | Task.Run(async () => |
|
- | 51 | { |
||
46 | _gotifyConnection = new GotifyConnection(); |
52 | _servers = await LoadServers(); |
|
47 | _gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification; |
53 | |
|
48 | _gotifyConnection.Start(Settings.Default.Username, Settings.Default.Password, Settings.Default.Host, |
54 | _gotifyConnectionManager.UpdateServers(_servers); |
|
Line 49... | Line 55... | |||
49 | Settings.Default.Port); |
55 | }); |
|
50 | } |
56 | } |
|
51 | |
57 | |
|
52 | /// <summary> |
58 | /// <summary> |
|
53 | /// Clean up any resources being used. |
59 | /// Clean up any resources being used. |
|
54 | /// </summary> |
60 | /// </summary> |
|
55 | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
61 | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
|
56 | protected override void Dispose(bool disposing) |
62 | protected override void Dispose(bool disposing) |
|
57 | { |
- | ||
58 | if (disposing && components != null) |
- | ||
59 | { |
63 | { |
|
60 | _gotifyConnection.GotifyNotification -= GotifyConnection_GotifyNotification; |
64 | if (disposing && components != null) |
|
Line 61... | Line 65... | |||
61 | |
65 | { |
|
62 | components.Dispose(); |
66 | components.Dispose(); |
|
Line 63... | Line 67... | |||
63 | } |
67 | } |
|
Line 64... | Line 68... | |||
64 | |
68 | |
|
Line 65... | Line -... | |||
65 | base.Dispose(disposing); |
- | ||
66 | } |
- | ||
67 | |
- | ||
68 | #endregion |
- | ||
69 | |
- | ||
70 | #region Event Handlers |
- | ||
71 | |
- | ||
72 | private void GotifyConnection_GotifyNotification(object sender, GotifyNotificationEventArgs e) |
- | ||
73 | { |
- | ||
74 | _notificationForm = new NotificationForm(e.Image, e.Notification.Title, e.Notification.Message, 5000); |
- | ||
75 | _notificationForm.Show(); |
- | ||
76 | } |
- | ||
77 | |
- | ||
78 | private void Default_PropertyChanged1(object sender, PropertyChangedEventArgs e) |
- | ||
79 | { |
- | ||
80 | if (_gotifyConnection != null) |
- | ||
81 | { |
- | ||
82 | _gotifyConnection.GotifyNotification -= GotifyConnection_GotifyNotification; |
- | ||
83 | _gotifyConnection.Stop(); |
- | ||
84 | _gotifyConnection.Dispose(); |
- | ||
85 | _gotifyConnection = null; |
- | ||
86 | } |
- | ||
87 | |
69 | base.Dispose(disposing); |
|
88 | _gotifyConnection = new GotifyConnection(); |
70 | } |
|
89 | _gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification; |
71 | |
|
90 | _gotifyConnection.Start(Settings.Default.Username, Settings.Default.Password, Settings.Default.Host, |
72 | #endregion |
|
Line 109... | Line 91... | |||
109 | if (_settingsForm != null) |
91 | if (_settingsForm != null) |
|
110 | { |
92 | { |
|
111 | return; |
93 | return; |
|
112 | } |
94 | } |
|
Line 113... | Line 95... | |||
113 | |
95 | |
|
114 | _settingsForm = new SettingsForm(); |
96 | _settingsForm = new SettingsForm(_servers); |
|
115 | _settingsForm.Closing += SettingsForm_Closing; |
97 | _settingsForm.Closing += SettingsForm_Closing; |
|
116 | ; |
98 | _settingsForm.ServersUpdated += SettingsForm_ServersUpdated; |
|
117 | _settingsForm.Show(); |
99 | _settingsForm.Show(); |
|
Line -... | Line 100... | |||
- | 100 | } |
||
- | 101 | |
||
- | 102 | private async void SettingsForm_ServersUpdated(object sender, ServersUpdatedEventArgs e) |
||
- | 103 | { |
||
- | 104 | _servers = e.Servers; |
||
- | 105 | |
||
- | 106 | switch (await ServersSerialization.Serialize(e.Servers, Constants.ServersFile)) |
||
- | 107 | { |
||
- | 108 | case SerializationSuccess _: |
||
- | 109 | _gotifyConnectionManager.UpdateServers(e.Servers); |
||
- | 110 | break; |
||
- | 111 | case SerializationFailure serializationFailure: |
||
- | 112 | Debug.WriteLine(serializationFailure.Exception.Message); |
||
- | 113 | break; |
||
- | 114 | } |
||
118 | } |
115 | } |
|
119 | |
116 | |
|
120 | private void SettingsForm_Closing(object sender, CancelEventArgs e) |
117 | private void SettingsForm_Closing(object sender, CancelEventArgs e) |
|
121 | { |
118 | { |
|
122 | if (_aboutForm == null) |
119 | if (_aboutForm == null) |
|
Line 157... | Line 154... | |||
157 | { |
154 | { |
|
158 | Application.Exit(); |
155 | Application.Exit(); |
|
159 | } |
156 | } |
|
Line 160... | Line 157... | |||
160 | |
157 | |
|
- | 158 | #endregion |
||
- | 159 | |
||
- | 160 | #region Private Methods |
||
- | 161 | |
||
- | 162 | private static async Task<Servers> LoadServers() |
||
- | 163 | { |
||
- | 164 | if (!Directory.Exists(Constants.UserApplicationDirectory)) |
||
- | 165 | { |
||
- | 166 | Directory.CreateDirectory(Constants.UserApplicationDirectory); |
||
- | 167 | } |
||
- | 168 | |
||
- | 169 | var deserializationResult = await ServersSerialization.Deserialize(Constants.ServersFile); |
||
- | 170 | |
||
- | 171 | switch (deserializationResult) |
||
- | 172 | { |
||
- | 173 | case SerializationSuccess serializationSuccess: |
||
- | 174 | return serializationSuccess.Servers; |
||
- | 175 | |
||
- | 176 | default: |
||
- | 177 | return new Servers(); |
||
- | 178 | } |
||
- | 179 | } |
||
- | 180 | |
||
161 | #endregion |
181 | #endregion |
|
162 | } |
182 | } |
|
163 | } |
183 | } |