using System.Collections.Generic;
using System.Linq;
using Examine;
using Umbraco.Core.Collections;
namespace Umbraco.Examine
{
///
/// An that is automatically associated to any index of type
///
///
public abstract class IndexPopulator : IndexPopulator where TIndex : IIndex
{
public override bool IsRegistered(IIndex index)
{
if (base.IsRegistered(index)) return true;
return index is TIndex;
}
}
public abstract class IndexPopulator : IIndexPopulator
{
private readonly ConcurrentHashSet _registeredIndexes = new ConcurrentHashSet();
public virtual bool IsRegistered(IIndex index)
{
return _registeredIndexes.Contains(index.Name);
}
///
/// Registers an index for this populator
///
///
public void RegisterIndex(string indexName)
{
_registeredIndexes.Add(indexName);
}
public void Populate(params IIndex[] indexes)
{
PopulateIndexes(indexes.Where(IsRegistered).ToList());
}
protected abstract void PopulateIndexes(IReadOnlyList indexes);
}
}