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

Commit d413344

Browse files
committed
Use standard C# naming conventions
1 parent 6e40717 commit d413344

File tree

59 files changed

+931
-1132
lines changed

Some content is hidden

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

59 files changed

+931
-1132
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace Titanium.Web.Proxy.Examples.Basic.Helpers
99
/// </summary>
1010
internal static class ConsoleHelper
1111
{
12-
private const uint ENABLE_QUICK_EDIT = 0x0040;
12+
private const uint EnableQuickEdit = 0x0040;
1313

1414
// STD_INPUT_HANDLE (DWORD): -10 is the standard input device.
15-
private const int STD_INPUT_HANDLE = -10;
15+
private const int StdInputHandle = -10;
1616

1717
[DllImport("kernel32.dll", SetLastError = true)]
1818
private static extern IntPtr GetStdHandle(int nStdHandle);
@@ -25,7 +25,7 @@ internal static class ConsoleHelper
2525

2626
internal static bool DisableQuickEditMode()
2727
{
28-
var consoleHandle = GetStdHandle(STD_INPUT_HANDLE);
28+
var consoleHandle = GetStdHandle(StdInputHandle);
2929

3030
// get current console mode
3131
if (!GetConsoleMode(consoleHandle, out uint consoleMode))
@@ -35,7 +35,7 @@ internal static bool DisableQuickEditMode()
3535
}
3636

3737
// Clear the quick edit bit in the mode flags
38-
consoleMode &= ~ENABLE_QUICK_EDIT;
38+
consoleMode &= ~EnableQuickEdit;
3939

4040
// set the new mode
4141
if (!SetConsoleMode(consoleHandle, consoleMode))

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

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public class ProxyTestController : IDisposable
2121
private ExplicitProxyEndPoint explicitEndPoint;
2222

2323
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
24-
private CancellationToken cancellationToken => cancellationTokenSource.Token;
24+
private CancellationToken CancellationToken => cancellationTokenSource.Token;
2525
private ConcurrentQueue<Tuple<ConsoleColor?, string>> consoleMessageQueue
2626
= new ConcurrentQueue<Tuple<ConsoleColor?, string>>();
2727

2828
public ProxyTestController()
2929
{
30-
Task.Run(() => listenToConsole());
30+
Task.Run(() => ListenToConsole());
3131

3232
proxyServer = new ProxyServer();
3333

@@ -43,11 +43,11 @@ public ProxyTestController()
4343
{
4444
if (exception is ProxyHttpException phex)
4545
{
46-
writeToConsole(exception.Message + ": " + phex.InnerException?.Message, ConsoleColor.Red);
46+
WriteToConsole(exception.Message + ": " + phex.InnerException?.Message, ConsoleColor.Red);
4747
}
4848
else
4949
{
50-
writeToConsole(exception.Message, ConsoleColor.Red);
50+
WriteToConsole(exception.Message, ConsoleColor.Red);
5151
}
5252
};
5353

@@ -76,9 +76,9 @@ public ProxyTestController()
7676

7777
public void StartProxy()
7878
{
79-
proxyServer.BeforeRequest += onRequest;
80-
proxyServer.BeforeResponse += onResponse;
81-
proxyServer.AfterResponse += onAfterResponse;
79+
proxyServer.BeforeRequest += OnRequest;
80+
proxyServer.BeforeResponse += OnResponse;
81+
proxyServer.AfterResponse += OnAfterResponse;
8282

8383
proxyServer.ServerCertificateValidationCallback += OnCertificateValidation;
8484
proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection;
@@ -88,8 +88,8 @@ public void StartProxy()
8888
explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000);
8989

9090
// Fired when a CONNECT request is received
91-
explicitEndPoint.BeforeTunnelConnectRequest += onBeforeTunnelConnectRequest;
92-
explicitEndPoint.BeforeTunnelConnectResponse += onBeforeTunnelConnectResponse;
91+
explicitEndPoint.BeforeTunnelConnectRequest += OnBeforeTunnelConnectRequest;
92+
explicitEndPoint.BeforeTunnelConnectResponse += OnBeforeTunnelConnectResponse;
9393

9494
// An explicit endpoint is where the client knows about the existence of a proxy
9595
// So client sends request in a proxy friendly manner
@@ -143,11 +143,11 @@ public void StartProxy()
143143

144144
public void Stop()
145145
{
146-
explicitEndPoint.BeforeTunnelConnectRequest -= onBeforeTunnelConnectRequest;
147-
explicitEndPoint.BeforeTunnelConnectResponse -= onBeforeTunnelConnectResponse;
146+
explicitEndPoint.BeforeTunnelConnectRequest -= OnBeforeTunnelConnectRequest;
147+
explicitEndPoint.BeforeTunnelConnectResponse -= OnBeforeTunnelConnectResponse;
148148

149-
proxyServer.BeforeRequest -= onRequest;
150-
proxyServer.BeforeResponse -= onResponse;
149+
proxyServer.BeforeRequest -= OnRequest;
150+
proxyServer.BeforeResponse -= OnResponse;
151151
proxyServer.ServerCertificateValidationCallback -= OnCertificateValidation;
152152
proxyServer.ClientCertificateSelectionCallback -= OnCertificateSelection;
153153

@@ -157,9 +157,9 @@ public void Stop()
157157
//proxyServer.CertificateManager.RemoveTrustedRootCertificates();
158158
}
159159

160-
private async Task<IExternalProxy> onGetCustomUpStreamProxyFunc(SessionEventArgsBase arg)
160+
private async Task<IExternalProxy> OnGetCustomUpStreamProxyFunc(SessionEventArgsBase arg)
161161
{
162-
arg.GetState().PipelineInfo.AppendLine(nameof(onGetCustomUpStreamProxyFunc));
162+
arg.GetState().PipelineInfo.AppendLine(nameof(OnGetCustomUpStreamProxyFunc));
163163

164164
// this is just to show the functionality, provided values are junk
165165
return new ExternalProxy
@@ -173,9 +173,9 @@ private async Task<IExternalProxy> onGetCustomUpStreamProxyFunc(SessionEventArgs
173173
};
174174
}
175175

176-
private async Task<IExternalProxy> onCustomUpStreamProxyFailureFunc(SessionEventArgsBase arg)
176+
private async Task<IExternalProxy> OnCustomUpStreamProxyFailureFunc(SessionEventArgsBase arg)
177177
{
178-
arg.GetState().PipelineInfo.AppendLine(nameof(onCustomUpStreamProxyFailureFunc));
178+
arg.GetState().PipelineInfo.AppendLine(nameof(OnCustomUpStreamProxyFailureFunc));
179179

180180
// this is just to show the functionality, provided values are junk
181181
return new ExternalProxy
@@ -189,11 +189,11 @@ private async Task<IExternalProxy> onCustomUpStreamProxyFailureFunc(SessionEvent
189189
};
190190
}
191191

192-
private async Task onBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
192+
private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
193193
{
194194
string hostname = e.HttpClient.Request.RequestUri.Host;
195-
e.GetState().PipelineInfo.AppendLine(nameof(onBeforeTunnelConnectRequest) + ":" + hostname);
196-
writeToConsole("Tunnel to: " + hostname);
195+
e.GetState().PipelineInfo.AppendLine(nameof(OnBeforeTunnelConnectRequest) + ":" + hostname);
196+
WriteToConsole("Tunnel to: " + hostname);
197197

198198
var clientLocalIp = e.ClientLocalEndPoint.Address;
199199
if (!clientLocalIp.Equals(IPAddress.Loopback) && !clientLocalIp.Equals(IPAddress.IPv6Loopback))
@@ -232,27 +232,27 @@ private void WebSocketDataSentReceived(SessionEventArgs args, DataEventArgs e, b
232232
{
233233
var data = frame.Data.ToArray();
234234
string str = string.Join(",", data.ToArray().Select(x => x.ToString("X2")));
235-
writeToConsole(str, color);
235+
WriteToConsole(str, color);
236236
}
237237

238238
if (frame.OpCode == WebsocketOpCode.Text)
239239
{
240-
writeToConsole(frame.GetText(), color);
240+
WriteToConsole(frame.GetText(), color);
241241
}
242242
}
243243
}
244244

245-
private Task onBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e)
245+
private Task OnBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e)
246246
{
247-
e.GetState().PipelineInfo.AppendLine(nameof(onBeforeTunnelConnectResponse) + ":" + e.HttpClient.Request.RequestUri);
247+
e.GetState().PipelineInfo.AppendLine(nameof(OnBeforeTunnelConnectResponse) + ":" + e.HttpClient.Request.RequestUri);
248248

249249
return Task.CompletedTask;
250250
}
251251

