Mayor code cleanup

Add Argument*Exceptions now use proper nameof operators.

Added exception messages to quite a few Argument*Exceptions.

Fixed rethorwing to be proper syntax.

Added a ton of null checkes. (This is only a start, there are about 500 places that need proper null handling)

Added some TODOs to log certain exceptions.

Fix sln again.

Fixed all AssemblyInfo's and added proper copyright (where I could find them)

We live in *current year*.

Fixed the use of braces.

Fixed a ton of properties, and made a fair amount of functions static that should be and can be static.

Made more Methods that should be static static.

You can now use static to find bad functions!

Removed unused variable. And added one more proper XML comment.
This commit is contained in:
Erwin de Haan
2019-01-06 21:50:43 +01:00
parent 3d867c2c46
commit ec1f5dc317
334 changed files with 1632 additions and 2603 deletions

View File

@@ -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
/// <returns>System.Int32.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.AiredEpisodeOrder; }
}
public string Name => ItemSortBy.AiredEpisodeOrder;
}
}

View File

@@ -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
/// </summary>
/// <param name="x">The x.</param>
/// <returns>System.String.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.AlbumArtist; }
}
public string Name => ItemSortBy.AlbumArtist;
}
}

View File

@@ -27,7 +27,7 @@ namespace Emby.Server.Implementations.Sorting
/// </summary>
/// <param name="x">The x.</param>
/// <returns>System.String.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.Album; }
}
public string Name => ItemSortBy.Album;
}
}

View File

@@ -27,7 +27,7 @@ namespace Emby.Server.Implementations.Sorting
/// </summary>
/// <param name="x">The x.</param>
/// <returns>System.String.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.Artist; }
}
public string Name => ItemSortBy.Artist;
}
}

View File

@@ -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
/// <returns>System.Int32.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.CommunityRating; }
}
public string Name => ItemSortBy.CommunityRating;
}
}

View File

@@ -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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.CriticRating; }
}
public string Name => ItemSortBy.CriticRating;
}
}

View File

@@ -18,6 +18,12 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.DateCreated; }
}
public string Name => ItemSortBy.DateCreated;
}
}

View File

@@ -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
/// </summary>
/// <param name="x">The x.</param>
/// <returns>DateTime.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.DateLastContentAdded; }
}
public string Name => ItemSortBy.DateLastContentAdded;
}
}

View File

@@ -61,9 +61,6 @@ namespace Emby.Server.Implementations.Sorting
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.DatePlayed; }
}
public string Name => ItemSortBy.DatePlayed;
}
}

View File

@@ -23,7 +23,7 @@ namespace Emby.Server.Implementations.Sorting
/// </summary>
/// <param name="x">The x.</param>
/// <returns>System.String.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.GameSystem; }
}
public string Name => ItemSortBy.GameSystem;
}
}

View File

@@ -38,10 +38,7 @@ namespace Emby.Server.Implementations.Sorting
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.IsFavoriteOrLiked; }
}
public string Name => ItemSortBy.IsFavoriteOrLiked;
/// <summary>
/// Gets or sets the user data repository.

View File

@@ -22,7 +22,7 @@ namespace Emby.Server.Implementations.Sorting
/// </summary>
/// <param name="x">The x.</param>
/// <returns>System.String.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.IsFolder; }
}
public string Name => ItemSortBy.IsFolder;
}
}

View File

@@ -38,10 +38,7 @@ namespace Emby.Server.Implementations.Sorting
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.IsUnplayed; }
}
public string Name => ItemSortBy.IsUnplayed;
/// <summary>
/// Gets or sets the user data repository.

View File

@@ -38,10 +38,7 @@ namespace Emby.Server.Implementations.Sorting
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.IsUnplayed; }
}
public string Name => ItemSortBy.IsUnplayed;
/// <summary>
/// Gets or sets the user data repository.

View File

@@ -18,6 +18,12 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.Name; }
}
public string Name => ItemSortBy.Name;
}
}

View File

@@ -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
/// <returns>System.Int32.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.OfficialRating; }
}
public string Name => ItemSortBy.OfficialRating;
}
}

View File

@@ -43,10 +43,7 @@ namespace Emby.Server.Implementations.Sorting
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.PlayCount; }
}
public string Name => ItemSortBy.PlayCount;
/// <summary>
/// Gets or sets the user data repository.

View File

@@ -22,7 +22,7 @@ namespace Emby.Server.Implementations.Sorting
/// </summary>
/// <param name="x">The x.</param>
/// <returns>System.String.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.Players; }
}
public string Name => ItemSortBy.Players;
}
}

View File

@@ -26,7 +26,7 @@ namespace Emby.Server.Implementations.Sorting
/// </summary>
/// <param name="x">The x.</param>
/// <returns>DateTime.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.PremiereDate; }
}
public string Name => ItemSortBy.PremiereDate;
}
}

View File

@@ -25,7 +25,7 @@ namespace Emby.Server.Implementations.Sorting
/// </summary>
/// <param name="x">The x.</param>
/// <returns>DateTime.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.ProductionYear; }
}
public string Name => ItemSortBy.ProductionYear;
}
}

View File

@@ -25,9 +25,6 @@ namespace Emby.Server.Implementations.Sorting
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.Random; }
}
public string Name => ItemSortBy.Random;
}
}

View File

@@ -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
/// <returns>System.Int32.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.Runtime; }
}
public string Name => ItemSortBy.Runtime;
}
}

View File

@@ -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;
}
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.SeriesSortName; }
}
public string Name => ItemSortBy.SeriesSortName;
}
}

View File

@@ -18,6 +18,12 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.SortName; }
}
public string Name => ItemSortBy.SortName;
}
}

View File

@@ -24,7 +24,7 @@ namespace Emby.Server.Implementations.Sorting
/// </summary>
/// <param name="x">The x.</param>
/// <returns>DateTime.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.StartDate; }
}
public string Name => ItemSortBy.StartDate;
}
}

View File

@@ -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
/// <returns>System.Int32.</returns>
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.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return ItemSortBy.Studio; }
}
public string Name => ItemSortBy.Studio;
}
}