diff --git a/Emby.Dlna/ConnectionManager/ServiceActionListBuilder.cs b/Emby.Dlna/ConnectionManager/ServiceActionListBuilder.cs index d42184f8ea..674bc4c8ee 100644 --- a/Emby.Dlna/ConnectionManager/ServiceActionListBuilder.cs +++ b/Emby.Dlna/ConnectionManager/ServiceActionListBuilder.cs @@ -77,7 +77,7 @@ namespace Emby.Dlna.ConnectionManager return action; } - + private static ServiceAction GetCurrentConnectionInfo() { var action = new ServiceAction diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs index aa4bb61279..45d4593de2 100644 --- a/Emby.Naming/Video/VideoListResolver.cs +++ b/Emby.Naming/Video/VideoListResolver.cs @@ -1,4 +1,4 @@ -using Emby.Naming.Common; +using Emby.Naming.Common; using System; using System.Collections.Generic; using System.IO; @@ -236,7 +236,7 @@ namespace Emby.Naming.Video if (testFilename.StartsWith(folderName, StringComparison.OrdinalIgnoreCase)) { testFilename = testFilename.Substring(folderName.Length).Trim(); - return testFilename.StartsWith("-", StringComparison.OrdinalIgnoreCase)||Regex.Replace(testFilename, @"\[([^]]*)\]", "").Trim() == string.Empty; + return testFilename.StartsWith("-", StringComparison.OrdinalIgnoreCase) || Regex.Replace(testFilename, @"\[([^]]*)\]", "").Trim() == string.Empty; } return false; diff --git a/Emby.Server.Implementations/Devices/DeviceId.cs b/Emby.Server.Implementations/Devices/DeviceId.cs index 5630d7d3ce..4f5950ac73 100644 --- a/Emby.Server.Implementations/Devices/DeviceId.cs +++ b/Emby.Server.Implementations/Devices/DeviceId.cs @@ -89,9 +89,10 @@ namespace Emby.Server.Implementations.Devices public DeviceId(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem) { - if (fileSystem == null) { - throw new ArgumentNullException(nameof(fileSystem)); - } + if (fileSystem == null) + { + throw new ArgumentNullException(nameof(fileSystem)); + } _appPaths = appPaths; _logger = logger; diff --git a/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs b/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs index dbc7b16a22..7397d4b60f 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -332,7 +332,7 @@ namespace Emby.Server.Implementations.LiveTv { try { - dto.ParentBackdropImageTags = new [] + dto.ParentBackdropImageTags = new[] { _imageProcessor.GetImageCacheTag(program, image) }; diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs index 1a33154f87..fd78dfa8e7 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs @@ -207,7 +207,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun throw new ArgumentNullException(nameof(buffer)); if (offset + count < 0) - throw new ArgumentOutOfRangeException(nameof(offset),"offset + count must not be negative"); + throw new ArgumentOutOfRangeException(nameof(offset), "offset + count must not be negative"); if (offset + count > buffer.Length) throw new ArgumentException("offset + count must not be greater than the length of buffer"); diff --git a/Emby.Server.Implementations/Playlists/PlaylistManager.cs b/Emby.Server.Implementations/Playlists/PlaylistManager.cs index a5fa24fc82..38fbac0309 100644 --- a/Emby.Server.Implementations/Playlists/PlaylistManager.cs +++ b/Emby.Server.Implementations/Playlists/PlaylistManager.cs @@ -459,7 +459,7 @@ namespace Emby.Server.Implementations.Playlists { if (string.IsNullOrEmpty(folderPath)) { - throw new ArgumentException("Folder path was null or empty.",nameof(folderPath)); + throw new ArgumentException("Folder path was null or empty.", nameof(folderPath)); } if (string.IsNullOrEmpty(fileAbsolutePath)) diff --git a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 602eeb29be..c8d6f20229 100644 --- a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -29,7 +29,6 @@ namespace Emby.Server.Implementations.ScheduledTasks /// The scheduled task. public IScheduledTask ScheduledTask { get; private set; } - /// /// Gets or sets the json serializer. /// /// The json serializer. diff --git a/Emby.Server.Implementations/Services/ServicePath.cs b/Emby.Server.Implementations/Services/ServicePath.cs index 4c98a3388b..0222b3782c 100644 --- a/Emby.Server.Implementations/Services/ServicePath.cs +++ b/Emby.Server.Implementations/Services/ServicePath.cs @@ -116,7 +116,6 @@ namespace Emby.Server.Implementations.Services { if (string.IsNullOrEmpty(component)) continue; - if (StringContains(component, VariablePrefix) && component.IndexOf(ComponentSeperator) != -1) { @@ -352,7 +351,7 @@ namespace Emby.Server.Implementations.Services if (withPathInfoParts.Length != this.PathComponentsCount && !this.IsWildCardPath) { - return false; + return false; } if (!Verbs.Contains(httpMethod, StringComparer.OrdinalIgnoreCase)) diff --git a/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs b/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs index 32a8f6b457..1bbe30b955 100644 --- a/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs +++ b/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Sorting; using MediaBrowser.Model.Querying; using System; @@ -24,7 +24,7 @@ namespace Emby.Server.Implementations.Sorting return hasSeries != null ? hasSeries.FindSeriesSortName() : null; } - + /// /// Gets the name. /// diff --git a/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/StringExtensions.cs b/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/StringExtensions.cs index c60757c02e..5db68bbf1c 100644 --- a/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/StringExtensions.cs +++ b/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/StringExtensions.cs @@ -1,25 +1,25 @@ -using System; +using System; namespace NLangDetect.Core.Extensions { - public static class StringExtensions - { - /// - /// Returns a new character sequence that is a subsequence of this sequence. The subsequence starts with the character at the specified index and ends with the character at index end - 1. The length of the returned sequence is end - start, so if start == end then an empty sequence is returned. - /// - /// - /// the start index, inclusive - /// the end index, exclusive - /// the specified subsequence - /// if start or end are negative, if end is greater than length(), or if start is greater than end - public static string SubSequence(this string s, int start, int end) + public static class StringExtensions { - if (start < 0) throw new ArgumentOutOfRangeException(nameof(start), "Argument must not be negative."); - if (end < 0) throw new ArgumentOutOfRangeException(nameof(end), "Argument must not be negative."); - if (end > s.Length) throw new ArgumentOutOfRangeException(nameof(end), "Argument must not be greater than the input string's length."); - if (start > end) throw new ArgumentOutOfRangeException(nameof(start), "Argument must not be greater than the 'end' argument."); - - return s.Substring(start, end - start); + /// + /// Returns a new character sequence that is a subsequence of this sequence. The subsequence starts with the character at the specified index and ends with the character at index end - 1. The length of the returned sequence is end - start, so if start == end then an empty sequence is returned. + /// + /// + /// the start index, inclusive + /// the end index, exclusive + /// the specified subsequence + /// if start or end are negative, if end is greater than length(), or if start is greater than end + public static string SubSequence(this string s, int start, int end) + { + if (start < 0) throw new ArgumentOutOfRangeException(nameof(start), "Argument must not be negative."); + if (end < 0) throw new ArgumentOutOfRangeException(nameof(end), "Argument must not be negative."); + if (end > s.Length) throw new ArgumentOutOfRangeException(nameof(end), "Argument must not be greater than the input string's length."); + if (start > end) throw new ArgumentOutOfRangeException(nameof(start), "Argument must not be greater than the 'end' argument."); + + return s.Substring(start, end - start); + } } - } } diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 2e423c31e0..ba7f7070b6 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Dlna; @@ -595,8 +595,10 @@ namespace MediaBrowser.Api.Playback /// The stream request. private void ParseStreamOptions(StreamRequest request) { - foreach (var param in Request.QueryString) { - if (char.IsLower(param.Name[0])) { + foreach (var param in Request.QueryString) + { + if (char.IsLower(param.Name[0])) + { // This was probably not parsed initially and should be a StreamOptions // TODO: This should be incorporated either in the lower framework for parsing requests // or the generated URL should correctly serialize it diff --git a/MediaBrowser.Controller/Entities/PeopleHelper.cs b/MediaBrowser.Controller/Entities/PeopleHelper.cs index 1f670b7528..d09ef3a15f 100644 --- a/MediaBrowser.Controller/Entities/PeopleHelper.cs +++ b/MediaBrowser.Controller/Entities/PeopleHelper.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Entities; using System; using System.Collections.Generic; using System.Linq; @@ -16,7 +16,7 @@ namespace MediaBrowser.Controller.Entities if (string.IsNullOrEmpty(person.Name)) { - throw new ArgumentException("The person's name was empty or null.",nameof(person)); + throw new ArgumentException("The person's name was empty or null.", nameof(person)); } // Normalize diff --git a/MediaBrowser.Controller/Library/ItemResolveArgs.cs b/MediaBrowser.Controller/Library/ItemResolveArgs.cs index 387540b812..4d1a4ed2f5 100644 --- a/MediaBrowser.Controller/Library/ItemResolveArgs.cs +++ b/MediaBrowser.Controller/Library/ItemResolveArgs.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Providers; using System; using System.Collections.Generic; @@ -155,7 +155,7 @@ namespace MediaBrowser.Controller.Library { if (string.IsNullOrEmpty(path)) { - throw new ArgumentException("The path was empty or null.",nameof(path)); + throw new ArgumentException("The path was empty or null.", nameof(path)); } if (AdditionalLocations == null) diff --git a/MediaBrowser.Providers/Omdb/OmdbProvider.cs b/MediaBrowser.Providers/Omdb/OmdbProvider.cs index 8d99f7b7f0..6aca093ecf 100644 --- a/MediaBrowser.Providers/Omdb/OmdbProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbProvider.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Model.IO; +using MediaBrowser.Model.IO; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; @@ -320,7 +320,7 @@ namespace MediaBrowser.Providers.Omdb { if (string.IsNullOrWhiteSpace(seriesImdbId)) { - throw new ArgumentException("The series IMDb ID was null or whitespace.",nameof(seriesImdbId)); + throw new ArgumentException("The series IMDb ID was null or whitespace.", nameof(seriesImdbId)); } var imdbParam = seriesImdbId.StartsWith("tt", StringComparison.OrdinalIgnoreCase) ? seriesImdbId : "tt" + seriesImdbId; diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index 4fdba39fa3..5390f50495 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; @@ -65,7 +65,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers if (string.IsNullOrEmpty(metadataFile)) { - throw new ArgumentException("The metadata file was empty or null.",nameof(metadataFile)); + throw new ArgumentException("The metadata file was empty or null.", nameof(metadataFile)); } var settings = XmlReaderSettingsFactory.Create(false); diff --git a/RSSDP/DeviceEventArgs.cs b/RSSDP/DeviceEventArgs.cs index 0212d1d7ce..55b23b68c9 100644 --- a/RSSDP/DeviceEventArgs.cs +++ b/RSSDP/DeviceEventArgs.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; @@ -18,14 +18,14 @@ namespace Rssdp #region Constructors - /// - /// Constructs a new instance for the specified . - /// - /// The associated with the event this argument class is being used for. - /// Thrown if the argument is null. - public DeviceEventArgs(SsdpDevice device) - { - if (device == null) throw new ArgumentNullException(nameof(device)); + /// + /// Constructs a new instance for the specified . + /// + /// The associated with the event this argument class is being used for. + /// Thrown if the argument is null. + public DeviceEventArgs(SsdpDevice device) + { + if (device == null) throw new ArgumentNullException(nameof(device)); _Device = device; } diff --git a/RSSDP/DeviceUnavailableEventArgs.cs b/RSSDP/DeviceUnavailableEventArgs.cs index e01248fa5b..ecba7c0132 100644 --- a/RSSDP/DeviceUnavailableEventArgs.cs +++ b/RSSDP/DeviceUnavailableEventArgs.cs @@ -1,59 +1,59 @@ -using System; +using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace Rssdp { - /// - /// Event arguments for the event. - /// - public sealed class DeviceUnavailableEventArgs : EventArgs - { - - #region Fields - - private readonly DiscoveredSsdpDevice _DiscoveredDevice; - private readonly bool _Expired; - - #endregion - - #region Constructors - - /// - /// Full constructor. - /// - /// A instance representing the device that has become unavailable. - /// A boolean value indicating whether this device is unavailable because it expired, or because it explicitly sent a byebye notification.. See for more detail. - /// Thrown if the parameter is null. - public DeviceUnavailableEventArgs(DiscoveredSsdpDevice discoveredDevice, bool expired) - { - if (discoveredDevice == null) throw new ArgumentNullException(nameof(discoveredDevice)); - - _DiscoveredDevice = discoveredDevice; - _Expired = expired; - } - - #endregion - - #region Public Properties - - /// - /// Returns true if the device is considered unavailable because it's cached information expired before a new alive notification or search result was received. Returns false if the device is unavailable because it sent an explicit notification of it's unavailability. - /// - public bool Expired - { - get { return _Expired; } - } - - /// - /// A reference to a instance containing the discovery details of the removed device. - /// - public DiscoveredSsdpDevice DiscoveredDevice - { - get { return _DiscoveredDevice; } - } - - #endregion - } -} \ No newline at end of file + /// + /// Event arguments for the event. + /// + public sealed class DeviceUnavailableEventArgs : EventArgs + { + + #region Fields + + private readonly DiscoveredSsdpDevice _DiscoveredDevice; + private readonly bool _Expired; + + #endregion + + #region Constructors + + /// + /// Full constructor. + /// + /// A instance representing the device that has become unavailable. + /// A boolean value indicating whether this device is unavailable because it expired, or because it explicitly sent a byebye notification.. See for more detail. + /// Thrown if the parameter is null. + public DeviceUnavailableEventArgs(DiscoveredSsdpDevice discoveredDevice, bool expired) + { + if (discoveredDevice == null) throw new ArgumentNullException(nameof(discoveredDevice)); + + _DiscoveredDevice = discoveredDevice; + _Expired = expired; + } + + #endregion + + #region Public Properties + + /// + /// Returns true if the device is considered unavailable because it's cached information expired before a new alive notification or search result was received. Returns false if the device is unavailable because it sent an explicit notification of it's unavailability. + /// + public bool Expired + { + get { return _Expired; } + } + + /// + /// A reference to a instance containing the discovery details of the removed device. + /// + public DiscoveredSsdpDevice DiscoveredDevice + { + get { return _DiscoveredDevice; } + } + + #endregion + } +} diff --git a/RSSDP/HttpRequestParser.cs b/RSSDP/HttpRequestParser.cs index 7d611dea86..1af7f0d515 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; @@ -8,70 +8,70 @@ using System.Threading.Tasks; namespace Rssdp.Infrastructure { - /// - /// Parses a string into a or throws an exception. - /// - public sealed class HttpRequestParser : HttpParserBase - { - - #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" - }; - - #endregion - - #region Public Methods - - /// - /// Parses the specified data into a instance. - /// - /// A string containing the data to parse. - /// A instance containing the parsed data. - public override System.Net.Http.HttpRequestMessage Parse(string data) - { - System.Net.Http.HttpRequestMessage retVal = null; - - try - { - retVal = new System.Net.Http.HttpRequestMessage(); - - Parse(retVal, retVal.Headers, data); - - return retVal; - } - finally - { - if (retVal != null) - retVal.Dispose(); - } - } - - #endregion - - #region Overrides - - /// - /// Used to parse the first line of an HTTP request or response and assign the values to the appropriate properties on the . - /// - /// The first line of the HTTP message to be parsed. - /// Either a or to assign the parsed values to. - protected override void ParseStatusLine(string data, HttpRequestMessage 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.", nameof(data)); - - message.Method = new HttpMethod(parts[0].Trim()); - Uri requestUri; - if (Uri.TryCreate(parts[1].Trim(), UriKind.RelativeOrAbsolute, out requestUri)) - message.RequestUri = requestUri; - else - System.Diagnostics.Debug.WriteLine(parts[1]); + /// + /// Parses a string into a or throws an exception. + /// + public sealed class HttpRequestParser : HttpParserBase + { + + #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" + }; + + #endregion + + #region Public Methods + + /// + /// Parses the specified data into a instance. + /// + /// A string containing the data to parse. + /// A instance containing the parsed data. + public override System.Net.Http.HttpRequestMessage Parse(string data) + { + System.Net.Http.HttpRequestMessage retVal = null; + + try + { + retVal = new System.Net.Http.HttpRequestMessage(); + + Parse(retVal, retVal.Headers, data); + + return retVal; + } + finally + { + if (retVal != null) + retVal.Dispose(); + } + } + + #endregion + + #region Overrides + + /// + /// Used to parse the first line of an HTTP request or response and assign the values to the appropriate properties on the . + /// + /// The first line of the HTTP message to be parsed. + /// Either a or to assign the parsed values to. + protected override void ParseStatusLine(string data, HttpRequestMessage 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.", nameof(data)); + + message.Method = new HttpMethod(parts[0].Trim()); + Uri requestUri; + if (Uri.TryCreate(parts[1].Trim(), UriKind.RelativeOrAbsolute, out requestUri)) + message.RequestUri = requestUri; + else + System.Diagnostics.Debug.WriteLine(parts[1]); if (parts.Length >= 3) { diff --git a/RSSDP/HttpResponseParser.cs b/RSSDP/HttpResponseParser.cs index 9c1373f746..d864a8bb74 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; @@ -8,82 +8,82 @@ using System.Threading.Tasks; namespace Rssdp.Infrastructure { - /// - /// Parses a string into a or throws an exception. - /// - public sealed class HttpResponseParser : HttpParserBase - { - - #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" - }; - - #endregion - - #region Public Methods - - /// - /// Parses the specified data into a instance. - /// - /// A string containing the data to parse. - /// A instance containing the parsed data. - public override HttpResponseMessage Parse(string data) - { - System.Net.Http.HttpResponseMessage retVal = null; - try - { - retVal = new System.Net.Http.HttpResponseMessage(); - - Parse(retVal, retVal.Headers, data); - - return retVal; - } - catch - { - if (retVal != null) - retVal.Dispose(); - - throw; - } - } - - #endregion - - #region Overrides Methods - - /// - /// Returns a boolean indicating whether the specified HTTP header name represents a content header (true), or a message header (false). - /// - /// A string containing the name of the header to return the type of. - /// A boolean, true if th specified header relates to HTTP content, otherwise false. - protected override bool IsContentHeader(string headerName) - { - return ContentHeaderNames.Contains(headerName, StringComparer.OrdinalIgnoreCase); - } - - /// - /// Used to parse the first line of an HTTP request or response and assign the values to the appropriate properties on the . - /// - /// The first line of the HTTP message to be parsed. - /// Either a or to assign the parsed values to. - protected override void ParseStatusLine(string data, HttpResponseMessage 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.", 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.", nameof(data)); - - message.StatusCode = (HttpStatusCode)statusCode; + /// + /// Parses a string into a or throws an exception. + /// + public sealed class HttpResponseParser : HttpParserBase + { + + #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" + }; + + #endregion + + #region Public Methods + + /// + /// Parses the specified data into a instance. + /// + /// A string containing the data to parse. + /// A instance containing the parsed data. + public override HttpResponseMessage Parse(string data) + { + System.Net.Http.HttpResponseMessage retVal = null; + try + { + retVal = new System.Net.Http.HttpResponseMessage(); + + Parse(retVal, retVal.Headers, data); + + return retVal; + } + catch + { + if (retVal != null) + retVal.Dispose(); + + throw; + } + } + + #endregion + + #region Overrides Methods + + /// + /// Returns a boolean indicating whether the specified HTTP header name represents a content header (true), or a message header (false). + /// + /// A string containing the name of the header to return the type of. + /// A boolean, true if th specified header relates to HTTP content, otherwise false. + protected override bool IsContentHeader(string headerName) + { + return ContentHeaderNames.Contains(headerName, StringComparer.OrdinalIgnoreCase); + } + + /// + /// Used to parse the first line of an HTTP request or response and assign the values to the appropriate properties on the . + /// + /// The first line of the HTTP message to be parsed. + /// Either a or to assign the parsed values to. + protected override void ParseStatusLine(string data, HttpResponseMessage 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.", 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.", nameof(data)); + + message.StatusCode = (HttpStatusCode)statusCode; if (parts.Length >= 3) { diff --git a/RSSDP/IEnumerableExtensions.cs b/RSSDP/IEnumerableExtensions.cs index 950d561b05..c96542dca4 100644 --- a/RSSDP/IEnumerableExtensions.cs +++ b/RSSDP/IEnumerableExtensions.cs @@ -1,16 +1,16 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Rssdp.Infrastructure { - internal static class IEnumerableExtensions - { - public static IEnumerable SelectManyRecursive(this IEnumerable source, Func> selector) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (selector == null) throw new ArgumentNullException(nameof(selector)); + internal static class IEnumerableExtensions + { + public static IEnumerable SelectManyRecursive(this IEnumerable source, Func> selector) + { + if (source == null) throw new ArgumentNullException(nameof(source)); + if (selector == null) throw new ArgumentNullException(nameof(selector)); return !source.Any() ? source : source.Concat(