mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-05 07:18:47 +01:00
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.");
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user