Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into dotnet-5
Browse files Browse the repository at this point in the history
  • Loading branch information
crobibero committed Nov 15, 2020
2 parents 3f31320 + 7caf166 commit dae4541
Show file tree
Hide file tree
Showing 74 changed files with 525 additions and 772 deletions.
2 changes: 1 addition & 1 deletion DvdLib/Ifo/Dvd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Dvd(string path)
continue;
}

var nums = ifo.Name.Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
var nums = ifo.Name.Split('_', StringSplitOptions.RemoveEmptyEntries);
if (nums.Length >= 2 && ushort.TryParse(nums[1], out var ifoNumber))
{
ReadVTS(ifoNumber, ifo.FullName);
Expand Down
2 changes: 1 addition & 1 deletion Emby.Dlna/Didl/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Filter(string filter)
{
_all = string.Equals(filter, "*", StringComparison.OrdinalIgnoreCase);

_fields = (filter ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
_fields = (filter ?? string.Empty).Split(',', StringSplitOptions.RemoveEmptyEntries);
}

public bool Contains(string field)
Expand Down
2 changes: 1 addition & 1 deletion Emby.Dlna/Eventing/DlnaEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public EventSubscriptionResponse CreateEventSubscription(string notificationType
if (!string.IsNullOrEmpty(header))
{
// Starts with SECOND-
header = header.Split('-').Last();
header = header.Split('-')[^1];

if (int.TryParse(header, NumberStyles.Integer, _usCulture, out var val))
{
Expand Down
27 changes: 27 additions & 0 deletions Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,33 @@ protected set
}
}

/// <summary>
/// Manually pre-loads a factory so that it is available pre system initialisation.
/// </summary>
/// <typeparam name="T">Class to register.</typeparam>
public virtual void RegisterConfiguration<T>()
where T : IConfigurationFactory
{
IConfigurationFactory factory = Activator.CreateInstance<T>();

if (_configurationFactories == null)
{
_configurationFactories = new[] { factory };
}
else
{
var oldLen = _configurationFactories.Length;
var arr = new IConfigurationFactory[oldLen + 1];
_configurationFactories.CopyTo(arr, 0);
arr[oldLen] = factory;
_configurationFactories = arr;
}

_configurationStores = _configurationFactories
.SelectMany(i => i.GetConfigurations())
.ToArray();
}

/// <summary>
/// Adds parts.
/// </summary>
Expand Down
73 changes: 40 additions & 33 deletions Emby.Server.Implementations/ApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public abstract class ApplicationHost : IServerApplicationHost, IDisposable
private IMediaEncoder _mediaEncoder;
private ISessionManager _sessionManager;
private IHttpClientFactory _httpClientFactory;

private string[] _urlPrefixes;

/// <summary>
Expand Down Expand Up @@ -497,24 +496,11 @@ public void Init()
HttpsPort = ServerConfiguration.DefaultHttpsPort;
}

if (Plugins != null)
{
var pluginBuilder = new StringBuilder();

foreach (var plugin in Plugins)
{
pluginBuilder.Append(plugin.Name)
.Append(' ')
.Append(plugin.Version)
.AppendLine();
}

Logger.LogInformation("Plugins: {Plugins}", pluginBuilder.ToString());
}

DiscoverTypes();

RegisterServices();

RegisterPluginServices();
}

/// <summary>
Expand Down Expand Up @@ -779,10 +765,24 @@ private void FindParts()

ConfigurationManager.AddParts(GetExports<IConfigurationFactory>());
_plugins = GetExports<IPlugin>()
.Select(LoadPlugin)
.Where(i => i != null)
.ToArray();

if (Plugins != null)
{
var pluginBuilder = new StringBuilder();

foreach (var plugin in Plugins)
{
pluginBuilder.Append(plugin.Name)
.Append(' ')
.Append(plugin.Version)
.AppendLine();
}

Logger.LogInformation("Plugins: {Plugins}", pluginBuilder.ToString());
}

_urlPrefixes = GetUrlPrefixes().ToArray();

Resolve<ILibraryManager>().AddParts(
Expand Down Expand Up @@ -812,21 +812,6 @@ private void FindParts()
Resolve<IIsoManager>().AddParts(GetExports<IIsoMounter>());
}

private IPlugin LoadPlugin(IPlugin plugin)
{
try
{
plugin.RegisterServices(ServiceCollection);
}
catch (Exception ex)
{
Logger.LogError(ex, "Error loading plugin {PluginName}", plugin.GetType().FullName);
return null;
}

return plugin;
}

/// <summary>
/// Discovers the types.
/// </summary>
Expand All @@ -837,6 +822,22 @@ protected void DiscoverTypes()
_allConcreteTypes = GetTypes(GetComposablePartAssemblies()).ToArray();
}

