Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit bd85ee9

Browse files
committed
ReSharper code cleanup
1 parent b653aa3 commit bd85ee9

File tree

186 files changed

+16548
-18190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+16548
-18190
lines changed

.github/docfx.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{
44
"src": [
55
{
6-
"files": [ "Titanium.Web.Proxy.Docs.sln"],
7-
"src": "../src/"
6+
"files": ["Titanium.Web.Proxy.Docs.sln"],
7+
"src": "../src/"
88
}
99
],
1010
"dest": "obj/api"
@@ -13,17 +13,17 @@
1313
"build": {
1414
"content": [
1515
{
16-
"files": [ "**/*.yml" ],
16+
"files": ["**/*.yml"],
1717
"src": "obj/api",
1818
"dest": "api"
1919
},
2020
{
21-
"files": [ "*.md" ]
21+
"files": ["*.md"]
2222
}
2323
],
2424
"resource": [
2525
{
26-
"files": [ ""]
26+
"files": [""]
2727
}
2828
],
2929
"overwrite": "specs/*.md",
@@ -32,6 +32,6 @@
3232
"_enableSearch": true
3333
},
3434
"dest": "../docs",
35-
"xrefService": [ "https://xref.docs.microsoft.com/query?uid={uid}" ]
35+
"xrefService": ["https://xref.docs.microsoft.com/query?uid={uid}"]
3636
}
37-
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<configuration>
4-
<startup>
5-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
6-
</startup>
4+
<startup>
5+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
6+
</startup>
77
</configuration>

examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,19 @@ internal static bool DisableQuickEditMode()
2828
var consoleHandle = GetStdHandle(StdInputHandle);
2929

3030
// get current console mode
31-
if (!GetConsoleMode(consoleHandle, out uint consoleMode))
32-
{
31+
if (!GetConsoleMode(consoleHandle, out var consoleMode))
3332
// ERROR: Unable to get console mode.
3433
return false;
35-
}
3634

3735
// Clear the quick edit bit in the mode flags
3836
consoleMode &= ~EnableQuickEdit;
3937

4038
// set the new mode
4139
if (!SetConsoleMode(consoleHandle, consoleMode))
42-
{
4340
// ERROR: Unable to set console mode
4441
return false;
45-
}
4642

4743
return true;
4844
}
4945
}
50-
}
46+
}

examples/Titanium.Web.Proxy.Examples.Basic/Program.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ public class Program
1010

1111
public static void Main(string[] args)
1212
{
13-
1413
if (RunTime.IsWindows)
15-
{
1614
// fix console hang due to QuickEdit mode
1715
ConsoleHelper.DisableQuickEditMode();
18-
}
1916

2017
// Start proxy controller
2118
controller.StartProxy();
@@ -27,4 +24,4 @@ public static void Main(string[] args)
2724
controller.Stop();
2825
}
2926
}
30-
}
27+
}

examples/Titanium.Web.Proxy.Examples.Basic/ProxyEventArgsBaseExtensions.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ public static class ProxyEventArgsBaseExtensions
66
{
77
public static SampleClientState GetState(this ProxyEventArgsBase args)
88
{
9-
if (args.ClientUserData == null)
10-
{
11-
args.ClientUserData = new SampleClientState();
12-
}
9+
if (args.ClientUserData == null) args.ClientUserData = new SampleClientState();
1310

1411
return (SampleClientState)args.ClientUserData;
1512
}
1613
}
17-
}
14+
}

examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs

+25-47
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.IO;
34
using System.Linq;
45
using System.Net;
56
using System.Net.Security;
67
using System.Threading;
78
using System.Threading.Tasks;
89
using Titanium.Web.Proxy.EventArguments;
9-
using Titanium.Web.Proxy.Examples.Basic.Helpers;
1010
using Titanium.Web.Proxy.Exceptions;
1111
using Titanium.Web.Proxy.Helpers;
1212
using Titanium.Web.Proxy.Http;
@@ -18,13 +18,14 @@ namespace Titanium.Web.Proxy.Examples.Basic
1818
public class ProxyTestController : IDisposable
1919
{
2020
private readonly ProxyServer proxyServer;
21-
private ExplicitProxyEndPoint explicitEndPoint;
2221

23-
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
24-
private CancellationToken CancellationToken => cancellationTokenSource.Token;
25-
private ConcurrentQueue<Tuple<ConsoleColor?, string>> consoleMessageQueue
22+
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
23+
24+
private readonly ConcurrentQueue<Tuple<ConsoleColor?, string>> consoleMessageQueue
2625
= new ConcurrentQueue<Tuple<ConsoleColor?, string>>();
2726

27+
private ExplicitProxyEndPoint explicitEndPoint;
28+
2829
public ProxyTestController()
2930
{
3031
Task.Run(() => ListenToConsole());
@@ -42,13 +43,9 @@ public ProxyTestController()
4243
proxyServer.ExceptionFunc = async exception =>
4344
{
4445
if (exception is ProxyHttpException phex)
45-
{
4646
WriteToConsole(exception.Message + ": " + phex.InnerException?.Message, ConsoleColor.Red);
47-
}
4847
else
49-
{
5048
WriteToConsole(exception.Message, ConsoleColor.Red);
51-
}
5249
};
5350

5451
proxyServer.TcpTimeWaitSeconds = 10;
@@ -74,6 +71,14 @@ public ProxyTestController()
7471
//proxyServer.CertificateManager.RootCertificate = new X509Certificate2("myCert.pfx", string.Empty, X509KeyStorageFlags.Exportable);
7572
}
7673

74+
private CancellationToken CancellationToken => cancellationTokenSource.Token;
75+
76+
public void Dispose()
77+
{
78+
cancellationTokenSource.Dispose();
79+
proxyServer.Dispose();
80+
}
81+
7782
public void StartProxy()
7883
{
7984
proxyServer.BeforeRequest += OnRequest;
@@ -127,18 +132,13 @@ public void StartProxy()
127132
//proxyServer.AddEndPoint(socksEndPoint);
128133

129134
foreach (var endPoint in proxyServer.ProxyEndPoints)
130-
{
131135
Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ", endPoint.GetType().Name,
132136
endPoint.IpAddress, endPoint.Port);
133-
}
134137

135138
// Only explicit proxies can be set as system proxy!
136139
//proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
137140
//proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
138-
if (RunTime.IsWindows)
139-
{
140-
proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);
141-
}
141+
if (RunTime.IsWindows) proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);
142142
}
143143

144144
public void Stop()
@@ -191,23 +191,19 @@ private async Task<IExternalProxy> OnCustomUpStreamProxyFailureFunc(SessionEvent
191191

192192
private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
193193
{
194-
string hostname = e.HttpClient.Request.RequestUri.Host;
194+
var hostname = e.HttpClient.Request.RequestUri.Host;
195195
e.GetState().PipelineInfo.AppendLine(nameof(OnBeforeTunnelConnectRequest) + ":" + hostname);
196196
WriteToConsole("Tunnel to: " + hostname);
197197

198198
var clientLocalIp = e.ClientLocalEndPoint.Address;
199199
if (!clientLocalIp.Equals(IPAddress.Loopback) && !clientLocalIp.Equals(IPAddress.IPv6Loopback))
200-
{
201200
e.HttpClient.UpStreamEndPoint = new IPEndPoint(clientLocalIp, 0);
202-
}
203201

204202
if (hostname.Contains("dropbox.com"))
205-
{
206203
// Exclude Https addresses you don't want to proxy
207204
// Useful for clients that use certificate pinning
208205
// for example dropbox.com
209206
e.DecryptSsl = false;
210-
}
211207
}
212208

213209
private void WebSocket_DataSent(object sender, DataEventArgs e)
@@ -231,20 +227,18 @@ private void WebSocketDataSentReceived(SessionEventArgs args, DataEventArgs e, b
231227
if (frame.OpCode == WebsocketOpCode.Binary)
232228
{
233229
var data = frame.Data.ToArray();
234-
string str = string.Join(",", data.ToArray().Select(x => x.ToString("X2")));
230+
var str = string.Join(",", data.ToArray().Select(x => x.ToString("X2")));
235231
WriteToConsole(str, color);
236232
}
237233

238-
if (frame.OpCode == WebsocketOpCode.Text)
239-
{
240-
WriteToConsole(frame.GetText(), color);
241-
}
234+
if (frame.OpCode == WebsocketOpCode.Text) WriteToConsole(frame.GetText(), color);
242235
}
243236
}
244237

