aboutsummaryrefslogtreecommitdiff
path: root/RSSDP
diff options
context:
space:
mode:
authorErwin de Haan <EraYaN@users.noreply.github.com>2019-01-06 21:50:43 +0100
committerErwin de Haan <EraYaN@users.noreply.github.com>2019-01-10 20:38:53 +0100
commitec1f5dc317182582ebff843c9e8a4d5277405469 (patch)
tree6514de336cc9aa94becb3fbd767285dfa61d0b1b /RSSDP
parent3d867c2c46cec39b669bb8647efef677f32b8a8d (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 'RSSDP')
-rw-r--r--RSSDP/DeviceAvailableEventArgs.cs2
-rw-r--r--RSSDP/DeviceEventArgs.cs2
-rw-r--r--RSSDP/DeviceUnavailableEventArgs.cs2
-rw-r--r--RSSDP/HttpParserBase.cs10
-rw-r--r--RSSDP/HttpRequestParser.cs6
-rw-r--r--RSSDP/HttpResponseParser.cs8
-rw-r--r--RSSDP/IEnumerableExtensions.cs4
-rw-r--r--RSSDP/Properties/AssemblyInfo.cs26
-rw-r--r--RSSDP/SsdpCommunicationsServer.cs8
-rw-r--r--RSSDP/SsdpDevice.cs4
-rw-r--r--RSSDP/SsdpDeviceLocator.cs6
-rw-r--r--RSSDP/SsdpDevicePublisher.cs14
12 files changed, 43 insertions, 49 deletions
diff --git a/RSSDP/DeviceAvailableEventArgs.cs b/RSSDP/DeviceAvailableEventArgs.cs
index d80b4b65b..d69407b41 100644
--- a/RSSDP/DeviceAvailableEventArgs.cs
+++ b/RSSDP/DeviceAvailableEventArgs.cs
@@ -30,7 +30,7 @@ namespace Rssdp
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="discoveredDevice"/> parameter is null.</exception>
public DeviceAvailableEventArgs(DiscoveredSsdpDevice discoveredDevice, bool isNewlyDiscovered)
{
- if (discoveredDevice == null) throw new ArgumentNullException("discoveredDevice");
+ if (discoveredDevice == null) throw new ArgumentNullException(nameof(discoveredDevice));
_DiscoveredDevice = discoveredDevice;
_IsNewlyDiscovered = isNewlyDiscovered;
diff --git a/RSSDP/DeviceEventArgs.cs b/RSSDP/DeviceEventArgs.cs
index 774d812ee..a49ef0736 100644
--- a/RSSDP/DeviceEventArgs.cs
+++ b/RSSDP/DeviceEventArgs.cs
@@ -25,7 +25,7 @@ namespace Rssdp
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="device"/> argument is null.</exception>
public DeviceEventArgs(SsdpDevice device)
{
- if (device == null) throw new ArgumentNullException("device");
+ if (device == null) throw new ArgumentNullException(nameof(device));
_Device = device;
}
diff --git a/RSSDP/DeviceUnavailableEventArgs.cs b/RSSDP/DeviceUnavailableEventArgs.cs
index 171a834a0..e01248fa5 100644
--- a/RSSDP/DeviceUnavailableEventArgs.cs
+++ b/RSSDP/DeviceUnavailableEventArgs.cs
@@ -28,7 +28,7 @@ namespace Rssdp
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="discoveredDevice"/> parameter is null.</exception>
public DeviceUnavailableEventArgs(DiscoveredSsdpDevice discoveredDevice, bool expired)
{
- if (discoveredDevice == null) throw new ArgumentNullException("discoveredDevice");
+ if (discoveredDevice == null) throw new ArgumentNullException(nameof(discoveredDevice));
_DiscoveredDevice = discoveredDevice;
_Expired = expired;
diff --git a/RSSDP/HttpParserBase.cs b/RSSDP/HttpParserBase.cs
index e841feab3..000d6db26 100644
--- a/RSSDP/HttpParserBase.cs
+++ b/RSSDP/HttpParserBase.cs
@@ -42,9 +42,9 @@ namespace Rssdp.Infrastructure
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "Honestly, it's fine. MemoryStream doesn't mind.")]
protected virtual void Parse(T message, System.Net.Http.Headers.HttpHeaders headers, string data)
{
- if (data == null) throw new ArgumentNullException("data");
- if (data.Length == 0) throw new ArgumentException("data cannot be an empty string.", "data");
- if (!LineTerminators.Any(data.Contains)) throw new ArgumentException("data is not a valid request, it does not contain any CRLF/LF terminators.", "data");
+ if (data == null) throw new ArgumentNullException(nameof(data));
+ if (data.Length == 0) throw new ArgumentException("data cannot be an empty string.", nameof(data));
+ if (!LineTerminators.Any(data.Contains)) throw new ArgumentException("data is not a valid request, it does not contain any CRLF/LF terminators.", nameof(data));
using (var retVal = new ByteArrayContent(EmptyByteArray))
{
@@ -77,10 +77,10 @@ namespace Rssdp.Infrastructure
/// <returns>A <see cref="Version"/> object containing the parsed version data.</returns>
protected Version ParseHttpVersion(string versionData)
{
- if (versionData == null) throw new ArgumentNullException("versionData");
+ if (versionData == null) throw new ArgumentNullException(nameof(versionData));
var versionSeparatorIndex = versionData.IndexOf('/');
- if (versionSeparatorIndex <= 0 || versionSeparatorIndex == versionData.Length) throw new ArgumentException("request header line is invalid. Http Version not supplied or incorrect format.", "versionData");
+ if (versionSeparatorIndex <= 0 || versionSeparatorIndex == versionData.Length) throw new ArgumentException("request header line is invalid. Http Version not supplied or incorrect format.", nameof(versionData));
return Version.Parse(versionData.Substring(versionSeparatorIndex + 1));
}
diff --git a/RSSDP/HttpRequestParser.cs b/RSSDP/HttpRequestParser.cs
index 8460e1ca5..c3106fbce 100644
--- a/RSSDP/HttpRequestParser.cs
+++ b/RSSDP/HttpRequestParser.cs
@@ -60,11 +60,11 @@ namespace Rssdp.Infrastructure
/// <param name="message">Either a <see cref="System.Net.Http.HttpResponseMessage"/> or <see cref="System.Net.Http.HttpRequestMessage"/> to assign the parsed values to.</param>
protected override void ParseStatusLine(string data, HttpRequestMessage message)
{
- if (data == null) throw new ArgumentNullException("data");
- if (message == null) throw new ArgumentNullException("message");
+ if (data == null) throw new ArgumentNullException(nameof(data));
+ if (message == null) throw new ArgumentNullException(nameof(message));
var parts = data.Split(' ');
- if (parts.Length < 2) throw new ArgumentException("Status line is invalid. Insufficient status parts.", "data");
+ if (parts.Length < 2) throw new ArgumentException("Status line is invalid. Insufficient status parts.", nameof(data));
message.Method = new HttpMethod(parts[0].Trim());
Uri requestUri;
diff --git a/RSSDP/HttpResponseParser.cs b/RSSDP/HttpResponseParser.cs
index 8ecb944c2..eb170ea24 100644
--- a/RSSDP/HttpResponseParser.cs
+++ b/RSSDP/HttpResponseParser.cs
@@ -71,17 +71,17 @@ namespace Rssdp.Infrastructure
/// <param name="message">Either a <see cref="System.Net.Http.HttpResponseMessage"/> or <see cref="System.Net.Http.HttpRequestMessage"/> to assign the parsed values to.</param>
protected override void ParseStatusLine(string data, HttpResponseMessage message)
{
- if (data == null) throw new ArgumentNullException("data");
- if (message == null) throw new ArgumentNullException("message");
+ if (data == null) throw new ArgumentNullException(nameof(data));
+ if (message == null) throw new ArgumentNullException(nameof(message));
var parts = data.Split(' ');
- if (parts.Length < 2) throw new ArgumentException("data status line is invalid. Insufficient status parts.", "data");
+ if (parts.Length < 2) throw new ArgumentException("data status line is invalid. Insufficient status parts.", nameof(data));
message.Version = ParseHttpVersion(parts[0].Trim());
int statusCode = -1;
if (!Int32.TryParse(parts[1].Trim(), out statusCode))
- throw new ArgumentException("data status line is invalid. Status code is not a valid integer.", "data");
+ throw new ArgumentException("data status line is invalid. Status code is not a valid integer.", nameof(data));
message.StatusCode = (HttpStatusCode)statusCode;
diff --git a/RSSDP/IEnumerableExtensions.cs b/RSSDP/IEnumerableExtensions.cs
index f72073949..9608cb479 100644
--- a/RSSDP/IEnumerableExtensions.cs
+++ b/RSSDP/IEnumerableExtensions.cs
@@ -9,8 +9,8 @@ namespace Rssdp.Infrastructure
{
public static IEnumerable<T> SelectManyRecursive<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> selector)
{
- if (source == null) throw new ArgumentNullException("source");
- if (selector == null) throw new ArgumentNullException("selector");
+ if (source == null) throw new ArgumentNullException(nameof(source));
+ if (selector == null) throw new ArgumentNullException(nameof(selector));
return !source.Any() ? source :
source.Concat(
diff --git a/RSSDP/Properties/AssemblyInfo.cs b/RSSDP/Properties/AssemblyInfo.cs
index 1ce64b159..a60820520 100644
--- a/RSSDP/Properties/AssemblyInfo.cs
+++ b/RSSDP/Properties/AssemblyInfo.cs
@@ -1,30 +1,24 @@
-using System.Resources;
using System.Reflection;
-using System.Runtime.CompilerServices;
+using System.Resources;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
-[assembly: AssemblyTitle("RSSDP2")]
+[assembly: AssemblyTitle("RSSDP")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("RSSDP2")]
-[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyCompany("Jellyfin Project")]
+[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
+[assembly: AssemblyCopyright("Copyright © 2015 Troy Willmot. Code released under the MIT license. Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.cs
index 65ec0ca71..5ce3683eb 100644
--- a/RSSDP/SsdpCommunicationsServer.cs
+++ b/RSSDP/SsdpCommunicationsServer.cs
@@ -89,8 +89,8 @@ namespace Rssdp.Infrastructure
/// <exception cref="System.ArgumentOutOfRangeException">The <paramref name="multicastTimeToLive"/> argument is less than or equal to zero.</exception>
public SsdpCommunicationsServer(ISocketFactory socketFactory, int localPort, int multicastTimeToLive, INetworkManager networkManager, ILogger logger, bool enableMultiSocketBinding)
{
- if (socketFactory == null) throw new ArgumentNullException("socketFactory");
- if (multicastTimeToLive <= 0) throw new ArgumentOutOfRangeException("multicastTimeToLive", "multicastTimeToLive must be greater than zero.");
+ if (socketFactory == null) throw new ArgumentNullException(nameof(socketFactory));
+ if (multicastTimeToLive <= 0) throw new ArgumentOutOfRangeException(nameof(multicastTimeToLive), "multicastTimeToLive must be greater than zero.");
_BroadcastListenSocketSynchroniser = new object();
_SendSocketSynchroniser = new object();
@@ -160,7 +160,7 @@ namespace Rssdp.Infrastructure
/// </summary>
public async Task SendMessage(byte[] messageData, IpEndPointInfo destination, IpAddressInfo fromLocalIpAddress, CancellationToken cancellationToken)
{
- if (messageData == null) throw new ArgumentNullException("messageData");
+ if (messageData == null) throw new ArgumentNullException(nameof(messageData));
ThrowIfDisposed();
@@ -245,7 +245,7 @@ namespace Rssdp.Infrastructure
/// </summary>
public async Task SendMulticastMessage(string message, int sendCount, CancellationToken cancellationToken)
{
- if (message == null) throw new ArgumentNullException("messageData");
+ if (message == null) throw new ArgumentNullException(nameof(message));
byte[] messageData = Encoding.UTF8.GetBytes(message);
diff --git a/RSSDP/SsdpDevice.cs b/RSSDP/SsdpDevice.cs
index ef6869c8b..4913ea0cf 100644
--- a/RSSDP/SsdpDevice.cs
+++ b/RSSDP/SsdpDevice.cs
@@ -281,7 +281,7 @@ namespace Rssdp
/// <seealso cref="DeviceAdded"/>
public void AddDevice(SsdpEmbeddedDevice device)
{
- if (device == null) throw new ArgumentNullException("device");
+ if (device == null) throw new ArgumentNullException(nameof(device));
if (device.RootDevice != null && device.RootDevice != this.ToRootDevice()) throw new InvalidOperationException("This device is already associated with a different root device (has been added as a child in another branch).");
if (device == this) throw new InvalidOperationException("Can't add device to itself.");
@@ -309,7 +309,7 @@ namespace Rssdp
/// <seealso cref="DeviceRemoved"/>
public void RemoveDevice(SsdpEmbeddedDevice device)
{
- if (device == null) throw new ArgumentNullException("device");
+ if (device == null) throw new ArgumentNullException(nameof(device));
bool wasRemoved = false;
lock (_Devices)
diff --git a/RSSDP/SsdpDeviceLocator.cs b/RSSDP/SsdpDeviceLocator.cs
index 32289822f..d36b306a0 100644
--- a/RSSDP/SsdpDeviceLocator.cs
+++ b/RSSDP/SsdpDeviceLocator.cs
@@ -39,7 +39,7 @@ namespace Rssdp.Infrastructure
/// </summary>
public SsdpDeviceLocator(ISsdpCommunicationsServer communicationsServer, ITimerFactory timerFactory)
{
- if (communicationsServer == null) throw new ArgumentNullException("communicationsServer");
+ if (communicationsServer == null) throw new ArgumentNullException(nameof(communicationsServer));
_CommunicationsServer = communicationsServer;
_timerFactory = timerFactory;
@@ -164,8 +164,8 @@ namespace Rssdp.Infrastructure
private Task SearchAsync(string searchTarget, TimeSpan searchWaitTime, CancellationToken cancellationToken)
{
- if (searchTarget == null) throw new ArgumentNullException("searchTarget");
- if (searchTarget.Length == 0) throw new ArgumentException("searchTarget cannot be an empty string.", "searchTarget");
+ if (searchTarget == null) throw new ArgumentNullException(nameof(searchTarget));
+ if (searchTarget.Length == 0) throw new ArgumentException("searchTarget cannot be an empty string.", nameof(searchTarget));
if (searchWaitTime.TotalSeconds < 0) throw new ArgumentException("searchWaitTime must be a positive time.");
if (searchWaitTime.TotalSeconds > 0 && searchWaitTime.TotalSeconds <= 1) throw new ArgumentException("searchWaitTime must be zero (if you are not using the result and relying entirely in the events), or greater than one second.");
diff --git a/RSSDP/SsdpDevicePublisher.cs b/RSSDP/SsdpDevicePublisher.cs
index cee9b7f91..11aaf4641 100644
--- a/RSSDP/SsdpDevicePublisher.cs
+++ b/RSSDP/SsdpDevicePublisher.cs
@@ -41,11 +41,11 @@ namespace Rssdp.Infrastructure
/// </summary>
public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, ITimerFactory timerFactory, string osName, string osVersion)
{
- if (communicationsServer == null) throw new ArgumentNullException("communicationsServer");
- if (osName == null) throw new ArgumentNullException("osName");
- if (osName.Length == 0) throw new ArgumentException("osName cannot be an empty string.", "osName");
- if (osVersion == null) throw new ArgumentNullException("osVersion");
- if (osVersion.Length == 0) throw new ArgumentException("osVersion cannot be an empty string.", "osName");
+ if (communicationsServer == null) throw new ArgumentNullException(nameof(communicationsServer));
+ if (osName == null) throw new ArgumentNullException(nameof(osName));
+ if (osName.Length == 0) throw new ArgumentException("osName cannot be an empty string.", nameof(osName));
+ if (osVersion == null) throw new ArgumentNullException(nameof(osVersion));
+ if (osVersion.Length == 0) throw new ArgumentException("osVersion cannot be an empty string.", nameof(osName));
_SupportPnpRootDevice = true;
_timerFactory = timerFactory;
@@ -81,7 +81,7 @@ namespace Rssdp.Infrastructure
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "t", Justification = "Capture task to local variable supresses compiler warning, but task is not really needed.")]
public void AddDevice(SsdpRootDevice device)
{
- if (device == null) throw new ArgumentNullException("device");
+ if (device == null) throw new ArgumentNullException(nameof(device));
ThrowIfDisposed();
@@ -116,7 +116,7 @@ namespace Rssdp.Infrastructure
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="device"/> argument is null.</exception>
public async Task RemoveDevice(SsdpRootDevice device)
{
- if (device == null) throw new ArgumentNullException("device");
+ if (device == null) throw new ArgumentNullException(nameof(device));
bool wasRemoved = false;
TimeSpan minCacheTime = TimeSpan.Zero;