diff options
| author | Erwin de Haan <EraYaN@users.noreply.github.com> | 2019-01-06 21:50:43 +0100 |
|---|---|---|
| committer | Erwin de Haan <EraYaN@users.noreply.github.com> | 2019-01-10 20:38:53 +0100 |
| commit | ec1f5dc317182582ebff843c9e8a4d5277405469 (patch) | |
| tree | 6514de336cc9aa94becb3fbd767285dfa61d0b1b /Emby.Server.Implementations/Networking/NetworkManager.cs | |
| parent | 3d867c2c46cec39b669bb8647efef677f32b8a8d (diff) | |
Mayor code cleanup
Add Argument*Exceptions now use proper nameof operators.
Added exception messages to quite a few Argument*Exceptions.
Fixed rethorwing to be proper syntax.
Added a ton of null checkes. (This is only a start, there are about 500 places that need proper null handling)
Added some TODOs to log certain exceptions.
Fix sln again.
Fixed all AssemblyInfo's and added proper copyright (where I could find them)
We live in *current year*.
Fixed the use of braces.
Fixed a ton of properties, and made a fair amount of functions static that should be and can be static.
Made more Methods that should be static static.
You can now use static to find bad functions!
Removed unused variable. And added one more proper XML comment.
Diffstat (limited to 'Emby.Server.Implementations/Networking/NetworkManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Networking/NetworkManager.cs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs index 260d20e35..dbf89d7e1 100644 --- a/Emby.Server.Implementations/Networking/NetworkManager.cs +++ b/Emby.Server.Implementations/Networking/NetworkManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -114,7 +114,7 @@ namespace Emby.Server.Implementations.Networking .ToList(); } - private bool FilterIpAddress(IPAddress address) + private static bool FilterIpAddress(IPAddress address) { var addressString = address.ToString(); @@ -228,7 +228,7 @@ namespace Emby.Server.Implementations.Networking subnet_Test++; } - var subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray()); + var subnet_Match = string.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray()); // TODO: Is this check necessary? if (adapter.OperationalStatus == OperationalStatus.Up) @@ -245,7 +245,7 @@ namespace Emby.Server.Implementations.Networking } } - private bool Is172AddressPrivate(string endpoint) + private static bool Is172AddressPrivate(string endpoint) { for (var i = 16; i <= 31; i++) { @@ -268,7 +268,7 @@ namespace Emby.Server.Implementations.Networking return IsAddressInSubnets(IPAddress.Parse(addressString), addressString, subnets); } - private bool IsAddressInSubnets(IPAddress address, string addressString, string[] subnets) + private static bool IsAddressInSubnets(IPAddress address, string addressString, string[] subnets) { foreach (var subnet in subnets) { @@ -296,7 +296,7 @@ namespace Emby.Server.Implementations.Networking { if (string.IsNullOrEmpty(endpoint)) { - throw new ArgumentNullException("endpoint"); + throw new ArgumentNullException(nameof(endpoint)); } IPAddress address; @@ -380,7 +380,7 @@ namespace Emby.Server.Implementations.Networking return false; } - private Task<IPAddress[]> GetIpAddresses(string hostName) + private static Task<IPAddress[]> GetIpAddresses(string hostName) { return Dns.GetHostAddressesAsync(hostName); } @@ -436,7 +436,7 @@ namespace Emby.Server.Implementations.Networking .ToList(); } - private async Task<IEnumerable<IPAddress>> GetLocalIpAddressesFallback() + private static async Task<IEnumerable<IPAddress>> GetLocalIpAddressesFallback() { var host = await Dns.GetHostEntryAsync(Dns.GetHostName()).ConfigureAwait(false); @@ -480,7 +480,7 @@ namespace Emby.Server.Implementations.Networking return _macAddresses; } - private List<string> GetMacAddressesInternal() + private static List<string> GetMacAddressesInternal() { return NetworkInterface.GetAllNetworkInterfaces() .Where(i => i.NetworkInterfaceType != NetworkInterfaceType.Loopback) @@ -497,8 +497,9 @@ namespace Emby.Server.Implementations.Networking return physicalAddress.ToString(); } - catch (Exception ex) + catch (Exception) { + //TODO Log exception. return null; } }) @@ -526,7 +527,7 @@ namespace Emby.Server.Implementations.Networking /// <exception cref="System.FormatException"></exception> private static async Task<IPEndPoint> Parse(string endpointstring, int defaultport) { - if (String.IsNullOrEmpty(endpointstring) + if (string.IsNullOrEmpty(endpointstring) || endpointstring.Trim().Length == 0) { throw new ArgumentException("Endpoint descriptor may not be empty."); @@ -536,7 +537,7 @@ namespace Emby.Server.Implementations.Networking (defaultport < IPEndPoint.MinPort || defaultport > IPEndPoint.MaxPort)) { - throw new ArgumentException(String.Format("Invalid default port '{0}'", defaultport)); + throw new ArgumentException(string.Format("Invalid default port '{0}'", defaultport)); } string[] values = endpointstring.Split(new char[] { ':' }); @@ -557,7 +558,7 @@ namespace Emby.Server.Implementations.Networking //could [a:b:c]:d if (values[0].StartsWith("[") && values[values.Length - 2].EndsWith("]")) { - string ipaddressstring = String.Join(":", values.Take(values.Length - 1).ToArray()); + string ipaddressstring = string.Join(":", values.Take(values.Length - 1).ToArray()); ipaddy = IPAddress.Parse(ipaddressstring); port = GetPort(values[values.Length - 1]); } @@ -569,11 +570,11 @@ namespace Emby.Server.Implementations.Networking } else { - throw new FormatException(String.Format("Invalid endpoint ipaddress '{0}'", endpointstring)); + throw new FormatException(string.Format("Invalid endpoint ipaddress '{0}'", endpointstring)); } if (port == -1) - throw new ArgumentException(String.Format("No port specified: '{0}'", endpointstring)); + throw new ArgumentException(string.Format("No port specified: '{0}'", endpointstring)); return new IPEndPoint(ipaddy, port); } @@ -590,11 +591,11 @@ namespace Emby.Server.Implementations.Networking { int port; - if (!Int32.TryParse(p, out port) + if (!int.TryParse(p, out port) || port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort) { - throw new FormatException(String.Format("Invalid end point port '{0}'", p)); + throw new FormatException(string.Format("Invalid end point port '{0}'", p)); } return port; @@ -611,7 +612,7 @@ namespace Emby.Server.Implementations.Networking var hosts = await Dns.GetHostAddressesAsync(p).ConfigureAwait(false); if (hosts == null || hosts.Length == 0) - throw new ArgumentException(String.Format("Host not found: {0}", p)); + throw new ArgumentException(string.Format("Host not found: {0}", p)); return hosts[0]; } |