252252
// intercept & cancel redirect or update requests
253-
private async Task onRequest(object sender, SessionEventArgs e)
253+
private async Task OnRequest(object sender, SessionEventArgs e)
254254
{
255-
e.GetState().PipelineInfo.AppendLine(nameof(onRequest) + ":" + e.HttpClient.Request.RequestUri);
255+
e.GetState().PipelineInfo.AppendLine(nameof(OnRequest) + ":" + e.HttpClient.Request.RequestUri);
256256

257257
var clientLocalIp = e.ClientLocalEndPoint.Address;
258258
if (!clientLocalIp.Equals(IPAddress.Loopback) && !clientLocalIp.Equals(IPAddress.IPv6Loopback))
@@ -265,8 +265,8 @@ private async Task onRequest(object sender, SessionEventArgs e)
265265
e.CustomUpStreamProxy = new ExternalProxy("localhost", 8888);
266266
}
267267

268-
writeToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
269-
writeToConsole(e.HttpClient.Request.Url);
268+
WriteToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
269+
WriteToConsole(e.HttpClient.Request.Url);
270270

271271
// store it in the UserData property
272272
// It can be a simple integer, Guid, or any type
@@ -304,29 +304,29 @@ private async Task onRequest(object sender, SessionEventArgs e)
304304
}
305305

