1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-25 17:17:02 +00:00

IndexerProvider now uses PetaPoco.

This commit is contained in:
Mark McDowall 2011-06-17 17:10:33 -07:00
parent ec0ef5d46d
commit 01944acbb1
4 changed files with 21 additions and 12 deletions

View file

@ -29,7 +29,7 @@ public void Init_indexer_test()
{ {
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
//Act //Act
var indexerProvider = mocker.Resolve<IndexerProvider>(); var indexerProvider = mocker.Resolve<IndexerProvider>();
@ -51,7 +51,7 @@ public void Init_indexer_with_disabled_job()
{ {
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
//Act //Act
var indexerProvider = mocker.Resolve<IndexerProvider>(); var indexerProvider = mocker.Resolve<IndexerProvider>();

View file

@ -142,6 +142,14 @@ public override void Up()
new Column("Cutoff", DbType.Int32, ColumnProperty.NotNull), new Column("Cutoff", DbType.Int32, ColumnProperty.NotNull),
new Column("SonicAllowed", DbType.String, ColumnProperty.NotNull), new Column("SonicAllowed", DbType.String, ColumnProperty.NotNull),
}); });
Database.AddTable("IndexerSettings", "SQLite", new[]
{
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Enable", DbType.Boolean, ColumnProperty.NotNull),
new Column("IndexProviderType", DbType.String, ColumnProperty.NotNull),
new Column("Name", DbType.String, ColumnProperty.NotNull),
});
} }
public override void Down() public override void Down()

View file

@ -5,21 +5,21 @@
using NLog; using NLog;
using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using SubSonic.Repository; using PetaPoco;
namespace NzbDrone.Core.Providers namespace NzbDrone.Core.Providers
{ {
public class IndexerProvider public class IndexerProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _repository; private readonly IDatabase _database;
private IList<IndexerBase> _indexers = new List<IndexerBase>(); private IList<IndexerBase> _indexers = new List<IndexerBase>();
[Inject] [Inject]
public IndexerProvider(IRepository repository) public IndexerProvider(IDatabase database)
{ {
_repository = repository; _database = database;
} }
public IndexerProvider() public IndexerProvider()
@ -35,7 +35,7 @@ public virtual IList<IndexerBase> GetEnabledIndexers()
public virtual List<IndexerSetting> GetAllISettings() public virtual List<IndexerSetting> GetAllISettings()
{ {
return _repository.All<IndexerSetting>().ToList(); return _database.Fetch<IndexerSetting>();
} }
public virtual void SaveSettings(IndexerSetting settings) public virtual void SaveSettings(IndexerSetting settings)
@ -43,18 +43,18 @@ public virtual void SaveSettings(IndexerSetting settings)
if (settings.Id == 0) if (settings.Id == 0)
{ {
Logger.Debug("Adding Indexer settings for {0}", settings.Name); Logger.Debug("Adding Indexer settings for {0}", settings.Name);
_repository.Add(settings); _database.Insert(settings);
} }
else else
{ {
Logger.Debug("Updating Indexer settings for {0}", settings.Name); Logger.Debug("Updating Indexer settings for {0}", settings.Name);
_repository.Update(settings); _database.Update(settings);
} }
} }
public virtual IndexerSetting GetSettings(Type type) public virtual IndexerSetting GetSettings(Type type)
{ {
return _repository.Single<IndexerSetting>(s => s.IndexProviderType == type.ToString()); return _database.Single<IndexerSetting>("WHERE IndexProviderType = @0", type.ToString());
} }
public virtual void InitializeIndexers(IList<IndexerBase> indexers) public virtual void InitializeIndexers(IList<IndexerBase> indexers)

View file

@ -1,11 +1,12 @@
using System; using System;
using SubSonic.SqlGeneration.Schema; using PetaPoco;
namespace NzbDrone.Core.Repository namespace NzbDrone.Core.Repository
{ {
[TableName("IndexerSettings")]
[PrimaryKey("Id", autoIncrement = true)]
public class IndexerSetting public class IndexerSetting
{ {
[SubSonicPrimaryKey(true)]
public int Id { get; set; } public int Id { get; set; }
public Boolean Enable { get; set; } public Boolean Enable { get; set; }