JobProvider moved to PetaPoco.

pull/4/head
Mark McDowall 14 years ago
parent 901db9d58b
commit 9daf1ccfc0

@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() }; IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
//Act //Act
@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { new BrokenJob() }; IList<IJob> fakeJobs = new List<IJob> { new BrokenJob() };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
//Act //Act
@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() }; IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
var timerProvider = mocker.Resolve<JobProvider>(); var timerProvider = mocker.Resolve<JobProvider>();
@ -88,7 +88,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() }; IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
var timerProvider = mocker.Resolve<JobProvider>(); var timerProvider = mocker.Resolve<JobProvider>();
@ -110,7 +110,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { new SlowJob() }; IList<IJob> fakeJobs = new List<IJob> { new SlowJob() };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
var timerProvider = mocker.Resolve<JobProvider>(); var timerProvider = mocker.Resolve<JobProvider>();
@ -133,7 +133,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { new BrokenJob() }; IList<IJob> fakeJobs = new List<IJob> { new BrokenJob() };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
var timerProvider = mocker.Resolve<JobProvider>(); var timerProvider = mocker.Resolve<JobProvider>();
@ -156,7 +156,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { new SlowJob() }; IList<IJob> fakeJobs = new List<IJob> { new SlowJob() };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
var timerProvider = mocker.Resolve<JobProvider>(); var timerProvider = mocker.Resolve<JobProvider>();
@ -190,7 +190,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { slowJob }; IList<IJob> fakeJobs = new List<IJob> { slowJob };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
var timerProvider = mocker.Resolve<JobProvider>(); var timerProvider = mocker.Resolve<JobProvider>();
@ -218,7 +218,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { fakeTimer }; IList<IJob> fakeJobs = new List<IJob> { fakeTimer };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
var timerProvider = mocker.Resolve<JobProvider>(); var timerProvider = mocker.Resolve<JobProvider>();
@ -242,7 +242,7 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void Init_Timers_only_registers_once() public void Init_Timers_only_registers_once()
{ {
var repo = MockLib.GetEmptyRepository(); var repo = MockLib.GetEmptyDatabase();
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
@ -273,7 +273,7 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void Init_Timers_sets_interval_0_to_disabled() public void Init_Timers_sets_interval_0_to_disabled()
{ {
var repo = MockLib.GetEmptyRepository(); var repo = MockLib.GetEmptyDatabase();
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
@ -307,7 +307,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() }; IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
//Act //Act
@ -325,7 +325,7 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void Disabled_isnt_run_by_scheduler() public void Disabled_isnt_run_by_scheduler()
{ {
var repo = MockLib.GetEmptyRepository(); var repo = MockLib.GetEmptyDatabase();
var disabledJob = new DisabledJob(); var disabledJob = new DisabledJob();
@ -353,7 +353,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() }; IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
//Act //Act
@ -374,7 +374,7 @@ namespace NzbDrone.Core.Test
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() }; IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs); mocker.SetConstant(fakeJobs);
//Act //Act

@ -52,7 +52,7 @@ namespace NzbDrone.Core.Datastore.Migrations
new Column("QualityProfileId", DbType.Int16, ColumnProperty.NotNull), new Column("QualityProfileId", DbType.Int16, ColumnProperty.NotNull),
new Column("SeasonFolder", DbType.Boolean, ColumnProperty.NotNull), new Column("SeasonFolder", DbType.Boolean, ColumnProperty.NotNull),
new Column("LastInfoSync", DbType.DateTime, ColumnProperty.Null), new Column("LastInfoSync", DbType.DateTime, ColumnProperty.Null),
new Column("LastDiskSync", DbType.DateTime, ColumnProperty.Null), new Column("LastDiskSync", DbType.DateTime, ColumnProperty.Null)
}); });
Database.AddTable("Episodes", "SQLite", new[] Database.AddTable("Episodes", "SQLite", new[]
@ -67,7 +67,7 @@ namespace NzbDrone.Core.Datastore.Migrations
new Column("Ignored", DbType.Boolean, ColumnProperty.NotNull, false), new Column("Ignored", DbType.Boolean, ColumnProperty.NotNull, false),
new Column("EpisodeFileId", DbType.Int32, ColumnProperty.Null), new Column("EpisodeFileId", DbType.Int32, ColumnProperty.Null),
new Column("AirDate", DbType.DateTime, ColumnProperty.Null), new Column("AirDate", DbType.DateTime, ColumnProperty.Null),
new Column("GrabDate", DbType.DateTime, ColumnProperty.Null), new Column("GrabDate", DbType.DateTime, ColumnProperty.Null)
}); });
@ -88,7 +88,7 @@ namespace NzbDrone.Core.Datastore.Migrations
Database.AddTable("Config", "SQLite", new[] Database.AddTable("Config", "SQLite", new[]
{ {
new Column("Key", DbType.String, ColumnProperty.PrimaryKey), new Column("Key", DbType.String, ColumnProperty.PrimaryKey),
new Column("Value", DbType.String, ColumnProperty.NotNull), new Column("Value", DbType.String, ColumnProperty.NotNull)
}); });
Database.AddTable("History", "SQLite", new[] Database.AddTable("History", "SQLite", new[]
@ -106,7 +106,7 @@ namespace NzbDrone.Core.Datastore.Migrations
Database.AddTable("RootDirs", "SQLite", new[] Database.AddTable("RootDirs", "SQLite", new[]
{ {
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey), new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Path", DbType.String, ColumnProperty.NotNull), new Column("Path", DbType.String, ColumnProperty.NotNull)
}); });
Database.AddTable("ExternalNotificationSettings", "SQLite", new[] Database.AddTable("ExternalNotificationSettings", "SQLite", new[]
@ -116,6 +116,17 @@ namespace NzbDrone.Core.Datastore.Migrations
new Column("NotifierName", DbType.String, ColumnProperty.NotNull), new Column("NotifierName", DbType.String, ColumnProperty.NotNull),
new Column("Name", DbType.String, ColumnProperty.NotNull) new Column("Name", DbType.String, ColumnProperty.NotNull)
}); });
Database.AddTable("JobSettings", "SQLite", new[]
{
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Enable", DbType.Boolean, ColumnProperty.NotNull),
new Column("TypeName", DbType.String, ColumnProperty.NotNull),
new Column("Name", DbType.String, ColumnProperty.NotNull),
new Column("Interval", DbType.Int32, ColumnProperty.NotNull),
new Column("LastExecution", DbType.DateTime, ColumnProperty.NotNull),
new Column("Success", DbType.Boolean, ColumnProperty.NotNull)
});
} }
public override void Down() public override void Down()

