1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-28 19:05:55 +00:00
Radarr/NzbDrone.Core/Indexers/IndexerService.cs

76 lines
2.2 KiB
C#
Raw Normal View History

2013-04-07 07:30:37 +00:00
using System.Collections.Generic;
2013-02-21 07:07:34 +00:00
using System.Linq;
using NLog;
2013-02-21 16:38:31 +00:00
using NzbDrone.Core.Lifecycle;
2013-03-02 18:25:39 +00:00
2013-02-21 07:07:34 +00:00
namespace NzbDrone.Core.Indexers
{
public interface IIndexerService
{
2013-04-07 07:30:37 +00:00
List<IndexerDefinition> All();
List<IIndexerBase> GetAvailableIndexers();
void Save(IndexerDefinition indexer);
IndexerDefinition Get(string name);
2013-02-21 07:07:34 +00:00
}
2013-02-21 16:38:31 +00:00
public class IndexerService : IIndexerService, IInitializable
2013-02-21 07:07:34 +00:00
{
private readonly IIndexerRepository _indexerRepository;
2013-02-21 16:38:31 +00:00
private readonly Logger _logger;
2013-02-21 07:07:34 +00:00
2013-04-07 07:30:37 +00:00
private readonly IList<IIndexerBase> _indexers;
2013-02-21 07:07:34 +00:00
2013-04-07 07:30:37 +00:00
public IndexerService(IIndexerRepository indexerRepository, IEnumerable<IIndexerBase> indexers, Logger logger)
2013-02-21 07:07:34 +00:00
{
_indexerRepository = indexerRepository;
2013-02-21 16:38:31 +00:00
_logger = logger;
2013-02-21 07:07:34 +00:00
_indexers = indexers.ToList();
2013-02-21 16:38:31 +00:00
}
public void Init()
{
_logger.Debug("Initializing indexers. Count {0}", _indexers.Count);
var currentIndexers = All();
foreach (var feedProvider in _indexers)
{
2013-04-07 07:30:37 +00:00
IIndexerBase indexerLocal = feedProvider;
if (!currentIndexers.Exists(c => c.Name == indexerLocal.Name))
2013-02-21 16:38:31 +00:00
{
2013-04-07 07:30:37 +00:00
var settings = new IndexerDefinition
2013-02-21 16:38:31 +00:00
{
Enable = indexerLocal.EnabledByDefault,
2013-04-07 07:30:37 +00:00
Name = indexerLocal.Name.ToLower()
2013-02-21 16:38:31 +00:00
};
_indexerRepository.Insert(settings);
}
}
2013-02-21 07:07:34 +00:00
}
2013-04-07 07:30:37 +00:00
public List<IndexerDefinition> All()
2013-02-21 07:07:34 +00:00
{
return _indexerRepository.All().ToList();
}
2013-04-07 07:30:37 +00:00
public List<IIndexerBase> GetAvailableIndexers()
2013-02-21 07:07:34 +00:00
{
2013-04-07 07:30:37 +00:00
var enabled = All().Where(c => c.Enable).Select(c => c.Name);
var configureIndexers = _indexers.Where(c => c.Settings.IsValid);
return configureIndexers.Where(c => enabled.Contains(c.Name)).ToList();
2013-02-21 07:07:34 +00:00
}
2013-04-07 07:30:37 +00:00
public void Save(IndexerDefinition indexer)
2013-02-21 07:07:34 +00:00
{
2013-04-07 07:30:37 +00:00
_indexerRepository.Update(indexer);
2013-02-21 07:07:34 +00:00
}
2013-04-07 07:30:37 +00:00
public IndexerDefinition Get(string name)
2013-02-21 07:07:34 +00:00
{
2013-04-07 07:30:37 +00:00
return _indexerRepository.Get(name);
2013-02-21 07:07:34 +00:00
}
}
}