Winify

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 17  →  ?path2? @ 18
/trunk/Winify/Gotify/GotifyConnection.cs
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net.Http;
@@ -9,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Serilog;
using ClientWebSocket = System.Net.WebSockets.Managed.ClientWebSocket;
 
namespace Winify.Gotify
@@ -79,7 +79,9 @@
_cancellationToken = _cancellationTokenSource.Token;
 
_httpClient = new HttpClient();
 
var auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}"));
 
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);
 
_runTask = Run(webSocketsUri, httpUri, username, password, _cancellationToken);
@@ -107,7 +109,9 @@
try
{
_webSocketClient = new ClientWebSocket();
 
var auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}"));
 
_webSocketClient.Options.SetRequestHeader("Authorization", $"Basic {auth}");
 
await _webSocketClient.ConnectAsync(webSocketsUri, cancellationToken);
@@ -176,7 +180,7 @@
break;
}
 
Debug.WriteLine($"{gotifyNotification.Message}");
Log.Debug($"Notification message received: {gotifyNotification.Message}");
} while (!cancellationToken.IsCancellationRequested);
 
await _webSocketClient.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty,
@@ -184,7 +188,7 @@
}
catch (Exception ex) when (ex is WebSocketException || ex is HttpRequestException)
{
Debug.WriteLine($"Unable to connect to gotify server: {ex.Message}");
Log.Warning($"Unable to connect to gotify server: {ex.Message}");
 
// Reconnect
if (_webSocketClient != null)
@@ -203,7 +207,7 @@
}
catch (Exception ex)
{
Debug.WriteLine($"Exception: {ex}");
Log.Warning(ex, "Failure running connection loop.");
}
}