aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2019-02-02 12:27:06 +0100
committerBond_009 <bond.009@outlook.com>2019-02-02 12:27:06 +0100
commit1385d89df6d6af178dcfdfa1dee6346c6efcad2a (patch)
treed04c9666c3e9eed90e9c6c8a4832b03af49ceceb
parent8b073e2ba5e4b1dafc7ef11554cd13ef59339a5c (diff)
Remove MoreLINQ
-rw-r--r--Emby.Server.Implementations/Collections/CollectionImageProvider.cs3
-rw-r--r--Emby.Server.Implementations/Dto/DtoService.cs3
-rw-r--r--Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs17
-rw-r--r--Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs3
-rw-r--r--Emby.Server.Implementations/IO/FileRefresher.cs4
-rw-r--r--Emby.Server.Implementations/LiveTv/LiveTvManager.cs3
-rw-r--r--Emby.Server.Implementations/Networking/NetworkManager.cs6
-rw-r--r--Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs4
-rw-r--r--Emby.Server.Implementations/UserViews/DynamicImageProvider.cs4
-rw-r--r--MediaBrowser.Api/Library/LibraryService.cs15
-rw-r--r--MediaBrowser.Api/Movies/MoviesService.cs6
-rw-r--r--MediaBrowser.Controller/Entities/CollectionFolder.cs6
-rw-r--r--MediaBrowser.Controller/Entities/TV/Series.cs2
-rw-r--r--MediaBrowser.Controller/Library/NameExtensions.cs8
-rw-r--r--MediaBrowser.Model/Extensions/LinqExtensions.cs85
15 files changed, 53 insertions, 116 deletions
diff --git a/Emby.Server.Implementations/Collections/CollectionImageProvider.cs b/Emby.Server.Implementations/Collections/CollectionImageProvider.cs
index 6642d1ef4..6aeadda2f 100644
--- a/Emby.Server.Implementations/Collections/CollectionImageProvider.cs
+++ b/Emby.Server.Implementations/Collections/CollectionImageProvider.cs
@@ -70,7 +70,8 @@ namespace Emby.Server.Implementations.Collections
return null;
})
.Where(i => i != null)
- .DistinctBy(i => i.Id)
+ .GroupBy(x => x.Id)
+ .Select(x => x.First())
.OrderBy(i => Guid.NewGuid())
.ToList();
}
diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs
index a3529fdb4..f5634690f 100644
--- a/Emby.Server.Implementations/Dto/DtoService.cs
+++ b/Emby.Server.Implementations/Dto/DtoService.cs
@@ -620,7 +620,8 @@ namespace Emby.Server.Implementations.Dto
}
}).Where(i => i != null)
- .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .Select(x => x.First())
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
for (var i = 0; i < people.Count; i++)
diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs
index 7a8b09cf7..a670a289c 100644
--- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs
+++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs
@@ -277,14 +277,21 @@ namespace Emby.Server.Implementations.EntryPoints
lock (_libraryChangedSyncLock)
{
// Remove dupes in case some were saved multiple times
- var foldersAddedTo = _foldersAddedTo.DistinctBy(i => i.Id).ToList();
+ var foldersAddedTo = _foldersAddedTo
+ .GroupBy(x => x.Id)
+ .Select(x => x.First())
+ .ToList();
- var foldersRemovedFrom = _foldersRemovedFrom.DistinctBy(i => i.Id).ToList();
+ var foldersRemovedFrom = _foldersRemovedFrom
+ .GroupBy(x => x.Id)
+ .Select(x => x.First())
+ .ToList();
var itemsUpdated = _itemsUpdated
- .Where(i => !_itemsAdded.Contains(i))
- .DistinctBy(i => i.Id)
- .ToList();
+ .Where(i => !_itemsAdded.Contains(i))
+ .GroupBy(x => x.Id)
+ .Select(x => x.First())
+ .ToList();
SendChangeNotifications(_itemsAdded.ToList(), itemsUpdated, _itemsRemoved.ToList(), foldersAddedTo, foldersRemovedFrom, CancellationToken.None);
diff --git a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs
index 9e71ffceb..69784e410 100644
--- a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs
+++ b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs
@@ -121,7 +121,8 @@ namespace Emby.Server.Implementations.EntryPoints
var user = _userManager.GetUserById(userId);
var dtoList = changedItems
- .DistinctBy(i => i.Id)
+ .GroupBy(x => x.Id)
+ .Select(x => x.First())
.Select(i =>
{
var dto = _userDataManager.GetUserDataDto(i, user);
diff --git a/Emby.Server.Implementations/IO/FileRefresher.cs b/Emby.Server.Implementations/IO/FileRefresher.cs
index 12532a497..1cac0ba5c 100644
--- a/Emby.Server.Implementations/IO/FileRefresher.cs
+++ b/Emby.Server.Implementations/IO/FileRefresher.cs
@@ -146,8 +146,8 @@ namespace Emby.Server.Implementations.IO
.Distinct(StringComparer.OrdinalIgnoreCase)
.Select(GetAffectedBaseItem)
.Where(item => item != null)
- .DistinctBy(i => i.Id)
- .ToList();
+ .GroupBy(x => x.Id)
+ .Select(x => x.First());
foreach (var item in itemsToRefresh)
{
diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs
index c0c91e345..c3437bcda 100644
--- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs
+++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs
@@ -2464,7 +2464,8 @@ namespace Emby.Server.Implementations.LiveTv
.Where(i => i != null)
.Where(i => i.IsVisibleStandalone(user))
.SelectMany(i => _libraryManager.GetCollectionFolders(i))
- .DistinctBy(i => i.Id)
+ .GroupBy(x => x.Id)
+ .Select(x => x.First())
.OrderBy(i => i.SortName)
.ToList();
diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs
index f4b9f84dc..aa884664f 100644
--- a/Emby.Server.Implementations/Networking/NetworkManager.cs
+++ b/Emby.Server.Implementations/Networking/NetworkManager.cs
@@ -111,7 +111,8 @@ namespace Emby.Server.Implementations.Networking
.OrderBy(i => i.AddressFamily == AddressFamily.InterNetwork ? 0 : 1)
.ThenBy(i => listClone.IndexOf(i))
.Where(FilterIpAddress)
- .DistinctBy(i => i.ToString())
+ .GroupBy(i => i.ToString())
+ .Select(x => x.First())
.ToList();
}
@@ -429,7 +430,8 @@ namespace Emby.Server.Implementations.Networking
return new List<IPAddress>();
}
- }).DistinctBy(i => i.ToString())
+ }).GroupBy(i => i.ToString())
+ .Select(x => x.First())
.ToList();
}
diff --git a/Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs b/Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs
index 223153164..8a7c1492d 100644
--- a/Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs
+++ b/Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs
@@ -13,7 +13,6 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Querying;
@@ -64,7 +63,8 @@ namespace Emby.Server.Implementations.Playlists
})
.Where(i => i != null)
.OrderBy(i => Guid.NewGuid())
- .DistinctBy(i => i.Id)
+ .GroupBy(x => x.Id)
+ .Select(x => x.First())
.ToList();
}
}
diff --git a/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs b/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs
index 937db3f23..4ec68e550 100644
--- a/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs
+++ b/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs
@@ -12,7 +12,6 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
namespace Emby.Server.Implementations.UserViews
@@ -83,7 +82,8 @@ namespace Emby.Server.Implementations.UserViews
return i;
- }).DistinctBy(i => i.Id);
+ }).GroupBy(x => x.Id)
+ .Select(x => x.First());
if (isUsingCollectionStrip)
{
diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs
index 8e6d1febb..d44b07256 100644
--- a/MediaBrowser.Api/Library/LibraryService.cs
+++ b/MediaBrowser.Api/Library/LibraryService.cs
@@ -551,7 +551,8 @@ namespace MediaBrowser.Api.Library
Name = i.Name,
DefaultEnabled = IsSaverEnabledByDefault(i.Name, types, isNewLibrary)
})
- .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .Select(x => x.First())
.ToArray();
result.MetadataReaders = plugins
@@ -561,7 +562,8 @@ namespace MediaBrowser.Api.Library
Name = i.Name,
DefaultEnabled = true
})
- .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .Select(x => x.First())
.ToArray();
result.SubtitleFetchers = plugins
@@ -571,7 +573,8 @@ namespace MediaBrowser.Api.Library
Name = i.Name,
DefaultEnabled = true
})
- .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .Select(x => x.First())
.ToArray();
var typeOptions = new List<LibraryTypeOptions>();
@@ -593,7 +596,8 @@ namespace MediaBrowser.Api.Library
Name = i.Name,
DefaultEnabled = IsMetadataFetcherEnabledByDefault(i.Name, type, isNewLibrary)
})
- .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .Select(x => x.First())
.ToArray(),
ImageFetchers = plugins
@@ -604,7 +608,8 @@ namespace MediaBrowser.Api.Library
Name = i.Name,
DefaultEnabled = IsImageFetcherEnabledByDefault(i.Name, type, isNewLibrary)
})
- .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
+ .Select(x => x.First())
.ToArray(),
SupportedImageTypes = plugins
diff --git a/MediaBrowser.Api/Movies/MoviesService.cs b/MediaBrowser.Api/Movies/MoviesService.cs
index 996087018..91766255f 100644
--- a/MediaBrowser.Api/Movies/MoviesService.cs
+++ b/MediaBrowser.Api/Movies/MoviesService.cs
@@ -268,7 +268,8 @@ namespace MediaBrowser.Api.Movies
EnableGroupByMetadataKey = true,
DtoOptions = dtoOptions
- }).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
+ }).GroupBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
+ .Select(x => x.First())
.Take(itemLimit)
.ToList();
@@ -308,7 +309,8 @@ namespace MediaBrowser.Api.Movies
EnableGroupByMetadataKey = true,
DtoOptions = dtoOptions
- }).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
+ }).GroupBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
+ .Select(x => x.First())
.Take(itemLimit)
.ToList();
diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs
index 91cfcd0ce..275052d48 100644
--- a/MediaBrowser.Controller/Entities/CollectionFolder.cs
+++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs
@@ -335,7 +335,11 @@ namespace MediaBrowser.Controller.Entities
.OfType<Folder>()
.ToList();
- return PhysicalLocations.Where(i => !FileSystem.AreEqual(i, Path)).SelectMany(i => GetPhysicalParents(i, rootChildren)).DistinctBy(i => i.Id);
+ return PhysicalLocations
+ .Where(i => !FileSystem.AreEqual(i, Path))
+ .SelectMany(i => GetPhysicalParents(i, rootChildren))
+ .GroupBy(x => x.Id)
+ .Select(x => x.First());
}
private IEnumerable<Folder> GetPhysicalParents(string path, List<Folder> rootChildren)
diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs
index 4539ab0f2..570e9389e 100644
--- a/MediaBrowser.Controller/Entities/TV/Series.cs
+++ b/MediaBrowser.Controller/Entities/TV/Series.cs
@@ -270,7 +270,7 @@ namespace MediaBrowser.Controller.Entities.TV
// This depends on settings for that series
// When this happens, remove the duplicate from season 0
- return allEpisodes.DistinctBy(i => i.Id).Reverse();
+ return allEpisodes.GroupBy(i => i.Id).Select(x => x.First()).Reverse();
}
public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
diff --git a/MediaBrowser.Controller/Library/NameExtensions.cs b/MediaBrowser.Controller/Library/NameExtensions.cs
index e2988a831..6b0b7e53a 100644
--- a/MediaBrowser.Controller/Library/NameExtensions.cs
+++ b/MediaBrowser.Controller/Library/NameExtensions.cs
@@ -1,7 +1,7 @@
using System;
+using System.Linq;
using System.Collections.Generic;
using MediaBrowser.Controller.Extensions;
-using MediaBrowser.Model.Extensions;
namespace MediaBrowser.Controller.Library
{
@@ -14,13 +14,11 @@ namespace MediaBrowser.Controller.Library
return string.Empty;
}
- //return name;
return name.RemoveDiacritics();
}
public static IEnumerable<string> DistinctNames(this IEnumerable<string> names)
- {
- return names.DistinctBy(RemoveDiacritics, StringComparer.OrdinalIgnoreCase);
- }
+ => names.GroupBy(RemoveDiacritics, StringComparer.OrdinalIgnoreCase)
+ .Select(x => x.First());
}
}
diff --git a/MediaBrowser.Model/Extensions/LinqExtensions.cs b/MediaBrowser.Model/Extensions/LinqExtensions.cs
deleted file mode 100644
index f0febf1d0..000000000
--- a/MediaBrowser.Model/Extensions/LinqExtensions.cs
+++ /dev/null
@@ -1,85 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-// TODO: @bond Remove
-namespace MediaBrowser.Model.Extensions
-{
- // MoreLINQ - Extensions to LINQ to Objects
- // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
-
- public static class LinqExtensions
- {
- /// <summary>
- /// Returns all distinct elements of the given source, where "distinctness"
- /// is determined via a projection and the default equality comparer for the projected type.
- /// </summary>
- /// <remarks>
- /// This operator uses deferred execution and streams the results, although
- /// a set of already-seen keys is retained. If a key is seen multiple times,
- /// only the first element with that key is returned.
- /// </remarks>
- /// <typeparam name="TSource">Type of the source sequence</typeparam>
- /// <typeparam name="TKey">Type of the projected element</typeparam>
- /// <param name="source">Source sequence</param>
- /// <param name="keySelector">Projection for determining "distinctness"</param>
- /// <returns>A sequence consisting of distinct elements from the source sequence,
- /// comparing them by the specified key projection.</returns>
-
- public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
- Func<TSource, TKey> keySelector)
- {
- return source.DistinctBy(keySelector, null);
- }
-
- /// <summary>
- /// Returns all distinct elements of the given source, where "distinctness"
- /// is determined via a projection and the specified comparer for the projected type.
- /// </summary>
- /// <remarks>
- /// This operator uses deferred execution and streams the results, although
- /// a set of already-seen keys is retained. If a key is seen multiple times,
- /// only the first element with that key is returned.
- /// </remarks>
- /// <typeparam name="TSource">Type of the source sequence</typeparam>
- /// <typeparam name="TKey">Type of the projected element</typeparam>
- /// <param name="source">Source sequence</param>
- /// <param name="keySelector">Projection for determining "distinctness"</param>
- /// <param name="comparer">The equality comparer to use to determine whether or not keys are equal.
- /// If null, the default equality comparer for <c>TSource</c> is used.</param>
- /// <returns>A sequence consisting of distinct elements from the source sequence,
- /// comparing them by the specified key projection.</returns>
-
- public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
- Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
- {
- if (source == null) throw new ArgumentNullException(nameof(source));
- if (keySelector == null) throw new ArgumentNullException(nameof(keySelector));
- return DistinctByImpl(source, keySelector, comparer);
- }
-
- private static IEnumerable<TSource> DistinctByImpl<TSource, TKey>(IEnumerable<TSource> source,
- Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
- {
- var knownKeys = new HashSet<TKey>(comparer);
- foreach (var element in source)
- {
- if (knownKeys.Add(keySelector(element)))
- {
- yield return element;
- }
- }
- }
- }
-}