Winify – Diff between revs 46 and 47
?pathlinks?
Rev 46 | Rev 47 | |||
---|---|---|---|---|
Line 63... | Line 63... | |||
63 | { |
63 | { |
|
64 | httpClientHandler.ServerCertificateCustomValidationCallback = |
64 | httpClientHandler.ServerCertificateCustomValidationCallback = |
|
65 | (httpRequestMessage, cert, cetChain, policyErrors) => true; |
65 | (httpRequestMessage, cert, cetChain, policyErrors) => true; |
|
66 | } |
66 | } |
|
Line 67... | Line 67... | |||
67 | |
67 | |
|
- | 68 | _httpClient = new HttpClient(httpClientHandler); |
||
68 | _httpClient = new HttpClient(httpClientHandler) |
69 | if (!string.IsNullOrEmpty(_server.Username) && !string.IsNullOrEmpty(_server.Password)) |
|
69 | { |
- | ||
70 | DefaultRequestHeaders = |
- | ||
71 | { |
70 | { |
|
72 | Authorization = new AuthenticationHeaderValue("Basic", |
71 | _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", |
|
73 | Convert.ToBase64String(Encoding.Default.GetBytes($"{_server.Username}:{_server.Password}"))) |
72 | Convert.ToBase64String(Encoding.Default.GetBytes($"{_server.Username}:{_server.Password}"))); |
|
74 | } |
- | ||
Line 75... | Line 73... | |||
75 | }; |
73 | } |
|
76 | |
74 | |
|
- | 75 | if (!Uri.TryCreate(_server.Url, UriKind.Absolute, out _httpUri)) |
||
- | 76 | { |
||
- | 77 | Log.Error($"No HTTP URL could be built out of the supplied server URI {_server.Url}."); |
||
- | 78 | return; |
||
77 | if (Uri.TryCreate(_server.Url, UriKind.Absolute, out _httpUri)) |
79 | } |
|
78 | { |
80 | |
|
79 | // Build the web sockets URI. |
81 | // Build the web sockets URI. |
|
80 | var webSocketsUriBuilder = new UriBuilder(_httpUri); |
82 | var webSocketsUriBuilder = new UriBuilder(_httpUri); |
|
81 | switch (webSocketsUriBuilder.Scheme.ToUpperInvariant()) |
83 | switch (webSocketsUriBuilder.Scheme.ToUpperInvariant()) |
|
Line 86... | Line 88... | |||
86 | case "HTTPS": |
88 | case "HTTPS": |
|
87 | webSocketsUriBuilder.Scheme = "wss"; |
89 | webSocketsUriBuilder.Scheme = "wss"; |
|
88 | break; |
90 | break; |
|
89 | } |
91 | } |
|
Line -... | Line 92... | |||
- | 92 | |
||
- | 93 | try |
||
90 | |
94 | { |
|
91 | webSocketsUriBuilder.Path = Path.Combine(webSocketsUriBuilder.Path, "stream"); |
- | ||
92 | _webSocketsUri = webSocketsUriBuilder.Uri; |
95 | webSocketsUriBuilder.Path = Path.Combine(webSocketsUriBuilder.Path, "stream"); |
|
- | 96 | } |
||
- | 97 | catch (ArgumentException exception) |
||
- | 98 | { |
||
- | 99 | Log.Error($"No WebSockets URL could be built from the provided URL {_server.Url} due to {exception.Message}."); |
||
- | 100 | } |
||
- | 101 | |
||
93 | } |
102 | _webSocketsUri = webSocketsUriBuilder.Uri; |
|
Line 94... | Line 103... | |||
94 | } |
103 | } |
|
95 | |
104 | |
|
96 | public void Dispose() |
105 | public void Dispose() |
|
Line 112... | Line 121... | |||
112 | |
121 | |
|
Line 113... | Line 122... | |||
113 | #region Public Methods |
122 | #region Public Methods |
|
114 | |
123 | |
|
- | 124 | public void Start() |
||
- | 125 | { |
||
- | 126 | if (_webSocketsUri == null || _httpUri == null) |
||
- | 127 | { |
||
- | 128 | Log.Error("Could not start connection to server due to unreadable URLs."); |
||
- | 129 | return; |
||
115 | public void Start() |
130 | } |
|
116 | { |
131 | |
|
Line 117... | Line 132... | |||
117 | _cancellationTokenSource = new CancellationTokenSource(); |
132 | _cancellationTokenSource = new CancellationTokenSource(); |
|
Line 123... | Line 138... | |||
123 | } |
138 | } |
|
Line 124... | Line 139... | |||
124 | |
139 | |
|
125 | private void Connect() |
140 | private void Connect() |
|
126 | { |
141 | { |
|
- | 142 | _webSocketSharp = new WebSocket(_webSocketsUri.AbsoluteUri); |
||
- | 143 | if (!string.IsNullOrEmpty(_server.Username) && !string.IsNullOrEmpty(_server.Password)) |
||
127 | _webSocketSharp = new WebSocket(_webSocketsUri.AbsoluteUri); |
144 | { |
|
- | 145 | _webSocketSharp.SetCredentials(_server.Username, _server.Password, true); |
||
- | 146 | } |
||
128 | _webSocketSharp.SetCredentials(_server.Username, _server.Password, true); |
147 | |
|
129 | if (_configuration.IgnoreSelfSignedCertificates) |
148 | if (_configuration.IgnoreSelfSignedCertificates) |
|
130 | { |
149 | { |
|
131 | _webSocketSharp.SslConfiguration.ServerCertificateValidationCallback += |
150 | _webSocketSharp.SslConfiguration.ServerCertificateValidationCallback += |
|
132 | (sender, certificate, chain, errors) => true; |
151 | (sender, certificate, chain, errors) => true; |