Winify – Diff between revs 12 and 18

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 12 Rev 18
Line 1... Line 1...
1 using System; 1 using System;
2 using System.Diagnostics; -  
3 using System.Drawing; 2 using System.Drawing;
4 using System.IO; 3 using System.IO;
5 using System.Net.Http; 4 using System.Net.Http;
6 using System.Net.Http.Headers; 5 using System.Net.Http.Headers;
7 using System.Net.WebSockets; 6 using System.Net.WebSockets;
8 using System.Text; 7 using System.Text;
9 using System.Threading; 8 using System.Threading;
10 using System.Threading.Tasks; 9 using System.Threading.Tasks;
11 using Newtonsoft.Json; 10 using Newtonsoft.Json;
-   11 using Serilog;
12 using ClientWebSocket = System.Net.WebSockets.Managed.ClientWebSocket; 12 using ClientWebSocket = System.Net.WebSockets.Managed.ClientWebSocket;
Line 13... Line 13...
13   13  
14 namespace Winify.Gotify 14 namespace Winify.Gotify
15 { 15 {
Line 77... Line 77...
77   77  
78 _cancellationTokenSource = new CancellationTokenSource(); 78 _cancellationTokenSource = new CancellationTokenSource();
Line 79... Line 79...
79 _cancellationToken = _cancellationTokenSource.Token; 79 _cancellationToken = _cancellationTokenSource.Token;
-   80  
80   81 _httpClient = new HttpClient();
-   82  
81 _httpClient = new HttpClient(); 83 var auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}"));
Line 82... Line 84...
82 var auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}")); 84  
83 _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth); 85 _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);
Line 105... Line 107...
105 do 107 do
106 { 108 {
107 try 109 try
108 { 110 {
109 _webSocketClient = new ClientWebSocket(); 111 _webSocketClient = new ClientWebSocket();
-   112  
110 var auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}")); 113 var auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}"));
-   114  
111 _webSocketClient.Options.SetRequestHeader("Authorization", $"Basic {auth}"); 115 _webSocketClient.Options.SetRequestHeader("Authorization", $"Basic {auth}");
Line 112... Line 116...
112   116  
Line 113... Line 117...
113 await _webSocketClient.ConnectAsync(webSocketsUri, cancellationToken); 117 await _webSocketClient.ConnectAsync(webSocketsUri, cancellationToken);
Line 174... Line 178...
174   178  
175   179  
Line 176... Line 180...
176 break; 180 break;
177 } 181 }
Line 178... Line 182...
178   182  
179 Debug.WriteLine($"{gotifyNotification.Message}"); 183 Log.Debug($"Notification message received: {gotifyNotification.Message}");
180 } while (!cancellationToken.IsCancellationRequested); 184 } while (!cancellationToken.IsCancellationRequested);
181   185  
182 await _webSocketClient.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, 186 await _webSocketClient.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty,
183 CancellationToken.None); 187 CancellationToken.None);
Line 184... Line 188...
184 } 188 }
185 catch (Exception ex) when (ex is WebSocketException || ex is HttpRequestException) 189 catch (Exception ex) when (ex is WebSocketException || ex is HttpRequestException)
186 { 190 {
187 Debug.WriteLine($"Unable to connect to gotify server: {ex.Message}"); 191 Log.Warning($"Unable to connect to gotify server: {ex.Message}");
Line 201... Line 205...
201 catch (Exception ex) when (ex is OperationCanceledException || ex is ObjectDisposedException) 205 catch (Exception ex) when (ex is OperationCanceledException || ex is ObjectDisposedException)
202 { 206 {
203 } 207 }
204 catch (Exception ex) 208 catch (Exception ex)
205 { 209 {
206 Debug.WriteLine($"Exception: {ex}"); 210 Log.Warning(ex, "Failure running connection loop.");
207 } 211 }
208 } 212 }
Line 209... Line 213...
209   213  
210 #endregion 214 #endregion