diff options
| author | Erwin de Haan <EraYaN@users.noreply.github.com> | 2019-01-12 21:41:08 +0100 |
|---|---|---|
| committer | Erwin de Haan <EraYaN@users.noreply.github.com> | 2019-01-12 21:41:08 +0100 |
| commit | 846456b41e87c8ccced544298b80a27d0f199215 (patch) | |
| tree | 8196146818ecee84bfd5ee99ed1c5aea0402d165 | |
| parent | e2751d42e8775596b7c4b929fd004d879f980947 (diff) | |
Reformatted the files with notes.
20 files changed, 257 insertions, 256 deletions
diff --git a/Emby.Dlna/ConnectionManager/ServiceActionListBuilder.cs b/Emby.Dlna/ConnectionManager/ServiceActionListBuilder.cs index d42184f8e..674bc4c8e 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 aa4bb6127..45d4593de 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 5630d7d3c..4f5950ac7 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 dbc7b16a2..7397d4b60 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 1a33154f8..fd78dfa8e 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 a5fa24fc8..38fbac030 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 602eeb29b..c8d6f2022 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 /// <value>The scheduled task.</value> public IScheduledTask ScheduledTask { get; private set; } - /// <summary> /// Gets or sets the json serializer. /// </summary> /// <value>The json serializer.</value> diff --git a/Emby.Server.Implementations/Services/ServicePath.cs b/Emby.Server.Implementations/Services/ServicePath.cs index 4c98a3388..0222b3782 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 32a8f6b45..1bbe30b95 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; } - + /// <summary> /// Gets the name. /// </summary> diff --git a/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/StringExtensions.cs b/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/StringExtensions.cs index c60757c02..5db68bbf1 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 - { - /// <summary> - /// 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. - /// </summary> - /// <param name="s"></param> - /// <param name="start">the start index, inclusive</param> - /// <param name="end">the end index, exclusive</param> - /// <returns>the specified subsequence</returns> - /// <exception cref="IndexOutOfRangeException"> if start or end are negative, if end is greater than length(), or if start is greater than end</exception> - 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); + /// <summary> + /// 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. + /// </summary> + /// <param name="s"></param> + /// <param name="start">the start index, inclusive</param> + /// <param name="end">the end index, exclusive</param> + /// <returns>the specified subsequence</returns> + /// <exception cref="IndexOutOfRangeException"> if start or end are negative, if end is greater than length(), or if start is greater than end</exception> + 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 2e423c31e..ba7f7070b 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 /// <param name="request">The stream request.</param> 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 1f670b752..d09ef3a15 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 387540b81..4d1a4ed2f 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 8d99f7b7f..6aca093ec 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 4fdba39fa..5390f5049 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 0212d1d7c..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; @@ -18,14 +18,14 @@ namespace Rssdp #region Constructors - /// <summary> - /// Constructs a new instance for the specified <see cref="SsdpDevice"/>. - /// </summary> - /// <param name="device">The <see cref="SsdpDevice"/> associated with the event this argument class is being used for.</param> - /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="device"/> argument is null.</exception> - public DeviceEventArgs(SsdpDevice device) - { - if (device == null) throw new ArgumentNullException(nameof(device)); + /// <summary> + /// Constructs a new instance for the specified <see cref="SsdpDevice"/>. + /// </summary> + /// <param name="device">The <see cref="SsdpDevice"/> associated with the event this argument class is being used for.</param> + /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="device"/> argument is null.</exception> + 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 e01248fa5..ecba7c013 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 { - /// <summary> - /// Event arguments for the <see cref="Rssdp.Infrastructure.SsdpDeviceLocatorBase.DeviceUnavailable"/> event. - /// </summary> - public sealed class DeviceUnavailableEventArgs : EventArgs - { - - #region Fields - - private readonly DiscoveredSsdpDevice _DiscoveredDevice; - private readonly bool _Expired; - - #endregion - - #region Constructors - - /// <summary> - /// Full constructor. - /// </summary> - /// <param name="discoveredDevice">A <see cref="DiscoveredSsdpDevice"/> instance representing the device that has become unavailable.</param> - /// <param name="expired">A boolean value indicating whether this device is unavailable because it expired, or because it explicitly sent a byebye notification.. See <see cref="Expired"/> for more detail.</param> - /// <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(nameof(discoveredDevice)); - - _DiscoveredDevice = discoveredDevice; - _Expired = expired; - } - - #endregion - - #region Public Properties - - /// <summary> - /// 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. - /// </summary> - public bool Expired - { - get { return _Expired; } - } - - /// <summary> - /// A reference to a <see cref="Rssdp.DiscoveredSsdpDevice"/> instance containing the discovery details of the removed device. - /// </summary> - public DiscoveredSsdpDevice DiscoveredDevice - { - get { return _DiscoveredDevice; } - } - - #endregion - } -}
\ No newline at end of file + /// <summary> + /// Event arguments for the <see cref="Rssdp.Infrastructure.SsdpDeviceLocatorBase.DeviceUnavailable"/> event. + /// </summary> + public sealed class DeviceUnavailableEventArgs : EventArgs + { + + #region Fields + + private readonly DiscoveredSsdpDevice _DiscoveredDevice; + private readonly bool _Expired; + + #endregion + + #region Constructors + + /// <summary> + /// Full constructor. + /// </summary> + /// <param name="discoveredDevice">A <see cref="DiscoveredSsdpDevice"/> instance representing the device that has become unavailable.</param> + /// <param name="expired">A boolean value indicating whether this device is unavailable because it expired, or because it explicitly sent a byebye notification.. See <see cref="Expired"/> for more detail.</param> + /// <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(nameof(discoveredDevice)); + + _DiscoveredDevice = discoveredDevice; + _Expired = expired; + } + + #endregion + + #region Public Properties + + /// <summary> + /// 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. + /// </summary> + public bool Expired + { + get { return _Expired; } + } + + /// <summary> + /// A reference to a <see cref="Rssdp.DiscoveredSsdpDevice"/> instance containing the discovery details of the removed device. + /// </summary> + public DiscoveredSsdpDevice DiscoveredDevice + { + get { return _DiscoveredDevice; } + } + + #endregion + } +} diff --git a/RSSDP/HttpRequestParser.cs b/RSSDP/HttpRequestParser.cs index 7d611dea8..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; @@ -8,70 +8,70 @@ using System.Threading.Tasks; namespace Rssdp.Infrastructure { - /// <summary> - /// Parses a string into a <see cref="System.Net.Http.HttpRequestMessage"/> or throws an exception. - /// </summary> - public sealed class HttpRequestParser : HttpParserBase<HttpRequestMessage> - { - - #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 - - /// <summary> - /// Parses the specified data into a <see cref="System.Net.Http.HttpRequestMessage"/> instance. - /// </summary> - /// <param name="data">A string containing the data to parse.</param> - /// <returns>A <see cref="System.Net.Http.HttpRequestMessage"/> instance containing the parsed data.</returns> - 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 - - /// <summary> - /// Used to parse the first line of an HTTP request or response and assign the values to the appropriate properties on the <paramref name="message"/>. - /// </summary> - /// <param name="data">The first line of the HTTP message to be parsed.</param> - /// <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(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]); + /// <summary> + /// Parses a string into a <see cref="System.Net.Http.HttpRequestMessage"/> or throws an exception. + /// </summary> + public sealed class HttpRequestParser : HttpParserBase<HttpRequestMessage> + { + + #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 + + /// <summary> + /// Parses the specified data into a <see cref="System.Net.Http.HttpRequestMessage"/> instance. + /// </summary> + /// <param name="data">A string containing the data to parse.</param> + /// <returns>A <see cref="System.Net.Http.HttpRequestMessage"/> instance containing the parsed data.</returns> + 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 + + /// <summary> + /// Used to parse the first line of an HTTP request or response and assign the values to the appropriate properties on the <paramref name="message"/>. + /// </summary> + /// <param name="data">The first line of the HTTP message to be parsed.</param> + /// <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(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 9c1373f74..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; @@ -8,82 +8,82 @@ using System.Threading.Tasks; namespace Rssdp.Infrastructure { - /// <summary> - /// Parses a string into a <see cref="System.Net.Http.HttpResponseMessage"/> or throws an exception. - /// </summary> - public sealed class HttpResponseParser : HttpParserBase<System.Net.Http.HttpResponseMessage> - { - - #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 - - /// <summary> - /// Parses the specified data into a <see cref="System.Net.Http.HttpResponseMessage"/> instance. - /// </summary> - /// <param name="data">A string containing the data to parse.</param> - /// <returns>A <see cref="System.Net.Http.HttpResponseMessage"/> instance containing the parsed data.</returns> - 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 - - /// <summary> - /// Returns a boolean indicating whether the specified HTTP header name represents a content header (true), or a message header (false). - /// </summary> - /// <param name="headerName">A string containing the name of the header to return the type of.</param> - /// <returns>A boolean, true if th specified header relates to HTTP content, otherwise false.</returns> - protected override bool IsContentHeader(string headerName) - { - return ContentHeaderNames.Contains(headerName, StringComparer.OrdinalIgnoreCase); - } - - /// <summary> - /// Used to parse the first line of an HTTP request or response and assign the values to the appropriate properties on the <paramref name="message"/>. - /// </summary> - /// <param name="data">The first line of the HTTP message to be parsed.</param> - /// <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(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; + /// <summary> + /// Parses a string into a <see cref="System.Net.Http.HttpResponseMessage"/> or throws an exception. + /// </summary> + public sealed class HttpResponseParser : HttpParserBase<System.Net.Http.HttpResponseMessage> + { + + #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 + + /// <summary> + /// Parses the specified data into a <see cref="System.Net.Http.HttpResponseMessage"/> instance. + /// </summary> + /// <param name="data">A string containing the data to parse.</param> + /// <returns>A <see cref="System.Net.Http.HttpResponseMessage"/> instance containing the parsed data.</returns> + 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 + + /// <summary> + /// Returns a boolean indicating whether the specified HTTP header name represents a content header (true), or a message header (false). + /// </summary> + /// <param name="headerName">A string containing the name of the header to return the type of.</param> + /// <returns>A boolean, true if th specified header relates to HTTP content, otherwise false.</returns> + protected override bool IsContentHeader(string headerName) + { + return ContentHeaderNames.Contains(headerName, StringComparer.OrdinalIgnoreCase); + } + + /// <summary> + /// Used to parse the first line of an HTTP request or response and assign the values to the appropriate properties on the <paramref name="message"/>. + /// </summary> + /// <param name="data">The first line of the HTTP message to be parsed.</param> + /// <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(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 950d561b0..c96542dca 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<T> SelectManyRecursive<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> selector) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (selector == null) throw new ArgumentNullException(nameof(selector)); + internal static class IEnumerableExtensions + { + public static IEnumerable<T> SelectManyRecursive<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> selector) + { + if (source == null) throw new ArgumentNullException(nameof(source)); + if (selector == null) throw new ArgumentNullException(nameof(selector)); return !source.Any() ? source : source.Concat( |
