registered eloquere db with autofac.

This commit is contained in:
kay.one 2013-02-03 17:27:34 -08:00
parent d13f977bb5
commit 0155de4d92
7 changed files with 61 additions and 33 deletions

View File

@ -9,13 +9,16 @@ namespace NzbDrone.Common
private const string APP_DATA = "App_Data\\";
public const string IIS_FOLDER = "IISExpress";
public const string IIS_EXE = "iisexpress.exe";
private const string LOG_CONFIG_FILE = "log.config";
private const string APP_CONFIG_FILE = "config.xml";
public const string NZBDRONE_EXE = "NzbDrone.exe";
public const string NZBDRONE_DB_FILE = "nzbdrone.sdf";
public const string LOG_DB_FILE = "log.sdf";
public const string NZBDRONE_SQLCE_DB_FILE = "nzbdrone.sdf";
public const string NZBDRONE_ELQ_DB_FILE = "nzbdrone.eq";
public const string LOG_SQLCE_DB_FILE = "log.sdf";
public const string LOG_ELQ_DB_FILE = "log.eq";
private const string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip";
@ -77,14 +80,24 @@ namespace NzbDrone.Common
return Path.Combine(environmentProvider.ApplicationPath, APP_CONFIG_FILE);
}
public static string GetNzbDroneDbFile(this EnvironmentProvider environmentProvider)
public static string GetSqlCeMainDbPath(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB_FILE);
return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_SQLCE_DB_FILE);
}
public static string GetLogDbFileDbFile(this EnvironmentProvider environmentProvider)
public static string GetSqlCeLogDbPath(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetAppDataPath(), LOG_DB_FILE);
return Path.Combine(environmentProvider.GetAppDataPath(), LOG_SQLCE_DB_FILE);
}
public static string GetElqMainDbPath(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_ELQ_DB_FILE);
}
public static string GetElqLogDbPath(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetAppDataPath(), LOG_ELQ_DB_FILE);
}
public static string GetMediaCoverPath(this EnvironmentProvider environmentProvider)

View File

@ -10,20 +10,25 @@ namespace NzbDrone.Core.Test.Datastore
[TestFixture]
public class ObjectDatabaseFixture : ObjectDbTest
{
private Series testSeries;
private Episode testEpisode;
[SetUp]
public void SetUp()
{
WithObjectDb();
testSeries = Builder<Series>.CreateNew().Build();
testEpisode = Builder<Episode>.CreateNew().Build();
}
[Test]
public void should_be_able_to_write_to_database()
{
var series = Builder<Series>.CreateNew().Build();
Db.Create(series);
Db.Insert(testSeries);
Db.AsQueryable<Series>().Should().HaveCount(1);
@ -32,14 +37,11 @@ namespace NzbDrone.Core.Test.Datastore
[Test]
public void should_not_store_dirty_data_in_cache()
{
var episode = Builder<Episode>.CreateNew().Build();
//Save series without episode attached
Db.Create(episode);
Db.Insert(testEpisode);
Db.AsQueryable<Episode>().Single().Series.Should().BeNull();
episode.Series = Builder<Series>.CreateNew().Build();
testEpisode.Series = Builder<Series>.CreateNew().Build();
Db.AsQueryable<Episode>().Single().Series.Should().BeNull();
}
@ -49,10 +51,9 @@ namespace NzbDrone.Core.Test.Datastore
[Test]
public void should_store_nested_objects()
{
var episode = Builder<Episode>.CreateNew().Build();
episode.Series = Builder<Series>.CreateNew().Build();
testEpisode.Series = testSeries;
Db.Create(episode);
Db.Insert(testEpisode);
Db.AsQueryable<Episode>().Should().HaveCount(1);
Db.AsQueryable<Episode>().Single().Series.Should().NotBeNull();
@ -61,18 +62,26 @@ namespace NzbDrone.Core.Test.Datastore
[Test]
public void should_update_nested_objects()
{
var episode = Builder<Episode>.CreateNew().Build();
episode.Series = Builder<Series>.CreateNew().Build();
testEpisode.Series = Builder<Series>.CreateNew().Build();
Db.Create(episode);
Db.Insert(testEpisode);
episode.Series.Title = "UpdatedTitle";
testEpisode.Series.Title = "UpdatedTitle";
Db.Update(episode);
Db.Update(testEpisode);
Db.AsQueryable<Episode>().Should().HaveCount(1);
Db.AsQueryable<Episode>().Single().Series.Should().NotBeNull();
Db.AsQueryable<Episode>().Single().Series.Title.Should().Be("UpdatedTitle");
}
[Test]
public void new_objects_should_get_id()
{
Db.Insert(testSeries);
testSeries.Id.Should().NotBe(0);
}
}
}

View File

@ -80,6 +80,12 @@ namespace NzbDrone.Core
container.Register(c => c.Resolve<ConnectionFactory>().GetLogPetaPocoDb())
.Named<IDatabase>("LogProvider");
container.Register(c =>
{
var env = c.Resolve<EnvironmentProvider>();
return c.Resolve<EloqueraDbFactory>().Create(env.GetElqMainDbPath());
}).As<EloqueraDb>().SingleInstance();
container.RegisterType<DatabaseTarget>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("DatabaseTarget"));
container.RegisterType<LogProvider>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("LogProvider"));
}

View File

@ -35,7 +35,7 @@ namespace NzbDrone.Core.Datastore
{
get
{
return GetConnectionString(_environmentProvider.GetNzbDroneDbFile());
return GetConnectionString(_environmentProvider.GetSqlCeMainDbPath());
}
}
@ -43,7 +43,7 @@ namespace NzbDrone.Core.Datastore
{
get
{
return GetConnectionString(_environmentProvider.GetLogDbFileDbFile());
return GetConnectionString(_environmentProvider.GetSqlCeLogDbPath());
}
}

View File

@ -20,15 +20,15 @@ namespace NzbDrone.Core.Datastore
}
public T Create<T>(T obj)
public T Insert<T>(T obj)
{
_db.Store(obj);
return obj;
}
public IList<T> CreateMany<T>(IEnumerable<T> objects)
public IList<T> InsertMany<T>(IEnumerable<T> objects)
{
return DoMany(objects, Create);
return DoMany(objects, Insert);
}
public T Update<T>(T obj)

View File

@ -17,11 +17,11 @@ namespace NzbDrone.Core.Datastore.Migrations
public override void Up()
{
if (Database.ConnectionString.Contains(PathExtentions.NZBDRONE_DB_FILE))
if (Database.ConnectionString.Contains(PathExtentions.NZBDRONE_SQLCE_DB_FILE))
{
MainDbUpgrade();
}
else if (Database.ConnectionString.Contains(PathExtentions.LOG_DB_FILE))
else if (Database.ConnectionString.Contains(PathExtentions.LOG_SQLCE_DB_FILE))
{
LogDbUpgrade();
}

View File

@ -23,7 +23,7 @@ namespace NzbDrone.Core.Providers
public virtual string CreateBackupZip()
{
var dbFile = _environmentProvider.GetNzbDroneDbFile();
var dbFile = _environmentProvider.GetSqlCeMainDbPath();
var configFile = _environmentProvider.GetConfigPath();
var zipFile = _environmentProvider.GetConfigBackupFile();