@ -7,6 +7,7 @@ using Ninject;
using NLog; using NLog;
using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using PetaPoco;
using SubSonic.Repository; using SubSonic.Repository;
namespace NzbDrone.Core.Providers.Jobs namespace NzbDrone.Core.Providers.Jobs
@ -14,7 +15,7 @@ namespace NzbDrone.Core.Providers.Jobs
public class JobProvider public class JobProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _repository; private readonly IDatabase _database;
private readonly NotificationProvider _notificationProvider; private readonly NotificationProvider _notificationProvider;
private readonly IList<IJob> _jobs; private readonly IList<IJob> _jobs;
@ -26,9 +27,9 @@ namespace NzbDrone.Core.Providers.Jobs
private ProgressNotification _notification; private ProgressNotification _notification;
[Inject] [Inject]
public JobProvider(IRepository repository, NotificationProvider notificationProvider, IList<IJob> jobs) public JobProvider(IDatabase database, NotificationProvider notificationProvider, IList<IJob> jobs)
{ {
_repository = repository; _database = database;
_notificationProvider = notificationProvider; _notificationProvider = notificationProvider;
_jobs = jobs; _jobs = jobs;
} }
@ -42,7 +43,7 @@ namespace NzbDrone.Core.Providers.Jobs
/// <returns></returns> /// <returns></returns>
public virtual List<JobSetting> All() public virtual List<JobSetting> All()
{ {
return _repository.All<JobSetting>().ToList(); return _database.Fetch<JobSetting>().ToList();
} }
/// <summary> /// <summary>
@ -54,12 +55,12 @@ namespace NzbDrone.Core.Providers.Jobs
if (settings.Id == 0) if (settings.Id == 0)
{ {
Logger.Debug("Adding job settings for {0}", settings.Name); Logger.Debug("Adding job settings for {0}", settings.Name);
_repository.Add(settings); _database.Insert(settings);
} }
else else
{ {
Logger.Debug("Updating job settings for {0}", settings.Name); Logger.Debug("Updating job settings for {0}", settings.Name);
_repository.Update(settings); _database.Update(settings);
} }
} }

@ -1,8 +1,11 @@
using System; using System;
using PetaPoco;
using SubSonic.SqlGeneration.Schema; using SubSonic.SqlGeneration.Schema;
namespace NzbDrone.Core.Repository namespace NzbDrone.Core.Repository
{ {
[TableName("JobSettings")]
[PrimaryKey("Id", autoIncrement = true)]
public class JobSetting public class JobSetting
{ {
[SubSonicPrimaryKey(true)] [SubSonicPrimaryKey(true)]

Loading…
Cancel
Save