Winify – Diff between revs 50 and 51

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 50 Rev 51
Line 87... Line 87...
87 Convert.ToBase64String(Encoding.Default.GetBytes($"{_server.Username}:{_server.Password}"))); 87 Convert.ToBase64String(Encoding.Default.GetBytes($"{_server.Username}:{_server.Password}")));
88 } 88 }
Line 89... Line 89...
89   89  
90 if (!Uri.TryCreate(_server.Url, UriKind.Absolute, out _httpUri)) 90 if (!Uri.TryCreate(_server.Url, UriKind.Absolute, out _httpUri))
91 { 91 {
92 Log.Error($"No HTTP URL could be built out of the supplied server URI {_server.Url}."); 92 Log.Error($"No HTTP URL could be built out of the supplied server URI {_server.Url}");
93 return; 93 return;
Line 94... Line 94...
94 } 94 }
95   95  
Line 109... Line 109...
109 { 109 {
110 webSocketsUriBuilder.Path = Path.Combine(webSocketsUriBuilder.Path, "stream"); 110 webSocketsUriBuilder.Path = Path.Combine(webSocketsUriBuilder.Path, "stream");
111 } 111 }
112 catch (ArgumentException exception) 112 catch (ArgumentException exception)
113 { 113 {
114 Log.Error($"No WebSockets URL could be built from the provided URL {_server.Url} due to {exception.Message}."); 114 Log.Error($"No WebSockets URL could be built from the provided URL {_server.Url} due to {exception.Message}");
115 } 115 }
Line 116... Line 116...
116   116  
117 _webSocketsUri = webSocketsUriBuilder.Uri; 117 _webSocketsUri = webSocketsUriBuilder.Uri;
Line 144... Line 144...
144   144  
145 public void Start() 145 public void Start()
146 { 146 {
147 if (_webSocketsUri == null || _httpUri == null) 147 if (_webSocketsUri == null || _httpUri == null)
148 { 148 {
149 Log.Error("Could not start connection to server due to unreadable URLs."); 149 Log.Error("Could not start connection to server due to unreadable URLs");
150 return; 150 return;
Line 151... Line 151...
151 } 151 }
152   152  
Line 177... Line 177...
177 { 177 {
178 _webSocketSharp.SslConfiguration.ServerCertificateValidationCallback += 178 _webSocketSharp.SslConfiguration.ServerCertificateValidationCallback +=
179 (sender, certificate, chain, errors) => true; 179 (sender, certificate, chain, errors) => true;
180 } 180 }
Line -... Line 181...
-   181  
-   182 _webSocketSharp.Log.Output = (logData, s) =>
-   183 {
-   184 Log.Information($"WebSockets low level logging reported: {logData.Message}");
-   185 };
181   186  
182 _webSocketSharp.OnMessage += WebSocketSharp_OnMessage; 187 _webSocketSharp.OnMessage += WebSocketSharp_OnMessage;
183 _webSocketSharp.OnError += WebSocketSharp_OnError; 188 _webSocketSharp.OnError += WebSocketSharp_OnError;
184 _webSocketSharp.OnOpen += WebSocketSharp_OnOpen; 189 _webSocketSharp.OnOpen += WebSocketSharp_OnOpen;
185 _webSocketSharp.OnClose += WebSocketSharp_OnClose; -  
186 _webSocketSharp.Log.Output = (data, s) => 190 _webSocketSharp.OnClose += WebSocketSharp_OnClose;
187 { -  
188 var a = s; -  
189 }; 191
190 _webSocketSharp.ConnectAsync(); 192 _webSocketSharp.ConnectAsync();
Line 191... Line 193...
191 } 193 }
192   194  
193 private void WebSocketSharp_OnClose(object sender, CloseEventArgs e) 195 private void WebSocketSharp_OnClose(object sender, CloseEventArgs e)
194 { 196 {
Line 195... Line 197...
195 Log.Information($"WebSockets connection to server {_webSocketsUri.AbsoluteUri} closed with reason {e.Reason}."); 197 Log.Information($"WebSockets connection to server {_webSocketsUri.AbsoluteUri} closed with reason {e.Reason}");
196 } 198 }
197   199  
198 private void WebSocketSharp_OnOpen(object sender, EventArgs e) 200 private void WebSocketSharp_OnOpen(object sender, EventArgs e)
Line 199... Line 201...
199 { 201 {
200 Log.Information($"WebSockets connection to server {_webSocketsUri.AbsoluteUri} is now open."); 202 Log.Information($"WebSockets connection to server {_webSocketsUri.AbsoluteUri} is now open");
201 } 203 }
Line 202... Line 204...
202   204  
203 private async void WebSocketSharp_OnError(object sender, ErrorEventArgs e) 205 private async void WebSocketSharp_OnError(object sender, ErrorEventArgs e)
204 { 206 {
205 Log.Error($"Connection to WebSockets server {_webSocketsUri.AbsoluteUri} terminated unexpectedly with message {e.Message}.", e.Exception); 207 Log.Error($"Connection to WebSockets server {_webSocketsUri.AbsoluteUri} terminated unexpectedly with message {e.Message}", e.Exception);
206   208  
Line 207... Line 209...
207 if (_cancellationToken.IsCancellationRequested) 209 if (_cancellationToken.IsCancellationRequested)
208 { 210 {
Line 209... Line 211...
209 Stop(); 211 Stop();
210 return; 212 return;
Line 211... Line 213...
211 } 213 }
212   214  
213 await Task.Delay(TimeSpan.FromSeconds(1), _cancellationToken); 215 await Task.Delay(TimeSpan.FromSeconds(1), _cancellationToken);
214 Log.Information($"Reconnecting to websocket server {_webSocketsUri.AbsoluteUri}."); 216 Log.Information($"Reconnecting to websocket server {_webSocketsUri.AbsoluteUri}");
215   217  
216 Connect(); 218 Connect();
217 } 219 }
Line 218... Line 220...
218   220  
Line 248... Line 250...
248 gotifyNotification.Server = _server; 250 gotifyNotification.Server = _server;
Line 249... Line 251...
249   251  
250 if (!Uri.TryCreate(Path.Combine($"{_httpUri}", "application"), UriKind.Absolute, 252 if (!Uri.TryCreate(Path.Combine($"{_httpUri}", "application"), UriKind.Absolute,
251 out var applicationUri)) 253 out var applicationUri))
252 { 254 {
253 Log.Warning($"Could not build an URI to an application."); 255 Log.Warning($"Could not build an URI to an application");
254 return; 256 return;
Line 255... Line 257...
255 } 257 }
256   258  
257 using (var imageStream = 259 using (var imageStream =
258 await RetrieveGotifyApplicationImage(gotifyNotification.AppId, applicationUri, _cancellationToken)) 260 await RetrieveGotifyApplicationImage(gotifyNotification.AppId, applicationUri, _cancellationToken))
259 { 261 {
260 if (imageStream == null) 262 if (imageStream == null)
261 { 263 {
262 Log.Warning("Could not find any application image for notification."); 264 Log.Warning("Could not find any application image for notification");
Line 263... Line 265...
263 return; 265 return;
Line 293... Line 295...
293 catch (Exception exception) when (exception is OperationCanceledException || exception is ObjectDisposedException) 295 catch (Exception exception) when (exception is OperationCanceledException || exception is ObjectDisposedException)
294 { 296 {
295 } 297 }
296 catch (Exception exception) 298 catch (Exception exception)
297 { 299 {
298 Log.Warning(exception, "Failure running connection loop."); 300 Log.Warning(exception, "Failure running connection loop");
299 } 301 }
300 } 302 }
Line 301... Line 303...
301   303  
302 private async Task<Stream> RetrieveGotifyApplicationImage(int appId, Uri applicationUri, 304 private async Task<Stream> RetrieveGotifyApplicationImage(int appId, Uri applicationUri,
Line 324... Line 326...
324 if (application.Id != appId) continue; 326 if (application.Id != appId) continue;
Line 325... Line 327...
325   327  
326 if (!Uri.TryCreate(Path.Combine($"{_httpUri}", $"{application.Image}"), UriKind.Absolute, 328 if (!Uri.TryCreate(Path.Combine($"{_httpUri}", $"{application.Image}"), UriKind.Absolute,
327 out var applicationImageUri)) 329 out var applicationImageUri))
328 { 330 {
329 Log.Warning("Could not build URL path to application icon."); 331 Log.Warning("Could not build URL path to application icon");
330 continue; 332 continue;
Line 331... Line 333...
331 } 333 }