From ec1f5dc317182582ebff843c9e8a4d5277405469 Mon Sep 17 00:00:00 2001 From: Erwin de Haan Date: Sun, 6 Jan 2019 21:50:43 +0100 Subject: 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. --- .../Sorting/AiredEpisodeOrderComparer.cs | 23 ++++++++++++++-------- .../Sorting/AlbumArtistComparer.cs | 9 +++------ .../Sorting/AlbumComparer.cs | 7 ++----- .../Sorting/ArtistComparer.cs | 7 ++----- .../Sorting/CommunityRatingComparer.cs | 12 +++++++---- .../Sorting/CriticRatingComparer.cs | 7 ++----- .../Sorting/DateCreatedComparer.cs | 11 +++++++---- .../Sorting/DateLastMediaAddedComparer.cs | 9 +++------ .../Sorting/DatePlayedComparer.cs | 5 +---- .../Sorting/GameSystemComparer.cs | 7 ++----- .../Sorting/IsFavoriteOrLikeComparer.cs | 5 +---- .../Sorting/IsFolderComparer.cs | 7 ++----- .../Sorting/IsPlayedComparer.cs | 5 +---- .../Sorting/IsUnplayedComparer.cs | 5 +---- .../Sorting/NameComparer.cs | 11 +++++++---- .../Sorting/OfficialRatingComparer.cs | 12 +++++++---- .../Sorting/PlayCountComparer.cs | 5 +---- .../Sorting/PlayersComparer.cs | 7 ++----- .../Sorting/PremiereDateComparer.cs | 7 ++----- .../Sorting/ProductionYearComparer.cs | 7 ++----- .../Sorting/RandomComparer.cs | 5 +---- .../Sorting/RuntimeComparer.cs | 12 +++++++---- .../Sorting/SeriesSortNameComparer.cs | 9 +++------ .../Sorting/SortNameComparer.cs | 11 +++++++---- .../Sorting/StartDateComparer.cs | 7 ++----- .../Sorting/StudioComparer.cs | 11 +++++++---- 26 files changed, 100 insertions(+), 123 deletions(-) (limited to 'Emby.Server.Implementations/Sorting') diff --git a/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs b/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs index 494668cb9..1b2974c27 100644 --- a/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs +++ b/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Sorting; using MediaBrowser.Model.Querying; @@ -16,6 +16,16 @@ namespace Emby.Server.Implementations.Sorting /// System.Int32. public int Compare(BaseItem x, BaseItem y) { + if (x == null) + { + throw new ArgumentNullException(nameof(x)); + } + + if (y == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.PremiereDate.HasValue && y.PremiereDate.HasValue) { var val = DateTime.Compare(x.PremiereDate.Value, y.PremiereDate.Value); @@ -70,7 +80,7 @@ namespace Emby.Server.Implementations.Sorting return CompareEpisodeToSpecial(y, x) * -1; } - private int CompareEpisodeToSpecial(Episode x, Episode y) + private static int CompareEpisodeToSpecial(Episode x, Episode y) { // http://thetvdb.com/wiki/index.php?title=Special_Episodes @@ -119,7 +129,7 @@ namespace Emby.Server.Implementations.Sorting return GetSpecialCompareValue(x).CompareTo(GetSpecialCompareValue(y)); } - private int GetSpecialCompareValue(Episode item) + private static int GetSpecialCompareValue(Episode item) { // First sort by season number // Since there are three sort orders, pad with 9 digits (3 for each, figure 1000 episode buffer should be enough) @@ -140,7 +150,7 @@ namespace Emby.Server.Implementations.Sorting return val; } - private int CompareEpisodes(Episode x, Episode y) + private static int CompareEpisodes(Episode x, Episode y) { var xValue = (x.ParentIndexNumber ?? -1) * 1000 + (x.IndexNumber ?? -1); var yValue = (y.ParentIndexNumber ?? -1) * 1000 + (y.IndexNumber ?? -1); @@ -152,9 +162,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.AiredEpisodeOrder; } - } + public string Name => ItemSortBy.AiredEpisodeOrder; } } diff --git a/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs b/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs index cd3834080..df64d816f 100644 --- a/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs +++ b/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Sorting; @@ -28,7 +28,7 @@ namespace Emby.Server.Implementations.Sorting /// /// The x. /// System.String. - private string GetValue(BaseItem x) + private static string GetValue(BaseItem x) { var audio = x as IHasAlbumArtist; @@ -39,9 +39,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.AlbumArtist; } - } + public string Name => ItemSortBy.AlbumArtist; } } diff --git a/Emby.Server.Implementations/Sorting/AlbumComparer.cs b/Emby.Server.Implementations/Sorting/AlbumComparer.cs index 68f5f173e..dda1c5478 100644 --- a/Emby.Server.Implementations/Sorting/AlbumComparer.cs +++ b/Emby.Server.Implementations/Sorting/AlbumComparer.cs @@ -27,7 +27,7 @@ namespace Emby.Server.Implementations.Sorting /// /// The x. /// System.String. - private string GetValue(BaseItem x) + private static string GetValue(BaseItem x) { var audio = x as Audio; @@ -38,9 +38,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.Album; } - } + public string Name => ItemSortBy.Album; } } diff --git a/Emby.Server.Implementations/Sorting/ArtistComparer.cs b/Emby.Server.Implementations/Sorting/ArtistComparer.cs index 616aff673..b0f0549e3 100644 --- a/Emby.Server.Implementations/Sorting/ArtistComparer.cs +++ b/Emby.Server.Implementations/Sorting/ArtistComparer.cs @@ -27,7 +27,7 @@ namespace Emby.Server.Implementations.Sorting /// /// The x. /// System.String. - private string GetValue(BaseItem x) + private static string GetValue(BaseItem x) { var audio = x as Audio; @@ -43,9 +43,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.Artist; } - } + public string Name => ItemSortBy.Artist; } } diff --git a/Emby.Server.Implementations/Sorting/CommunityRatingComparer.cs b/Emby.Server.Implementations/Sorting/CommunityRatingComparer.cs index 396bbbdb9..994759171 100644 --- a/Emby.Server.Implementations/Sorting/CommunityRatingComparer.cs +++ b/Emby.Server.Implementations/Sorting/CommunityRatingComparer.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Sorting; using MediaBrowser.Model.Querying; +using System; namespace Emby.Server.Implementations.Sorting { @@ -14,6 +15,12 @@ namespace Emby.Server.Implementations.Sorting /// System.Int32. public int Compare(BaseItem x, BaseItem y) { + if (x == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null) + throw new ArgumentNullException(nameof(y)); + return (x.CommunityRating ?? 0).CompareTo(y.CommunityRating ?? 0); } @@ -21,9 +28,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.CommunityRating; } - } + public string Name => ItemSortBy.CommunityRating; } } diff --git a/Emby.Server.Implementations/Sorting/CriticRatingComparer.cs b/Emby.Server.Implementations/Sorting/CriticRatingComparer.cs index 877dbfcc1..5c4aeaf86 100644 --- a/Emby.Server.Implementations/Sorting/CriticRatingComparer.cs +++ b/Emby.Server.Implementations/Sorting/CriticRatingComparer.cs @@ -20,7 +20,7 @@ namespace Emby.Server.Implementations.Sorting return GetValue(x).CompareTo(GetValue(y)); } - private float GetValue(BaseItem x) + private static float GetValue(BaseItem x) { return x.CriticRating ?? 0; } @@ -29,9 +29,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.CriticRating; } - } + public string Name => ItemSortBy.CriticRating; } } diff --git a/Emby.Server.Implementations/Sorting/DateCreatedComparer.cs b/Emby.Server.Implementations/Sorting/DateCreatedComparer.cs index c436fcb4a..1c5149517 100644 --- a/Emby.Server.Implementations/Sorting/DateCreatedComparer.cs +++ b/Emby.Server.Implementations/Sorting/DateCreatedComparer.cs @@ -18,6 +18,12 @@ namespace Emby.Server.Implementations.Sorting /// System.Int32. public int Compare(BaseItem x, BaseItem y) { + if (x == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null) + throw new ArgumentNullException(nameof(y)); + return DateTime.Compare(x.DateCreated, y.DateCreated); } @@ -25,9 +31,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.DateCreated; } - } + public string Name => ItemSortBy.DateCreated; } } diff --git a/Emby.Server.Implementations/Sorting/DateLastMediaAddedComparer.cs b/Emby.Server.Implementations/Sorting/DateLastMediaAddedComparer.cs index fc92505ac..ffe7fbaec 100644 --- a/Emby.Server.Implementations/Sorting/DateLastMediaAddedComparer.cs +++ b/Emby.Server.Implementations/Sorting/DateLastMediaAddedComparer.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Sorting; using MediaBrowser.Model.Querying; @@ -42,7 +42,7 @@ namespace Emby.Server.Implementations.Sorting /// /// The x. /// DateTime. - private DateTime GetDate(BaseItem x) + private static DateTime GetDate(BaseItem x) { var folder = x as Folder; @@ -61,9 +61,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.DateLastContentAdded; } - } + public string Name => ItemSortBy.DateLastContentAdded; } } diff --git a/Emby.Server.Implementations/Sorting/DatePlayedComparer.cs b/Emby.Server.Implementations/Sorting/DatePlayedComparer.cs index 388d2772e..c9ae68189 100644 --- a/Emby.Server.Implementations/Sorting/DatePlayedComparer.cs +++ b/Emby.Server.Implementations/Sorting/DatePlayedComparer.cs @@ -61,9 +61,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.DatePlayed; } - } + public string Name => ItemSortBy.DatePlayed; } } diff --git a/Emby.Server.Implementations/Sorting/GameSystemComparer.cs b/Emby.Server.Implementations/Sorting/GameSystemComparer.cs index 4ee30397d..0b534b3cb 100644 --- a/Emby.Server.Implementations/Sorting/GameSystemComparer.cs +++ b/Emby.Server.Implementations/Sorting/GameSystemComparer.cs @@ -23,7 +23,7 @@ namespace Emby.Server.Implementations.Sorting /// /// The x. /// System.String. - private string GetValue(BaseItem x) + private static string GetValue(BaseItem x) { var game = x as Game; @@ -46,9 +46,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.GameSystem; } - } + public string Name => ItemSortBy.GameSystem; } } diff --git a/Emby.Server.Implementations/Sorting/IsFavoriteOrLikeComparer.cs b/Emby.Server.Implementations/Sorting/IsFavoriteOrLikeComparer.cs index 27485f09e..48e3172ce 100644 --- a/Emby.Server.Implementations/Sorting/IsFavoriteOrLikeComparer.cs +++ b/Emby.Server.Implementations/Sorting/IsFavoriteOrLikeComparer.cs @@ -38,10 +38,7 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.IsFavoriteOrLiked; } - } + public string Name => ItemSortBy.IsFavoriteOrLiked; /// /// Gets or sets the user data repository. diff --git a/Emby.Server.Implementations/Sorting/IsFolderComparer.cs b/Emby.Server.Implementations/Sorting/IsFolderComparer.cs index 756d13bd8..8b6cbb2db 100644 --- a/Emby.Server.Implementations/Sorting/IsFolderComparer.cs +++ b/Emby.Server.Implementations/Sorting/IsFolderComparer.cs @@ -22,7 +22,7 @@ namespace Emby.Server.Implementations.Sorting /// /// The x. /// System.String. - private int GetValue(BaseItem x) + private static int GetValue(BaseItem x) { return x.IsFolder ? 0 : 1; } @@ -31,9 +31,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.IsFolder; } - } + public string Name => ItemSortBy.IsFolder; } } diff --git a/Emby.Server.Implementations/Sorting/IsPlayedComparer.cs b/Emby.Server.Implementations/Sorting/IsPlayedComparer.cs index 987dc54a5..9f4fc2c06 100644 --- a/Emby.Server.Implementations/Sorting/IsPlayedComparer.cs +++ b/Emby.Server.Implementations/Sorting/IsPlayedComparer.cs @@ -38,10 +38,7 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.IsUnplayed; } - } + public string Name => ItemSortBy.IsUnplayed; /// /// Gets or sets the user data repository. diff --git a/Emby.Server.Implementations/Sorting/IsUnplayedComparer.cs b/Emby.Server.Implementations/Sorting/IsUnplayedComparer.cs index 0f4e4c37e..d145aa8dd 100644 --- a/Emby.Server.Implementations/Sorting/IsUnplayedComparer.cs +++ b/Emby.Server.Implementations/Sorting/IsUnplayedComparer.cs @@ -38,10 +38,7 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.IsUnplayed; } - } + public string Name => ItemSortBy.IsUnplayed; /// /// Gets or sets the user data repository. diff --git a/Emby.Server.Implementations/Sorting/NameComparer.cs b/Emby.Server.Implementations/Sorting/NameComparer.cs index 8ab5e5172..cfd810a6b 100644 --- a/Emby.Server.Implementations/Sorting/NameComparer.cs +++ b/Emby.Server.Implementations/Sorting/NameComparer.cs @@ -18,6 +18,12 @@ namespace Emby.Server.Implementations.Sorting /// System.Int32. public int Compare(BaseItem x, BaseItem y) { + if (x == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null) + throw new ArgumentNullException(nameof(y)); + return string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase); } @@ -25,9 +31,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.Name; } - } + public string Name => ItemSortBy.Name; } } diff --git a/Emby.Server.Implementations/Sorting/OfficialRatingComparer.cs b/Emby.Server.Implementations/Sorting/OfficialRatingComparer.cs index 3eab4fccc..cd48e3048 100644 --- a/Emby.Server.Implementations/Sorting/OfficialRatingComparer.cs +++ b/Emby.Server.Implementations/Sorting/OfficialRatingComparer.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.Sorting; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Querying; +using System; namespace Emby.Server.Implementations.Sorting { @@ -22,6 +23,12 @@ namespace Emby.Server.Implementations.Sorting /// System.Int32. public int Compare(BaseItem x, BaseItem y) { + if (x == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null) + throw new ArgumentNullException(nameof(y)); + var levelX = string.IsNullOrEmpty(x.OfficialRating) ? 0 : _localization.GetRatingLevel(x.OfficialRating) ?? 0; var levelY = string.IsNullOrEmpty(y.OfficialRating) ? 0 : _localization.GetRatingLevel(y.OfficialRating) ?? 0; @@ -32,9 +39,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.OfficialRating; } - } + public string Name => ItemSortBy.OfficialRating; } } diff --git a/Emby.Server.Implementations/Sorting/PlayCountComparer.cs b/Emby.Server.Implementations/Sorting/PlayCountComparer.cs index aecad7c58..9ed74f082 100644 --- a/Emby.Server.Implementations/Sorting/PlayCountComparer.cs +++ b/Emby.Server.Implementations/Sorting/PlayCountComparer.cs @@ -43,10 +43,7 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.PlayCount; } - } + public string Name => ItemSortBy.PlayCount; /// /// Gets or sets the user data repository. diff --git a/Emby.Server.Implementations/Sorting/PlayersComparer.cs b/Emby.Server.Implementations/Sorting/PlayersComparer.cs index 3b54517c3..5b50ea48a 100644 --- a/Emby.Server.Implementations/Sorting/PlayersComparer.cs +++ b/Emby.Server.Implementations/Sorting/PlayersComparer.cs @@ -22,7 +22,7 @@ namespace Emby.Server.Implementations.Sorting /// /// The x. /// System.String. - private int GetValue(BaseItem x) + private static int GetValue(BaseItem x) { var game = x as Game; @@ -38,9 +38,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.Players; } - } + public string Name => ItemSortBy.Players; } } diff --git a/Emby.Server.Implementations/Sorting/PremiereDateComparer.cs b/Emby.Server.Implementations/Sorting/PremiereDateComparer.cs index d7219c86f..cd712e3dc 100644 --- a/Emby.Server.Implementations/Sorting/PremiereDateComparer.cs +++ b/Emby.Server.Implementations/Sorting/PremiereDateComparer.cs @@ -26,7 +26,7 @@ namespace Emby.Server.Implementations.Sorting /// /// The x. /// DateTime. - private DateTime GetDate(BaseItem x) + private static DateTime GetDate(BaseItem x) { if (x.PremiereDate.HasValue) { @@ -51,9 +51,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.PremiereDate; } - } + public string Name => ItemSortBy.PremiereDate; } } diff --git a/Emby.Server.Implementations/Sorting/ProductionYearComparer.cs b/Emby.Server.Implementations/Sorting/ProductionYearComparer.cs index ea479419a..0aa5e833b 100644 --- a/Emby.Server.Implementations/Sorting/ProductionYearComparer.cs +++ b/Emby.Server.Implementations/Sorting/ProductionYearComparer.cs @@ -25,7 +25,7 @@ namespace Emby.Server.Implementations.Sorting /// /// The x. /// DateTime. - private int GetValue(BaseItem x) + private static int GetValue(BaseItem x) { if (x.ProductionYear.HasValue) { @@ -44,9 +44,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.ProductionYear; } - } + public string Name => ItemSortBy.ProductionYear; } } diff --git a/Emby.Server.Implementations/Sorting/RandomComparer.cs b/Emby.Server.Implementations/Sorting/RandomComparer.cs index 1fbecde56..c69ebe41a 100644 --- a/Emby.Server.Implementations/Sorting/RandomComparer.cs +++ b/Emby.Server.Implementations/Sorting/RandomComparer.cs @@ -25,9 +25,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.Random; } - } + public string Name => ItemSortBy.Random; } } diff --git a/Emby.Server.Implementations/Sorting/RuntimeComparer.cs b/Emby.Server.Implementations/Sorting/RuntimeComparer.cs index 63c4758cb..77851d702 100644 --- a/Emby.Server.Implementations/Sorting/RuntimeComparer.cs +++ b/Emby.Server.Implementations/Sorting/RuntimeComparer.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Sorting; using MediaBrowser.Model.Querying; +using System; namespace Emby.Server.Implementations.Sorting { @@ -17,6 +18,12 @@ namespace Emby.Server.Implementations.Sorting /// System.Int32. public int Compare(BaseItem x, BaseItem y) { + if (x == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null) + throw new ArgumentNullException(nameof(y)); + return (x.RunTimeTicks ?? 0).CompareTo(y.RunTimeTicks ?? 0); } @@ -24,9 +31,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.Runtime; } - } + public string Name => ItemSortBy.Runtime; } } diff --git a/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs b/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs index b441a29c1..32a8f6b45 100644 --- a/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs +++ b/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs @@ -18,20 +18,17 @@ namespace Emby.Server.Implementations.Sorting return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase); } - private string GetValue(BaseItem item) + private static string GetValue(BaseItem item) { var hasSeries = item as IHasSeries; return hasSeries != null ? hasSeries.FindSeriesSortName() : null; } - + /// /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.SeriesSortName; } - } + public string Name => ItemSortBy.SeriesSortName; } } diff --git a/Emby.Server.Implementations/Sorting/SortNameComparer.cs b/Emby.Server.Implementations/Sorting/SortNameComparer.cs index f2a764840..6c42ed988 100644 --- a/Emby.Server.Implementations/Sorting/SortNameComparer.cs +++ b/Emby.Server.Implementations/Sorting/SortNameComparer.cs @@ -18,6 +18,12 @@ namespace Emby.Server.Implementations.Sorting /// System.Int32. public int Compare(BaseItem x, BaseItem y) { + if (x == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null) + throw new ArgumentNullException(nameof(y)); + return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase); } @@ -25,9 +31,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.SortName; } - } + public string Name => ItemSortBy.SortName; } } diff --git a/Emby.Server.Implementations/Sorting/StartDateComparer.cs b/Emby.Server.Implementations/Sorting/StartDateComparer.cs index 6be5f4883..7ae8037d9 100644 --- a/Emby.Server.Implementations/Sorting/StartDateComparer.cs +++ b/Emby.Server.Implementations/Sorting/StartDateComparer.cs @@ -24,7 +24,7 @@ namespace Emby.Server.Implementations.Sorting /// /// The x. /// DateTime. - private DateTime GetDate(BaseItem x) + private static DateTime GetDate(BaseItem x) { var hasStartDate = x as LiveTvProgram; @@ -39,9 +39,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.StartDate; } - } + public string Name => ItemSortBy.StartDate; } } diff --git a/Emby.Server.Implementations/Sorting/StudioComparer.cs b/Emby.Server.Implementations/Sorting/StudioComparer.cs index 6735022af..605d65154 100644 --- a/Emby.Server.Implementations/Sorting/StudioComparer.cs +++ b/Emby.Server.Implementations/Sorting/StudioComparer.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Sorting; using MediaBrowser.Model.Querying; +using System; using System.Linq; namespace Emby.Server.Implementations.Sorting @@ -15,6 +16,11 @@ namespace Emby.Server.Implementations.Sorting /// System.Int32. public int Compare(BaseItem x, BaseItem y) { + if (x == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null) + throw new ArgumentNullException(nameof(y)); return AlphanumComparator.CompareValues(x.Studios.FirstOrDefault() ?? string.Empty, y.Studios.FirstOrDefault() ?? string.Empty); } @@ -22,9 +28,6 @@ namespace Emby.Server.Implementations.Sorting /// Gets the name. /// /// The name. - public string Name - { - get { return ItemSortBy.Studio; } - } + public string Name => ItemSortBy.Studio; } } -- cgit v1.2.3 From 846456b41e87c8ccced544298b80a27d0f199215 Mon Sep 17 00:00:00 2001 From: Erwin de Haan Date: Sat, 12 Jan 2019 21:41:08 +0100 Subject: Reformatted the files with notes. --- .../ConnectionManager/ServiceActionListBuilder.cs | 2 +- Emby.Naming/Video/VideoListResolver.cs | 4 +- Emby.Server.Implementations/Devices/DeviceId.cs | 7 +- .../LiveTv/LiveTvDtoService.cs | 2 +- .../TunerHosts/HdHomerun/HdHomerunUdpStream.cs | 2 +- .../Playlists/PlaylistManager.cs | 2 +- .../ScheduledTasks/ScheduledTaskWorker.cs | 3 +- .../Services/ServicePath.cs | 3 +- .../Sorting/SeriesSortNameComparer.cs | 4 +- .../NLangDetect/Extensions/StringExtensions.cs | 38 ++--- MediaBrowser.Api/Playback/BaseStreamingService.cs | 8 +- MediaBrowser.Controller/Entities/PeopleHelper.cs | 4 +- MediaBrowser.Controller/Library/ItemResolveArgs.cs | 4 +- MediaBrowser.Providers/Omdb/OmdbProvider.cs | 4 +- MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs | 4 +- RSSDP/DeviceEventArgs.cs | 18 +-- RSSDP/DeviceUnavailableEventArgs.cs | 106 +++++++------- RSSDP/HttpRequestParser.cs | 130 ++++++++--------- RSSDP/HttpResponseParser.cs | 154 ++++++++++----------- RSSDP/IEnumerableExtensions.cs | 14 +- 20 files changed, 257 insertions(+), 256 deletions(-) (limited to 'Emby.Server.Implementations/Sorting') 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 /// 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 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; } - + /// /// Gets the name. /// 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 - { - /// - /// 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 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 /// 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 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 - /// - /// 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 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 { - /// - /// 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 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 { - /// - /// 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 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 { - /// - /// 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 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 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( -- cgit v1.2.3