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

Commit 65850f4

Browse files
committed
unnecessary conditinal codes removed (since .netstandard2 supports them). they are platform specifix, not target framework specific.
1 parent bde005d commit 65850f4

File tree

16 files changed

+32
-175
lines changed

16 files changed

+32
-175
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ public void StartProxy()
108108
foreach (var endPoint in proxyServer.ProxyEndPoints)
109109
Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ", endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port);
110110

111-
#if NET45
112-
//Only explicit proxies can be set as system proxy!
113-
//proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
114-
//proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
115-
proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);
111+
#if NETSTANDARD2_0
112+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
116113
#endif
114+
{
115+
//Only explicit proxies can be set as system proxy!
116+
//proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
117+
//proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
118+
proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);
119+
}
117120
}
118121

119122
public void Stop()

Titanium.Web.Proxy/Extensions/DotNet45Extensions.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

Titanium.Web.Proxy/Helpers/Firefox.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if NET45
2-
using System;
1+
using System;
32
using System.IO;
43

54
namespace Titanium.Web.Proxy.Helpers
@@ -51,4 +50,3 @@ internal void UseSystemProxy()
5150
}
5251
}
5352
}
54-
#endif

Titanium.Web.Proxy/Helpers/NativeMethods.SystemProxy.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if NET45
2-
using System;
1+
using System;
32
using System.Runtime.InteropServices;
43

54
namespace Titanium.Web.Proxy.Helpers
@@ -22,4 +21,3 @@ internal partial class NativeMethods
2221
internal delegate bool ConsoleEventDelegate(int eventType);
2322
}
2423
}
25-
#endif

Titanium.Web.Proxy/Helpers/Network.cs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ internal static int GetProcessIdFromPort(int port, bool ipV6Enabled)
2525
return FindProcessIdFromLocalPort(port, IpVersion.Ipv6);
2626
}
2727

28-
#if NET45
2928
/// <summary>
3029
/// Adapated from below link
3130
/// http://stackoverflow.com/questions/11834091/how-to-check-if-localhost
@@ -75,56 +74,5 @@ internal static bool IsLocalIpAddress(string hostName)
7574

7675
return isLocalhost;
7776
}
78-
#else
79-
/// <summary>
80-
/// Adapated from below link
81-
/// http://stackoverflow.com/questions/11834091/how-to-check-if-localhost
82-
/// </summary>
83-
/// <param name="address"></param>
84-
/// <returns></returns>
85-
internal static bool IsLocalIpAddress(IPAddress address)
86-
{
87-
// get local IP addresses
88-
var localIPs = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result;
89-
// test if any host IP equals to any local IP or to localhost
90-
return IPAddress.IsLoopback(address) || localIPs.Contains(address);
91-
}
92-
93-
internal static bool IsLocalIpAddress(string hostName)
94-
{
95-
bool isLocalhost = false;
96-
97-
var localhost = Dns.GetHostEntryAsync("127.0.0.1").Result;
98-
if (hostName == localhost.HostName)
99-
{
100-
var hostEntry = Dns.GetHostEntryAsync(hostName).Result;
101-
isLocalhost = hostEntry.AddressList.Any(IPAddress.IsLoopback);
102-
}
103-
104-
if (!isLocalhost)
105-
{
106-
localhost = Dns.GetHostEntryAsync(Dns.GetHostName()).Result;
107-
108-
IPAddress ipAddress;
109-
110-
if (IPAddress.TryParse(hostName, out ipAddress))
111-
isLocalhost = localhost.AddressList.Any(x => x.Equals(ipAddress));
112-
113-
if (!isLocalhost)
114-
{
115-
try
116-
{
117-
var hostEntry = Dns.GetHostEntryAsync(hostName).Result;
118-
isLocalhost = localhost.AddressList.Any(x => hostEntry.AddressList.Any(x.Equals));
119-
}
120-
catch (SocketException)
121-
{
122-
}
123-
}
124-
}
125-
126-
return isLocalhost;
127-
}
128-
#endif
12977
}
13078
}

Titanium.Web.Proxy/Helpers/ProxyInfo.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if NET45
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Linq;
54
using System.Text;
@@ -199,4 +198,3 @@ private static HttpSystemProxyValue ParseProxyValue(string value)
199198
}
200199
}
201200
}
202-
#endif

Titanium.Web.Proxy/Helpers/SystemProxy.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if NET45
2-
using System;
1+
using System;
32
using System.Linq;
43
using Microsoft.Win32;
54

@@ -328,4 +327,3 @@ private void Refresh()
328327
}
329328
}
330329
}
331-
#endif

Titanium.Web.Proxy/Helpers/WinHttp/NativeMethods.WinHttp.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if NET45
2-
using System;
1+
using System;
32
using System.Runtime.InteropServices;
43

54
// Helper classes for setting system proxy settings
@@ -131,4 +130,3 @@ internal enum ErrorCodes
131130
}
132131
}
133132
}
134-
#endif

Titanium.Web.Proxy/Helpers/WinHttp/WinHttpHandle.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#if NET45
21
using System;
32
using System.Runtime.InteropServices;
43

@@ -18,4 +17,3 @@ protected override bool ReleaseHandle()
1817
public override bool IsInvalid => handle == IntPtr.Zero;
1918
}
2019
}
21-
#endif

Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#if NET45
21
using System;
32
using System.Collections.Generic;
43
using System.Net;
@@ -331,4 +330,3 @@ private enum AutoWebProxyState
331330
}
332331
}
333332
}
334-
#endif

0 commit comments

Comments
 (0)