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