245238
private Task OnBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e)
246239
{
247-
e.GetState().PipelineInfo.AppendLine(nameof(OnBeforeTunnelConnectResponse) + ":" + e.HttpClient.Request.RequestUri);
240+
e.GetState().PipelineInfo
241+
.AppendLine(nameof(OnBeforeTunnelConnectResponse) + ":" + e.HttpClient.Request.RequestUri);
248242

249243
return Task.CompletedTask;
250244
}
@@ -256,14 +250,10 @@ private async Task OnRequest(object sender, SessionEventArgs e)
256250

257251
var clientLocalIp = e.ClientLocalEndPoint.Address;
258252
if (!clientLocalIp.Equals(IPAddress.Loopback) && !clientLocalIp.Equals(IPAddress.IPv6Loopback))
259-
{
260253
e.HttpClient.UpStreamEndPoint = new IPEndPoint(clientLocalIp, 0);
261-
}
262254

263255
if (e.HttpClient.Request.Url.Contains("yahoo.com"))
264-
{
265256
e.CustomUpStreamProxy = new ExternalProxy("localhost", 8888);
266-
}
267257

268258
WriteToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
269259
WriteToConsole(e.HttpClient.Request.Url);
@@ -310,10 +300,7 @@ private async Task MultipartRequestPartSent(object sender, MultipartRequestPartS
310300

311301
var session = (SessionEventArgs)sender;
312302
WriteToConsole("Multipart form data headers:");
313-
foreach (var header in e.Headers)
314-
{
315-
WriteToConsole(header.ToString());
316-
}
303+
foreach (var header in e.Headers) WriteToConsole(header.ToString());
317304
}
318305

319306
private async Task OnResponse(object sender, SessionEventArgs e)
@@ -328,7 +315,7 @@ private async Task OnResponse(object sender, SessionEventArgs e)
328315

329316
WriteToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
330317

331-
string ext = System.IO.Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath);
318+
var ext = Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath);
332319

333320
// access user data set in request to do something with it
334321
//var userData = e.HttpClient.UserData as CustomUserData;
@@ -385,10 +372,7 @@ public Task OnCertificateValidation(object sender, CertificateValidationEventArg
385372
e.GetState().PipelineInfo.AppendLine(nameof(OnCertificateValidation));
386373

387374
// set IsValid to true/false based on Certificate Errors
388-
if (e.SslPolicyErrors == SslPolicyErrors.None)
389-
{
390-
e.IsValid = true;
391-
}
375+
if (e.SslPolicyErrors == SslPolicyErrors.None) e.IsValid = true;
392376

393377
return Task.CompletedTask;
394378
}
@@ -423,7 +407,7 @@ private async Task ListenToConsole()
423407

424408
if (consoleColor.HasValue)
425409
{
426-
ConsoleColor existing = Console.ForegroundColor;
410+
var existing = Console.ForegroundColor;
427411
Console.ForegroundColor = consoleColor.Value;
428412
Console.WriteLine(message);
429413
Console.ForegroundColor = existing;
@@ -439,12 +423,6 @@ private async Task ListenToConsole()
439423
}
440424
}
441425

442-
public void Dispose()
443-
{
444-
cancellationTokenSource.Dispose();
445-
proxyServer.Dispose();
446-
}
447-
448426
///// <summary>
449427
///// User data object as defined by user.
450428
///// User data can be set to each SessionEventArgs.HttpClient.UserData property
@@ -456,4 +434,4 @@ public void Dispose()
456434
// public string RequestBodyString { get; set; }
457435
//}
458436
}
459-
}
437+
}

examples/Titanium.Web.Proxy.Examples.Basic/SampleClientState.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ public class SampleClientState
66
{
77
public StringBuilder PipelineInfo { get; } = new StringBuilder();
88
}
9-
}
9+
}

0 commit comments

Comments
 (0)