306306
// Modify response
307-
private async Task multipartRequestPartSent(object sender, MultipartRequestPartSentEventArgs e)
307+
private async Task MultipartRequestPartSent(object sender, MultipartRequestPartSentEventArgs e)
308308
{
309-
e.GetState().PipelineInfo.AppendLine(nameof(multipartRequestPartSent));
309+
e.GetState().PipelineInfo.AppendLine(nameof(MultipartRequestPartSent));
310310

311311
var session = (SessionEventArgs)sender;
312-
writeToConsole("Multipart form data headers:");
312+
WriteToConsole("Multipart form data headers:");
313313
foreach (var header in e.Headers)
314314
{
315-
writeToConsole(header.ToString());
315+
WriteToConsole(header.ToString());
316316
}
317317
}
318318

319-
private async Task onResponse(object sender, SessionEventArgs e)
319+
private async Task OnResponse(object sender, SessionEventArgs e)
320320
{
321-
e.GetState().PipelineInfo.AppendLine(nameof(onResponse));
321+
e.GetState().PipelineInfo.AppendLine(nameof(OnResponse));
322322

323323
if (e.HttpClient.ConnectRequest?.TunnelType == TunnelType.Websocket)
324324
{
325325
e.DataSent += WebSocket_DataSent;
326326
e.DataReceived += WebSocket_DataReceived;
327327
}
328328

329-
writeToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
329+
WriteToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
330330

331331
string ext = System.IO.Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath);
332332

@@ -370,9 +370,9 @@ private async Task onResponse(object sender, SessionEventArgs e)
370370
//}
371371
}
372372

373-
private async Task onAfterResponse(object sender, SessionEventArgs e)
373+
private async Task OnAfterResponse(object sender, SessionEventArgs e)
374374
{
375-
writeToConsole($"Pipelineinfo: {e.GetState().PipelineInfo}", ConsoleColor.Yellow);
375+
WriteToConsole($"Pipelineinfo: {e.GetState().PipelineInfo}", ConsoleColor.Yellow);
376376
}
377377

378378
/// <summary>
@@ -407,14 +407,14 @@ public Task OnCertificateSelection(object sender, CertificateSelectionEventArgs
407407
return Task.CompletedTask;
408408
}
409409

