diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2019-01-13 12:14:53 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-13 12:14:53 -0500 |
| commit | 9dcaafe700b7130b49bafbadf0d47b37c6ecf53b (patch) | |
| tree | 6ca1b2b3decac1a86b886dafd2645954a13601fd /RSSDP | |
| parent | 17d8de4962ea9d78f6ddb557fe26465be1944b38 (diff) | |
| parent | b936c439321b55bf89c99dac96fc78cefe752e84 (diff) | |
Merge pull request #458 from EraYaN/code-cleanup
Clean up several minor issues and add TODOs
Diffstat (limited to 'RSSDP')
| -rw-r--r-- | RSSDP/DeviceAvailableEventArgs.cs | 87 | ||||
| -rw-r--r-- | RSSDP/DeviceEventArgs.cs | 4 | ||||
| -rw-r--r-- | RSSDP/DeviceUnavailableEventArgs.cs | 4 | ||||
| -rw-r--r-- | RSSDP/HttpParserBase.cs | 10 | ||||
| -rw-r--r-- | RSSDP/HttpRequestParser.cs | 14 | ||||
| -rw-r--r-- | RSSDP/HttpResponseParser.cs | 16 | ||||
| -rw-r--r-- | RSSDP/IEnumerableExtensions.cs | 6 | ||||
| -rw-r--r-- | RSSDP/Properties/AssemblyInfo.cs | 26 | ||||
| -rw-r--r-- | RSSDP/SsdpCommunicationsServer.cs | 8 | ||||
| -rw-r--r-- | RSSDP/SsdpDevice.cs | 4 | ||||
| -rw-r--r-- | RSSDP/SsdpDeviceLocator.cs | 6 | ||||
| -rw-r--r-- | RSSDP/SsdpDevicePublisher.cs | 14 |
12 files changed, 97 insertions, 102 deletions
diff --git a/RSSDP/DeviceAvailableEventArgs.cs b/RSSDP/DeviceAvailableEventArgs.cs index fe1c81566..edc8687e9 100644 --- a/RSSDP/DeviceAvailableEventArgs.cs +++ b/RSSDP/DeviceAvailableEventArgs.cs @@ -16,46 +16,47 @@ namespace Rssdp #region Fields private readonly DiscoveredSsdpDevice _DiscoveredDevice; - private readonly bool _IsNewlyDiscovered; - - #endregion - - #region Constructors - - /// <summary> - /// Full constructor. - /// </summary> - /// <param name="discoveredDevice">A <see cref="DiscoveredSsdpDevice"/> instance representing the available device.</param> - /// <param name="isNewlyDiscovered">A boolean value indicating whether or not this device came from the cache. See <see cref="IsNewlyDiscovered"/> for more detail.</param> - /// <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"); - - _DiscoveredDevice = discoveredDevice; - _IsNewlyDiscovered = isNewlyDiscovered; - } - - #endregion - - #region Public Properties - - /// <summary> - /// Returns true if the device was discovered due to an alive notification, or a search and was not already in the cache. Returns false if the item came from the cache but matched the current search request. - /// </summary> - public bool IsNewlyDiscovered - { - get { return _IsNewlyDiscovered; } - } - - /// <summary> - /// A reference to a <see cref="Rssdp.DiscoveredSsdpDevice"/> instance containing the discovered details and allowing access to the full device description. - /// </summary> - public DiscoveredSsdpDevice DiscoveredDevice - { - get { return _DiscoveredDevice; } - } - - #endregion - } -} + private readonly bool _IsNewlyDiscovered; + + #endregion + + #region Constructors + + /// <summary> + /// Full constructor. + /// </summary> + /// <param name="discoveredDevice">A <see cref="DiscoveredSsdpDevice"/> instance representing the available device.</param> + /// <param name="isNewlyDiscovered">A boolean value indicating whether or not this device came from the cache. See <see cref="IsNewlyDiscovered"/> for more detail.</param> + /// <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(nameof(discoveredDevice)); + + _DiscoveredDevice = discoveredDevice; + _IsNewlyDiscovered = isNewlyDiscovered; + } + + #endregion + + #region Public Properties + + /// <summary> + /// Returns true if the device was discovered due to an alive notification, or a search and was not already in the cache. Returns false if the item came from the cache but matched the current search request. + /// </summary> + public bool IsNewlyDiscovered + { + get { return _IsNewlyDiscovered; } + } + + /// <summary> + /// A reference to a <see cref="Rssdp.DiscoveredSsdpDevice"/> instance containing the discovered details and allowing access to the full device description. + /// </summary> + public DiscoveredSsdpDevice DiscoveredDevice + { + get { return _DiscoveredDevice; } + } + + #endregion + + } +}
\ No newline at end of file diff --git a/RSSDP/DeviceEventArgs.cs b/RSSDP/DeviceEventArgs.cs index 5fd441041..55b23b68c 100644 --- a/RSSDP/DeviceEventArgs.cs +++ b/RSSDP/DeviceEventArgs.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; @@ -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 1190cfc81..ecba7c013 100644 --- a/RSSDP/DeviceUnavailableEventArgs.cs +++ b/RSSDP/DeviceUnavailableEventArgs.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; @@ -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 8b027ebd5..1af7f0d51 100644 --- a/RSSDP/HttpRequestParser.cs +++ b/RSSDP/HttpRequestParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -17,9 +17,9 @@ namespace Rssdp.Infrastructure #region Fields & Constants private readonly string[] ContentHeaderNames = new string[] - { - "Allow", "Content-Disposition", "Content-Encoding", "Content-Language", "Content-Length", "Content-Location", "Content-MD5", "Content-Range", "Content-Type", "Expires", "Last-Modified" - }; + { + "Allow", "Content-Disposition", "Content-Encoding", "Content-Language", "Content-Length", "Content-Location", "Content-MD5", "Content-Range", "Content-Type", "Expires", "Last-Modified" + }; #endregion @@ -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 cbd5517b8..d864a8bb7 100644 --- a/RSSDP/HttpResponseParser.cs +++ b/RSSDP/HttpResponseParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -17,9 +17,9 @@ namespace Rssdp.Infrastructure #region Fields & Constants private readonly string[] ContentHeaderNames = new string[] - { - "Allow", "Content-Disposition", "Content-Encoding", "Content-Language", "Content-Length", "Content-Location", "Content-MD5", "Content-Range", "Content-Type", "Expires", "Last-Modified" - }; + { + "Allow", "Content-Disposition", "Content-Encoding", "Content-Language", "Content-Length", "Content-Location", "Content-MD5", "Content-Range", "Content-Type", "Expires", "Last-Modified" + }; #endregion @@ -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 85a72c01d..c96542dca 100644 --- a/RSSDP/IEnumerableExtensions.cs +++ b/RSSDP/IEnumerableExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -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 f0584fa1a..7098279b4 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 e2e5c4e9f..5fc524428 100644 --- a/RSSDP/SsdpCommunicationsServer.cs +++ b/RSSDP/SsdpCommunicationsServer.cs @@ -86,8 +86,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(); @@ -157,7 +157,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(); @@ -242,7 +242,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 865084d05..4508e4f34 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 c7daf359d..0a092e6b0 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 30e1c5a0b..a44dd0c0c 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; |
