/trunk/Winify/Gotify/GotifyConnection.cs |
@@ -1,9 +1,11 @@ |
using System; |
using System.Drawing; |
using System.IO; |
using System.Net; |
using System.Net.Http; |
using System.Net.Http.Headers; |
using System.Net.Security; |
using System.Security.Authentication; |
using System.Security.Cryptography.X509Certificates; |
using System.Text; |
using System.Threading; |
@@ -12,8 +14,11 @@ |
using Serilog; |
using Servers; |
using WebSocketSharp; |
using WebSocketSharp.Net; |
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel; |
using Configuration = Configuration.Configuration; |
using ErrorEventArgs = WebSocketSharp.ErrorEventArgs; |
using NetworkCredential = System.Net.NetworkCredential; |
|
namespace Winify.Gotify |
{ |
@@ -57,7 +62,11 @@ |
_server = server; |
_configuration = configuration; |
|
var httpClientHandler = new HttpClientHandler(); |
var httpClientHandler = new HttpClientHandler() |
{ |
SslProtocols = SslProtocols.Tls12 |
}; |
|
_httpClient = new HttpClient(httpClientHandler); |
if (_configuration.IgnoreSelfSignedCertificates) |
{ |
@@ -65,6 +74,12 @@ |
(httpRequestMessage, cert, cetChain, policyErrors) => true; |
} |
|
if (_configuration.Proxy.Enable) |
{ |
httpClientHandler.Proxy = new WebProxy(_configuration.Proxy.Url, false, new string[] { }, |
new NetworkCredential(_configuration.Proxy.Username, _configuration.Proxy.Password)); |
} |
|
_httpClient = new HttpClient(httpClientHandler); |
if (!string.IsNullOrEmpty(_server.Username) && !string.IsNullOrEmpty(_server.Password)) |
{ |
@@ -146,6 +161,13 @@ |
private void Connect() |
{ |
_webSocketSharp = new WebSocket(_webSocketsUri.AbsoluteUri); |
_webSocketSharp.SslConfiguration = new ClientSslConfiguration(_webSocketsUri.Host, |
new X509CertificateCollection(new X509Certificate[] { }), SslProtocols.Tls12, false); |
if (_configuration.Proxy.Enable) |
{ |
_webSocketSharp.SetProxy(_configuration.Proxy.Url, _configuration.Proxy.Username, _configuration.Proxy.Password); |
} |
|
if (!string.IsNullOrEmpty(_server.Username) && !string.IsNullOrEmpty(_server.Password)) |
{ |
_webSocketSharp.SetCredentials(_server.Username, _server.Password, true); |
@@ -161,6 +183,10 @@ |
_webSocketSharp.OnError += WebSocketSharp_OnError; |
_webSocketSharp.OnOpen += WebSocketSharp_OnOpen; |
_webSocketSharp.OnClose += WebSocketSharp_OnClose; |
_webSocketSharp.Log.Output = (data, s) => |
{ |
var a = s; |
}; |
_webSocketSharp.ConnectAsync(); |
} |
|