1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-28 10:48:46 +00:00
Sonarr/NzbDrone.Core/Providers/IndexerProvider.cs

79 lines
2.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
2011-04-04 03:50:12 +00:00
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository;
2011-04-10 02:44:01 +00:00
using SubSonic.Repository;
namespace NzbDrone.Core.Providers
{
public class IndexerProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _repository;
public IndexerProvider(IRepository repository)
{
_repository = repository;
}
public IndexerProvider()
{
}
2011-04-22 06:23:29 +00:00
public virtual List<IndexerSetting> All()
{
return _repository.All<IndexerSetting>().ToList();
}
public virtual void SaveSettings(IndexerSetting settings)
{
if (settings.Id == 0)
{
Logger.Debug("Adding Indexer settings for {0}", settings.Name);
_repository.Add(settings);
}
else
{
Logger.Debug("Updating Indexer settings for {0}", settings.Name);
_repository.Update(settings);
}
}
public virtual IndexerSetting GetSettings(Type type)
{
return _repository.Single<IndexerSetting>(s => s.IndexProviderType == type.ToString());
}
2011-04-20 01:20:20 +00:00
public virtual IndexerSetting GetSettings(int id)
{
return _repository.Single<IndexerSetting>(s => s.Id == id);
}
public virtual void InitializeIndexers(IList<IndexerBase> indexers)
{
Logger.Info("Initializing indexers. Count {0}", indexers.Count);
2011-04-22 06:23:29 +00:00
var currentIndexers = All();
foreach (var feedProvider in indexers)
{
IndexerBase indexerLocal = feedProvider;
if (!currentIndexers.Exists(c => c.IndexProviderType == indexerLocal.GetType().ToString()))
{
var settings = new IndexerSetting()
{
Enable = false,
IndexProviderType = indexerLocal.GetType().ToString(),
Name = indexerLocal.Name
};
SaveSettings(settings);
}
}
}
}
2011-04-10 02:44:01 +00:00
}