2015-09-19 21:25:19 +00:00
|
|
|
|
using System.Linq;
|
2014-05-05 19:53:05 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2014-05-06 02:00:16 +00:00
|
|
|
|
namespace MediaBrowser.Controller.Providers
|
2014-05-05 19:53:05 +00:00
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
public static class ItemIdentifier<TLookupInfo>
|
2014-05-05 19:53:05 +00:00
|
|
|
|
where TLookupInfo : ItemLookupInfo
|
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
public static async Task FindIdentities(TLookupInfo item, IProviderManager providerManager, CancellationToken cancellationToken)
|
2014-05-05 19:53:05 +00:00
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
var providers = providerManager.GetItemIdentityProviders<TLookupInfo>();
|
|
|
|
|
var converters = providerManager.GetItemIdentityConverters<TLookupInfo>().ToList();
|
|
|
|
|
|
2014-05-05 19:53:05 +00:00
|
|
|
|
foreach (var provider in providers)
|
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
await provider.Identify(item);
|
2014-05-05 19:53:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-19 21:25:19 +00:00
|
|
|
|
bool changesMade = true;
|
2014-05-05 19:53:05 +00:00
|
|
|
|
|
2015-09-19 21:25:19 +00:00
|
|
|
|
while (changesMade)
|
2014-05-05 19:53:05 +00:00
|
|
|
|
{
|
|
|
|
|
changesMade = false;
|
|
|
|
|
|
2015-09-19 21:25:19 +00:00
|
|
|
|
foreach (var converter in converters)
|
2014-05-05 19:53:05 +00:00
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
if (await converter.Convert(item))
|
2014-05-05 19:53:05 +00:00
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
changesMade = true;
|
2014-05-05 19:53:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-19 21:25:19 +00:00
|
|
|
|
}
|
2014-05-05 19:53:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|