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