private void RegisterPluginServices()
{
foreach (var pluginServiceRegistrator in GetExportTypes<IPluginServiceRegistrator>())
{
try
{
var instance = (IPluginServiceRegistrator)Activator.CreateInstance(pluginServiceRegistrator);
instance.RegisterServices(ServiceCollection);
}
catch (Exception ex)
{
Logger.LogError(ex, "Error registering plugin services from {Assembly}.", pluginServiceRegistrator.Assembly);
}
}
}

private IEnumerable<Type> GetTypes(IEnumerable<Assembly> assemblies)
{
foreach (var ass in assemblies)
Expand Down Expand Up @@ -996,6 +997,12 @@ public IEnumerable<LocalPlugin> GetLocalPlugins(string path, bool cleanup = true
{
var minimumVersion = new Version(0, 0, 0, 1);
var versions = new List<LocalPlugin>();
if (!Directory.Exists(path))
{
// Plugin path doesn't exist, don't try to enumerate subfolders.
return Enumerable.Empty<LocalPlugin>();
}

var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly);

foreach (var dir in directories)
Expand Down Expand Up @@ -1026,7 +1033,7 @@ public IEnumerable<LocalPlugin> GetLocalPlugins(string path, bool cleanup = true
else
{
// No metafile, so lets see if the folder is versioned.
metafile = dir.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)[^1];
metafile = dir.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries)[^1];

int versionIndex = dir.LastIndexOf('_');
if (versionIndex != -1 && Version.TryParse(dir.Substring(versionIndex + 1), out Version parsedVersion))
Expand Down
52 changes: 35 additions & 17 deletions Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ private static void DeserializeProviderIds(string value, BaseItem item)
return;
}

var parts = value.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
var parts = value.Split('|', StringSplitOptions.RemoveEmptyEntries);

foreach (var part in parts)
{
Expand Down Expand Up @@ -1057,7 +1057,7 @@ private void DeserializeImages(string value, BaseItem item)
return;
}

var parts = value.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
var parts = value.Split('|' , StringSplitOptions.RemoveEmptyEntries);
var list = new List<ItemImageInfo>();
foreach (var part in parts)
{
Expand Down Expand Up @@ -1096,7 +1096,7 @@ public void AppendItemImageInfo(StringBuilder bldr, ItemImageInfo image)

public ItemImageInfo ItemImageInfoFromValueString(string value)
{
var parts = value.Split(new[] { '*' }, StringSplitOptions.None);
var parts = value.Split('*', StringSplitOptions.None);

if (parts.Length < 3)
{
Expand Down Expand Up @@ -1532,7 +1532,7 @@ private BaseItem GetItem(IReadOnlyList<IResultSetValue> reader, InternalItemsQue
{
if (!reader.IsDBNull(index))
{
item.Genres = reader.GetString(index).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
item.Genres = reader.GetString(index).Split('|', StringSplitOptions.RemoveEmptyEntries);
}

index++;
Expand Down Expand Up @@ -1593,7 +1593,7 @@ private BaseItem GetItem(IReadOnlyList<IResultSetValue> reader, InternalItemsQue
{
IEnumerable<MetadataField> GetLockedFields(string s)
{
foreach (var i in s.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
foreach (var i in s.Split('|', StringSplitOptions.RemoveEmptyEntries))
{
if (Enum.TryParse(i, true, out MetadataField parsedValue))
{
Expand All @@ -1612,7 +1612,7 @@ IEnumerable<MetadataField> GetLockedFields(string s)
{
if (!reader.IsDBNull(index))
{
item.Studios = reader.GetString(index).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
item.Studios = reader.GetString(index).Split('|', StringSplitOptions.RemoveEmptyEntries);
}

index++;
Expand All @@ -1622,7 +1622,7 @@ IEnumerable<MetadataField> GetLockedFields(string s)
{
if (!reader.IsDBNull(index))
{
item.Tags = reader.GetString(index).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
item.Tags = reader.GetString(index).Split('|', StringSplitOptions.RemoveEmptyEntries);
}

index++;
Expand All @@ -1636,7 +1636,7 @@ IEnumerable<MetadataField> GetLockedFields(string s)
{
IEnumerable<TrailerType> GetTrailerTypes(string s)
{
foreach (var i in s.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
foreach (var i in s.Split('|', StringSplitOptions.RemoveEmptyEntries))
{
if (Enum.TryParse(i, true, out TrailerType parsedValue))
{
Expand Down Expand Up @@ -1811,7 +1811,7 @@ IEnumerable<TrailerType> GetTrailerTypes(string s)
{
if (!reader.IsDBNull(index))
{
item.ProductionLocations = reader.GetString(index).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
item.ProductionLocations = reader.GetString(index).Split('|', StringSplitOptions.RemoveEmptyEntries).ToArray();
}

index++;
Expand Down Expand Up @@ -1848,14 +1848,14 @@ IEnumerable<TrailerType> GetTrailerTypes(string s)
{
if (item is IHasArtist hasArtists && !reader.IsDBNull(index))
{
hasArtists.Artists = reader.GetString(index).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
hasArtists.Artists = reader.GetString(index).Split('|', StringSplitOptions.RemoveEmptyEntries);
}

index++;

if (item is IHasAlbumArtist hasAlbumArtists && !reader.IsDBNull(index))
{
hasAlbumArtists.AlbumArtists = reader.GetString(index).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
hasAlbumArtists.AlbumArtists = reader.GetString(index).Split('|', StringSplitOptions.RemoveEmptyEntries);
}

index++;
Expand Down Expand Up @@ -2403,11 +2403,11 @@ private List<string> GetFinalColumnsToSelect(InternalItemsQuery query, IEnumerab

if (string.IsNullOrEmpty(item.OfficialRating))
{
builder.Append("((OfficialRating is null) * 10)");
builder.Append("(OfficialRating is null * 10)");
}
else
{
builder.Append("((OfficialRating=@ItemOfficialRating) * 10)");
builder.Append("(OfficialRating=@ItemOfficialRating * 10)");
}

if (item.ProductionYear.HasValue)
Expand All @@ -2416,8 +2416,26 @@ private List<string> GetFinalColumnsToSelect(InternalItemsQuery query, IEnumerab
builder.Append("+(Select Case When Abs(COALESCE(ProductionYear, 0) - @ItemProductionYear) < 5 Then 5 Else 0 End )");
}

//// genres, tags
builder.Append("+ ((Select count(CleanValue) from ItemValues where ItemId=Guid and CleanValue in (select CleanValue from itemvalues where ItemId=@SimilarItemId)) * 10)");
// genres, tags, studios, person, year?
builder.Append("+ (Select count(1) * 10 from ItemValues where ItemId=Guid and CleanValue in (select CleanValue from itemvalues where ItemId=@SimilarItemId))");

if (item is MusicArtist)
{
// Match albums where the artist is AlbumArtist against other albums.
// It is assumed that similar albums => similar artists.
builder.Append(
@"+ (WITH artistValues AS (
SELECT DISTINCT albumValues.CleanValue
FROM ItemValues albumValues
INNER JOIN ItemValues artistAlbums ON albumValues.ItemId = artistAlbums.ItemId
INNER JOIN TypedBaseItems artistItem ON artistAlbums.CleanValue = artistItem.CleanName AND artistAlbums.TYPE = 1 AND artistItem.Guid = @SimilarItemId
), similarArtist AS (
SELECT albumValues.ItemId
FROM ItemValues albumValues
INNER JOIN ItemValues artistAlbums ON albumValues.ItemId = artistAlbums.ItemId
INNER JOIN TypedBaseItems artistItem ON artistAlbums.CleanValue = artistItem.CleanName AND artistAlbums.TYPE = 1 AND artistItem.Guid = A.Guid
) SELECT COUNT(DISTINCT(CleanValue)) * 10 FROM ItemValues WHERE ItemId IN (SELECT ItemId FROM similarArtist) AND CleanValue IN (SELECT CleanValue FROM artistValues))");
}

builder.Append(") as SimilarityScore");

Expand Down Expand Up @@ -5052,7 +5070,7 @@ public List<PersonInfo> GetPeople(InternalPeopleQuery query)

CheckDisposed();

var commandText = "select ItemId, Name, Role, PersonType, SortOrder from People";
var commandText = "select ItemId, Name, Role, PersonType, SortOrder from People p";

var whereClauses = GetPeopleWhereClauses(query, null);

Expand Down Expand Up @@ -5593,7 +5611,7 @@ private ItemCounts GetItemCounts(IReadOnlyList<IResultSetValue> reader, int coun
return counts;
}

var allTypes = typeString.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
var allTypes = typeString.Split('|', StringSplitOptions.RemoveEmptyEntries)
.ToLookup(x => x);

foreach (var type in allTypes)
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Dto/DtoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private static void NormalizeMediaSourceContainers(BaseItemDto dto)
continue;
}

var containers = container.Split(new[] { ',' });
var containers = container.Split(',');
if (containers.Length < 2)
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private Dictionary<string, string> GetAuthorization(string authorizationHeader)
return null;
}

var parts = authorizationHeader.Split(new[] { ' ' }, 2);
var parts = authorizationHeader.Split(' ', 2);

// There should be at least to parts
if (parts.Length != 2)
Expand All @@ -269,11 +269,11 @@ private Dictionary<string, string> GetAuthorization(string authorizationHeader)

foreach (var item in parts)
{
var param = item.Trim().Split(new[] { '=' }, 2);
var param = item.Trim().Split('=', 2);

if (param.Length == 2)
{
var value = NormalizeValue(param[1].Trim(new[] { '"' }));
var value = NormalizeValue(param[1].Trim('"'));
result[param[0]] = value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Library/LibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,7 @@ public IEnumerable<Video> FindExtras(BaseItem owner, List<FileSystemMetadata> fi

var videos = videoListResolver.Resolve(fileSystemChildren);

var currentVideo = videos.FirstOrDefault(i => string.Equals(owner.Path, i.Files.First().Path, StringComparison.OrdinalIgnoreCase));
var currentVideo = videos.FirstOrDefault(i => string.Equals(owner.Path, i.Files[0].Path, StringComparison.OrdinalIgnoreCase));

if (currentVideo != null)
{
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Library/MediaSourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ public async Task CloseLiveStream(string id)
throw new ArgumentException("Key can't be empty.", nameof(key));
}

var keys = key.Split(new[] { LiveStreamIdDelimeter }, 2);
var keys = key.Split(LiveStreamIdDelimeter, 2);

var provider = _providers.FirstOrDefault(i => string.Equals(i.GetType().FullName.GetMD5().ToString("N", CultureInfo.InvariantCulture), keys[0], StringComparison.OrdinalIgnoreCase));

Expand Down
Loading

0 comments on commit dae4541

Please sign in to comment.