Winify – Diff between revs 48 and 50
?pathlinks?
Rev 48 | Rev 50 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | using System; |
1 | using System; |
|
2 | using System.Drawing; |
2 | using System.Drawing; |
|
3 | using System.IO; |
3 | using System.IO; |
|
- | 4 | using System.Net; |
||
4 | using System.Net.Http; |
5 | using System.Net.Http; |
|
5 | using System.Net.Http.Headers; |
6 | using System.Net.Http.Headers; |
|
6 | using System.Net.Security; |
7 | using System.Net.Security; |
|
- | 8 | using System.Security.Authentication; |
||
7 | using System.Security.Cryptography.X509Certificates; |
9 | using System.Security.Cryptography.X509Certificates; |
|
8 | using System.Text; |
10 | using System.Text; |
|
9 | using System.Threading; |
11 | using System.Threading; |
|
10 | using System.Threading.Tasks; |
12 | using System.Threading.Tasks; |
|
11 | using Newtonsoft.Json; |
13 | using Newtonsoft.Json; |
|
12 | using Serilog; |
14 | using Serilog; |
|
13 | using Servers; |
15 | using Servers; |
|
14 | using WebSocketSharp; |
16 | using WebSocketSharp; |
|
- | 17 | using WebSocketSharp.Net; |
||
- | 18 | using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel; |
||
15 | using Configuration = Configuration.Configuration; |
19 | using Configuration = Configuration.Configuration; |
|
16 | using ErrorEventArgs = WebSocketSharp.ErrorEventArgs; |
20 | using ErrorEventArgs = WebSocketSharp.ErrorEventArgs; |
|
- | 21 | using NetworkCredential = System.Net.NetworkCredential; |
||
Line 17... | Line 22... | |||
17 | |
22 | |
|
18 | namespace Winify.Gotify |
23 | namespace Winify.Gotify |
|
19 | { |
24 | { |
|
20 | public class GotifyConnection : IDisposable |
25 | public class GotifyConnection : IDisposable |
|
Line 55... | Line 60... | |||
55 | public GotifyConnection(Server server, global::Configuration.Configuration configuration) : this() |
60 | public GotifyConnection(Server server, global::Configuration.Configuration configuration) : this() |
|
56 | { |
61 | { |
|
57 | _server = server; |
62 | _server = server; |
|
58 | _configuration = configuration; |
63 | _configuration = configuration; |
|
Line 59... | Line 64... | |||
59 | |
64 | |
|
- | 65 | var httpClientHandler = new HttpClientHandler() |
||
- | 66 | { |
||
- | 67 | SslProtocols = SslProtocols.Tls12 |
||
- | 68 | }; |
||
60 | var httpClientHandler = new HttpClientHandler(); |
69 | |
|
61 | _httpClient = new HttpClient(httpClientHandler); |
70 | _httpClient = new HttpClient(httpClientHandler); |
|
62 | if (_configuration.IgnoreSelfSignedCertificates) |
71 | if (_configuration.IgnoreSelfSignedCertificates) |
|
63 | { |
72 | { |
|
64 | httpClientHandler.ServerCertificateCustomValidationCallback = |
73 | httpClientHandler.ServerCertificateCustomValidationCallback = |
|
65 | (httpRequestMessage, cert, cetChain, policyErrors) => true; |
74 | (httpRequestMessage, cert, cetChain, policyErrors) => true; |
|
Line -... | Line 75... | |||
- | 75 | } |
||
- | 76 | |
||
- | 77 | if (_configuration.Proxy.Enable) |
||
- | 78 | { |
||
- | 79 | httpClientHandler.Proxy = new WebProxy(_configuration.Proxy.Url, false, new string[] { }, |
||
- | 80 | new NetworkCredential(_configuration.Proxy.Username, _configuration.Proxy.Password)); |
||
66 | } |
81 | } |
|
67 | |
82 | |
|
68 | _httpClient = new HttpClient(httpClientHandler); |
83 | _httpClient = new HttpClient(httpClientHandler); |
|
69 | if (!string.IsNullOrEmpty(_server.Username) && !string.IsNullOrEmpty(_server.Password)) |
84 | if (!string.IsNullOrEmpty(_server.Username) && !string.IsNullOrEmpty(_server.Password)) |
|
70 | { |
85 | { |
|
Line 144... | Line 159... | |||
144 | } |
159 | } |
|
Line 145... | Line 160... | |||
145 | |
160 | |
|
146 | private void Connect() |
161 | private void Connect() |
|
147 | { |
162 | { |
|
- | 163 | _webSocketSharp = new WebSocket(_webSocketsUri.AbsoluteUri); |
||
- | 164 | _webSocketSharp.SslConfiguration = new ClientSslConfiguration(_webSocketsUri.Host, |
||
- | 165 | new X509CertificateCollection(new X509Certificate[] { }), SslProtocols.Tls12, false); |
||
- | 166 | if (_configuration.Proxy.Enable) |
||
- | 167 | { |
||
- | 168 | _webSocketSharp.SetProxy(_configuration.Proxy.Url, _configuration.Proxy.Username, _configuration.Proxy.Password); |
||
- | 169 | } |
||
148 | _webSocketSharp = new WebSocket(_webSocketsUri.AbsoluteUri); |
170 | |
|
149 | if (!string.IsNullOrEmpty(_server.Username) && !string.IsNullOrEmpty(_server.Password)) |
171 | if (!string.IsNullOrEmpty(_server.Username) && !string.IsNullOrEmpty(_server.Password)) |
|
150 | { |
172 | { |
|
151 | _webSocketSharp.SetCredentials(_server.Username, _server.Password, true); |
173 | _webSocketSharp.SetCredentials(_server.Username, _server.Password, true); |
|
Line 159... | Line 181... | |||
159 | |
181 | |
|
160 | _webSocketSharp.OnMessage += WebSocketSharp_OnMessage; |
182 | _webSocketSharp.OnMessage += WebSocketSharp_OnMessage; |
|
161 | _webSocketSharp.OnError += WebSocketSharp_OnError; |
183 | _webSocketSharp.OnError += WebSocketSharp_OnError; |
|
162 | _webSocketSharp.OnOpen += WebSocketSharp_OnOpen; |
184 | _webSocketSharp.OnOpen += WebSocketSharp_OnOpen; |
|
- | 185 | _webSocketSharp.OnClose += WebSocketSharp_OnClose; |
||
- | 186 | _webSocketSharp.Log.Output = (data, s) => |
||
- | 187 | { |
||
- | 188 | var a = s; |
||
163 | _webSocketSharp.OnClose += WebSocketSharp_OnClose; |
189 | }; |
|
164 | _webSocketSharp.ConnectAsync(); |
190 | _webSocketSharp.ConnectAsync(); |
|
Line 165... | Line 191... | |||
165 | } |
191 | } |
|
166 | |
192 | |