410-
private void writeToConsole(string message, ConsoleColor? consoleColor = null)
410+
private void WriteToConsole(string message, ConsoleColor? consoleColor = null)
411411
{
412412
consoleMessageQueue.Enqueue(new Tuple<ConsoleColor?, string>(consoleColor, message));
413413
}
414414

415-
private async Task listenToConsole()
415+
private async Task ListenToConsole()
416416
{
417-
while (!cancellationToken.IsCancellationRequested)
417+
while (!CancellationToken.IsCancellationRequested)
418418
{
419419
while (consoleMessageQueue.TryDequeue(out var item))
420420
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ static class Program
99
/// </summary>
1010
static void Main()
1111
{
12-
ServiceBase[] ServicesToRun;
13-
ServicesToRun = new ServiceBase[]
12+
ServiceBase[] servicesToRun;
13+
servicesToRun = new ServiceBase[]
1414
{
1515
new ProxyService()
1616
};
17-
ServiceBase.Run(ServicesToRun);
17+
ServiceBase.Run(servicesToRun);
1818
}
1919
}
2020
}

examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public SessionListItem SelectedSession
120120
if (value != selectedSession)
121121
{
122122
selectedSession = value;
123-
selectedSessionChanged();
123+
SelectedSessionChanged();
124124
}
125125
}
126126
}
@@ -145,7 +145,7 @@ private async Task ProxyServer_BeforeTunnelConnectRequest(object sender, TunnelC
145145
e.DecryptSsl = false;
146146
}
147147

148-
await Dispatcher.InvokeAsync(() => { addSession(e); });
148+
await Dispatcher.InvokeAsync(() => { AddSession(e); });
149149
}
150150

151151
private async Task ProxyServer_BeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e)
@@ -164,7 +164,7 @@ private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e)
164164
//if (e.HttpClient.Request.HttpVersion.Major != 2) return;
165165

166166
SessionListItem item = null;
167-
await Dispatcher.InvokeAsync(() => { item = addSession(e); });
167+
await Dispatcher.InvokeAsync(() => { item = AddSession(e); });
168168

169169
if (e.HttpClient.Request.HasBody)
170170
{
@@ -173,7 +173,7 @@ private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e)
173173

174174
if (item == SelectedSession)
175175
{
176-
await Dispatcher.InvokeAsync(selectedSessionChanged);
176+
await Dispatcher.InvokeAsync(SelectedSessionChanged);
177177
}
178178
}
179179
}
@@ -203,7 +203,7 @@ await Dispatcher.InvokeAsync(() =>
203203
await Dispatcher.InvokeAsync(() => { item.Update(e); });
204204
if (item == SelectedSession)
205205
{
206-
await Dispatcher.InvokeAsync(selectedSessionChanged);
206+
await Dispatcher.InvokeAsync(SelectedSessionChanged);
207207
}
208208
}
209209
}
@@ -220,15 +220,15 @@ await Dispatcher.InvokeAsync(() =>
220220
});
221221
}
222222

223-
private SessionListItem addSession(SessionEventArgsBase e)
223+
private SessionListItem AddSession(SessionEventArgsBase e)
224224
{
225-
var item = createSessionListItem(e);
225+
var item = CreateSessionListItem(e);
226226
Sessions.Add(item);
227227
sessionDictionary.Add(e.HttpClient, item);
228228
return item;
229229
}
230230

231-
private SessionListItem createSessionListItem(SessionEventArgsBase e)
231+
private SessionListItem CreateSessionListItem(SessionEventArgsBase e)
232232
{
233233
lastSessionNumber++;
234234
bool isTunnelConnect = e is TunnelConnectSessionEventArgs;
@@ -359,7 +359,7 @@ private void ListViewSessions_OnKeyDown(object sender, KeyEventArgs e)
359359
}
360360
}
361361

362-
private void selectedSessionChanged()
362+
private void SelectedSessionChanged()
363363
{
364364
if (SelectedSession == null)
365365
{

0 commit comments

Comments
 (0)