|
|
|
@ -3,8 +3,8 @@ using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Model.Entities
|
|
|
|
|
{
|
|
|
|
|
namespace MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class ProviderIdsExtensions.
|
|
|
|
|
/// </summary>
|
|
|
|
@ -27,11 +27,7 @@ namespace MediaBrowser.Model.Entities
|
|
|
|
|
/// <param name="name">The of the provider name.</param>
|
|
|
|
|
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
|
|
|
|
|
public static bool HasProviderId(this IHasProviderIds instance, string name)
|
|
|
|
|
{
|
|
|
|
|
ArgumentNullException.ThrowIfNull(instance);
|
|
|
|
|
|
|
|
|
|
return instance.TryGetProviderId(name, out _);
|
|
|
|
|
}
|
|
|
|
|
=> instance.TryGetProviderId(name, out _);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if this instance has an id for the given provider.
|
|
|
|
@ -40,9 +36,7 @@ namespace MediaBrowser.Model.Entities
|
|
|
|
|
/// <param name="provider">The provider.</param>
|
|
|
|
|
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
|
|
|
|
|
public static bool HasProviderId(this IHasProviderIds instance, MetadataProvider provider)
|
|
|
|
|
{
|
|
|
|
|
return instance.HasProviderId(provider.ToString());
|
|
|
|
|
}
|
|
|
|
|
=> instance.HasProviderId(provider.ToString());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a provider id.
|
|
|
|
@ -107,6 +101,52 @@ namespace MediaBrowser.Model.Entities
|
|
|
|
|
return instance.GetProviderId(provider.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a provider id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="instance">The instance.</param>
|
|
|
|
|
/// <param name="name">The name, this should not contain a '=' character.</param>
|
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
|
/// <remarks>Due to how deserialization from the database works the name can not contain '='.</remarks>
|
|
|
|
|
/// <returns><c>true</c> if the provider id got set successfully; otherwise, <c>false</c>.</returns>
|
|
|
|
|
public static bool TrySetProviderId(this IHasProviderIds instance, string? name, string? value)
|
|
|
|
|
{
|
|
|
|
|
ArgumentNullException.ThrowIfNull(instance);
|
|
|
|
|
|
|
|
|
|
// When name contains a '=' it can't be deserialized from the database
|
|
|
|
|
if (string.IsNullOrWhiteSpace(name)
|
|
|
|
|
|| string.IsNullOrWhiteSpace(value)
|
|
|
|
|
|| name.Contains('=', StringComparison.Ordinal))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure it exists
|
|
|
|
|
instance.ProviderIds ??= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
// Match on internal MetadataProvider enum string values before adding arbitrary providers
|
|
|
|
|
if (_metadataProviderEnumDictionary.TryGetValue(name, out var enumValue))
|
|
|
|
|
{
|
|
|
|
|
instance.ProviderIds[enumValue] = value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
instance.ProviderIds[name] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a provider id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="instance">The instance.</param>
|
|
|
|
|
/// <param name="provider">The provider.</param>
|
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
|
/// <returns><c>true</c> if the provider id got set successfully; otherwise, <c>false</c>.</returns>
|
|
|
|
|
public static bool TrySetProviderId(this IHasProviderIds instance, MetadataProvider provider, string? value)
|
|
|
|
|
=> instance.TrySetProviderId(provider.ToString(), value);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a provider id.
|
|
|
|
|
/// </summary>
|
|
|
|
@ -117,8 +157,8 @@ namespace MediaBrowser.Model.Entities
|
|
|
|
|
public static void SetProviderId(this IHasProviderIds instance, string name, string value)
|
|
|
|
|
{
|
|
|
|
|
ArgumentNullException.ThrowIfNull(instance);
|
|
|
|
|
ArgumentException.ThrowIfNullOrEmpty(name);
|
|
|
|
|
ArgumentException.ThrowIfNullOrEmpty(value);
|
|
|
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(name);
|
|
|
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(value);
|
|
|
|
|
|
|
|
|
|
// When name contains a '=' it can't be deserialized from the database
|
|
|
|
|
if (name.Contains('=', StringComparison.Ordinal))
|
|
|
|
@ -147,9 +187,7 @@ namespace MediaBrowser.Model.Entities
|
|
|
|
|
/// <param name="provider">The provider.</param>
|
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
|
public static void SetProviderId(this IHasProviderIds instance, MetadataProvider provider, string value)
|
|
|
|
|
{
|
|
|
|
|
instance.SetProviderId(provider.ToString(), value);
|
|
|
|
|
}
|
|
|
|
|
=> instance.SetProviderId(provider.ToString(), value);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes a provider id.
|
|
|
|
@ -176,4 +214,3 @@ namespace MediaBrowser.Model.Entities
|
|
|
|
|
instance.ProviderIds?.Remove(provider.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|