Winify – Diff between revs 56 and 67

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 56 Rev 67
Line 19... Line 19...
19 using Winify.Gotify; 19 using Winify.Gotify;
20 using Winify.Settings; 20 using Winify.Settings;
21 using Winify.Utilities; 21 using Winify.Utilities;
22 using Winify.Utilities.Serialization; 22 using Winify.Utilities.Serialization;
23 using ScheduledContinuation = Toasts.ScheduledContinuation; 23 using ScheduledContinuation = Toasts.ScheduledContinuation;
24 using Toasts = Toasts.Toasts; -  
Line 25... Line 24...
25   24  
26 namespace Winify 25 namespace Winify
27 { 26 {
28 public partial class MainForm : Form 27 public partial class MainForm : Form
Line 53... Line 52...
53   52  
Line 54... Line 53...
54 private LogViewForm _logViewForm; 53 private LogViewForm _logViewForm;
Line 55... Line 54...
55   54  
Line 56... Line 55...
56 private readonly LogMemorySink _memorySink; 55 private readonly LogMemorySink _memorySink;
Line 57... Line 56...
57   56  
Line 58... Line 57...
58 private readonly global::Toasts.Toasts _toasts; 57 private readonly Toasts.Toasts _toasts;
59   58  
-   59 #endregion
-   60  
60 #endregion 61 #region Constructors, Destructors and Finalizers
61   62  
Line 62... Line 63...
62 #region Constructors, Destructors and Finalizers 63 public MainForm()
Line 63... Line 64...
63   64 {
64 public MainForm() 65 InitializeComponent();
Line 65... Line 66...
65 { 66  
66 _cancellationTokenSource = new CancellationTokenSource(); 67 _cancellationTokenSource = new CancellationTokenSource();
67 _cancellationToken = _cancellationTokenSource.Token; -  
68   -  
69 ChangedConfigurationContinuation = new ScheduledContinuation(); 68 _cancellationToken = _cancellationTokenSource.Token;
70   69  
71 _toasts = new global::Toasts.Toasts(_cancellationToken); 70 ChangedConfigurationContinuation = new ScheduledContinuation();
72 } 71  
73   72 _toasts = new Toasts.Toasts(_cancellationToken);
Line 119... Line 118...
119 var servers = await LoadServers(); 118 var servers = await LoadServers();
120 _gotifyConnections = new ConcurrentBag<GotifyConnection>(); 119 _gotifyConnections = new ConcurrentBag<GotifyConnection>();
121 foreach (var server in servers.Server) 120 foreach (var server in servers.Server)
122 { 121 {
123 var gotifyConnection = new GotifyConnection(server, Configuration); 122 var gotifyConnection = new GotifyConnection(server, Configuration);
124 gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification; 123 gotifyConnection.GotifyMessage += GotifyConnectionGotifyMessage;
125 gotifyConnection.Start(); 124 gotifyConnection.Start();
126 _gotifyConnections.Add(gotifyConnection); 125 _gotifyConnections.Add(gotifyConnection);
127 } 126 }
128 } 127 }
Line 129... Line 128...
129   128  
130 private void LogViewToolStripMenuItem_Click(object sender, EventArgs e) 129 private void LogViewToolStripMenuItem_Click(object sender, EventArgs e)
131 { 130 {
-   131 if (_logViewForm != null)
-   132 {
-   133 return;
Line 132... Line 134...
132 if (_logViewForm != null) return; 134 }
133   135  
134 _logViewForm = new LogViewForm(this, _memorySink, _cancellationToken); 136 _logViewForm = new LogViewForm(this, _memorySink, _cancellationToken);
135 _logViewForm.Closing += LogViewForm_Closing; 137 _logViewForm.Closing += LogViewForm_Closing;
Line 136... Line 138...
136 _logViewForm.Show(); 138 _logViewForm.Show();
137 } 139 }
138   140  
-   141 private void LogViewForm_Closing(object sender, CancelEventArgs e)
-   142 {
-   143 if (_logViewForm == null)
Line 139... Line 144...
139 private void LogViewForm_Closing(object sender, CancelEventArgs e) 144 {
140 { 145 return;
141 if (_logViewForm == null) return; 146 }
142   147  
Line 170... Line 175...
170 await Task.WhenAll(SaveServers(e.Servers), SaveAnnouncements(e.Announcements)); 175 await Task.WhenAll(SaveServers(e.Servers), SaveAnnouncements(e.Announcements));
Line 171... Line 176...
171   176  
172 // Update connections to gotify servers. 177 // Update connections to gotify servers.
173 while (_gotifyConnections.TryTake(out var gotifyConnection)) 178 while (_gotifyConnections.TryTake(out var gotifyConnection))
174 { 179 {
175 gotifyConnection.GotifyNotification -= GotifyConnection_GotifyNotification; 180 gotifyConnection.GotifyMessage -= GotifyConnectionGotifyMessage;
176 gotifyConnection.Stop(); 181 await gotifyConnection.Stop();
177 gotifyConnection.Dispose(); -  
178 gotifyConnection = null; 182 gotifyConnection.Dispose();
Line 179... Line 183...
179 } 183 }
180   184  
181 foreach (var server in e.Servers.Server) 185 foreach (var server in e.Servers.Server)
182 { 186 {
183 var gotifyConnection = new GotifyConnection(server, Configuration); 187 var gotifyConnection = new GotifyConnection(server, Configuration);
184 gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification; 188 gotifyConnection.GotifyMessage += GotifyConnectionGotifyMessage;
185 gotifyConnection.Start(); 189 gotifyConnection.Start();
186 _gotifyConnections.Add(gotifyConnection); 190 _gotifyConnections.Add(gotifyConnection);
Line 187... Line 191...
187 } 191 }
188 } 192 }
189   193  
Line 190... Line 194...
190 private async void GotifyConnection_GotifyNotification(object sender, GotifyNotificationEventArgs e) 194 private async void GotifyConnectionGotifyMessage(object sender, GotifyMessageEventArgs e)
-   195 {
191 { 196 var announcements = await LoadAnnouncements();
192 var announcements = await LoadAnnouncements(); 197  
193   -  
194 foreach (var announcement in announcements.Announcement) -  
195 if (announcement.AppId == e.Notification.AppId) -  
196 { -  
197 var configuredNotification = new ToastForm( -  
198 $"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})", -  
199 e.Notification.Message, announcement.LingerTime, e.Image); 198 foreach (var announcement in announcements.Announcement)
200 199 {
Line -... Line 200...
-   200 if (announcement.AppId != e.Message.AppId)
-   201 {
-   202 continue;
-   203 }
-   204  
-   205 var configuredNotification = new ToastForm(
-   206 $"{e.Message.Title} ({e.Message.Server.Name}/{e.Message.AppId})",
-   207 e.Message.Message, announcement.LingerTime, e.Image);
-   208  
201 await _toasts.Queue(configuredNotification); 209 await _toasts.Queue(configuredNotification);
202   210  
203 return; 211 return;
204 } 212 }
205   213  
Line 206... Line 214...
206 if (Configuration.InfiniteToastDuration) 214 if (Configuration.InfiniteToastDuration)
Line 207... Line 215...
207 { 215 {
208 var infiniteToastForm = new ToastForm( 216 var infiniteToastForm = new ToastForm(
Line 209... Line 217...
209 $"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})", 217 $"{e.Message.Title} ({e.Message.Server.Name}/{e.Message.AppId})",
210 e.Notification.Message, e.Image); 218 e.Message.Message, e.Image);
211   219  
212 await _toasts.Queue(infiniteToastForm); 220 await _toasts.Queue(infiniteToastForm);
213   221  
214 return; 222 return;
Line 215... Line 223...
215 } 223 }
216   224  
217 var toastForm = new ToastForm( 225 var toastForm = new ToastForm(
-   226 $"{e.Message.Title} ({e.Message.Server.Name}/{e.Message.AppId})",
-   227 e.Message.Message, Configuration.ToastDuration, e.Image);
-   228  
Line 218... Line 229...
218 $"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})", 229 await _toasts.Queue(toastForm);
219 e.Notification.Message, Configuration.ToastDuration, e.Image); 230 }
220 231  
221 await _toasts.Queue(toastForm); 232 private void SettingsForm_Closing(object sender, CancelEventArgs e)
222 } 233 {
Line 223... Line 234...
223   234 if (_settingsForm == null)
224 private void SettingsForm_Closing(object sender, CancelEventArgs e) 235 {
225 { 236 return;
-   237 }
-   238  
-   239 _settingsForm.Save -= SettingsForm_Save;
Line 226... Line 240...
226 if (_settingsForm == null) return; 240 _settingsForm.Closing -= SettingsForm_Closing;
227   241 _settingsForm.Dispose();
228 _settingsForm.Save -= SettingsForm_Save; 242 _settingsForm = null;
229 _settingsForm.Closing -= SettingsForm_Closing; 243 }
Line 230... Line 244...
230 _settingsForm.Dispose(); 244  
231 _settingsForm = null; 245 private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
232 } 246 {
-   247 if (_aboutForm != null)
-   248 {
-   249 return;
Line 233... Line 250...
233   250 }
234 private void AboutToolStripMenuItem_Click(object sender, EventArgs e) 251  
235 { 252 _aboutForm = new AboutForm();
236 if (_aboutForm != null) return; 253 _aboutForm.Closing += AboutForm_Closing;