sonarr-repo-only/NzbDrone.Core/Datastore/EloqueraDbFactory.cs

84 lines
2.5 KiB
C#
Raw Normal View History

2013-02-03 22:01:36 +00:00
using System;
using System.IO;
using System.Linq;
using Eloquera.Client;
2013-02-04 04:18:59 +00:00
using NzbDrone.Common;
using NzbDrone.Core.Repository;
2013-02-06 06:40:51 +00:00
using NzbDrone.Core.RootFolders;
2013-02-03 22:01:36 +00:00
namespace NzbDrone.Core.Datastore
{
public class EloqueraDbFactory
{
2013-02-04 04:18:59 +00:00
private readonly EnvironmentProvider _environmentProvider;
private readonly string dllPath;
public EloqueraDbFactory(EnvironmentProvider environmentProvider)
{
_environmentProvider = environmentProvider;
dllPath = _environmentProvider.GetWebBinPath();// this is the path where Eloquera dlls live.
}
2013-02-04 00:10:15 +00:00
public EloqueraDb CreateMemoryDb()
2013-02-03 22:01:36 +00:00
{
2013-02-04 04:18:59 +00:00
return InternalCreate("server=(local);password=;options=inmemory;uselocalpath=" + dllPath, Guid.NewGuid().ToString());
2013-02-03 22:01:36 +00:00
}
2013-02-04 04:18:59 +00:00
public EloqueraDb Create(string dbPath = null)
2013-02-03 22:01:36 +00:00
{
2013-02-04 04:18:59 +00:00
if (dbPath == null)
{
dbPath = _environmentProvider.GetElqMainDbPath();
}
var file = new FileInfo(dbPath);
return InternalCreate(string.Format("server=(local);password=;usedatapath={0};uselocalpath={1}", file.Directory.FullName, dllPath), file.Name);
2013-02-04 00:10:15 +00:00
}
2013-02-03 22:01:36 +00:00
2013-02-04 00:10:15 +00:00
private EloqueraDb InternalCreate(string connectionString, string databaseName)
{
var db = new DB(connectionString);
2013-02-04 04:18:59 +00:00
try
{
db.OpenDatabase(databaseName);
}
catch (FileNotFoundException)
{
db.CreateDatabase(databaseName);
db.OpenDatabase(databaseName);
}
//This seemse to cause Invalid Cast Exceptions... WTF
//db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues;
2013-02-06 06:40:51 +00:00
RegisterTypeRules();
RegisterTypes(db);
return new EloqueraDb(db, new IdService(new IndexProvider(db)));
2013-02-03 22:01:36 +00:00
}
2013-02-04 00:10:15 +00:00
2013-02-06 06:40:51 +00:00
private void RegisterTypeRules()
{
RootFolder rootFolder = null;
DB.TypeRules
//.SetIDField(() => rootFolder.Id)
2013-02-06 06:40:51 +00:00
.IgnoreProperty(() => rootFolder.FreeSpace)
.IgnoreProperty(() => rootFolder.UnmappedFolders);
//Series series = null;
//DB.TypeRules
// .SetIDField(() => series.Id);
2013-02-06 06:40:51 +00:00
}
2013-02-04 00:10:15 +00:00
2013-02-06 06:40:51 +00:00
private void RegisterTypes(DB db)
{
db.RegisterType(typeof(RootFolder));
db.RegisterType(typeof(Series));
db.RegisterType(typeof(Episode));
2013-02-06 06:40:51 +00:00
}
2013-02-03 22:01:36 +00:00
}
}