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;
|
2013-02-08 08:05:43 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2013-02-17 00:27:33 +00:00
|
|
|
|
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-08 08:05:43 +00:00
|
|
|
|
|
2013-02-04 04:18:59 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
db.OpenDatabase(databaseName);
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
db.CreateDatabase(databaseName);
|
|
|
|
|
db.OpenDatabase(databaseName);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 08:05:43 +00:00
|
|
|
|
//This seemse to cause Invalid Cast Exceptions... WTF
|
|
|
|
|
//db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues;
|
2013-02-16 03:50:22 +00:00
|
|
|
|
|
2013-02-06 06:40:51 +00:00
|
|
|
|
RegisterTypeRules();
|
|
|
|
|
RegisterTypes(db);
|
|
|
|
|
|
2013-02-16 03:50:22 +00:00
|
|
|
|
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
|
2013-02-16 03:50:22 +00:00
|
|
|
|
//.SetIDField(() => rootFolder.Id)
|
2013-02-06 06:40:51 +00:00
|
|
|
|
.IgnoreProperty(() => rootFolder.FreeSpace)
|
|
|
|
|
.IgnoreProperty(() => rootFolder.UnmappedFolders);
|
2013-02-08 08:05:43 +00:00
|
|
|
|
|
|
|
|
|
//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));
|
2013-02-08 08:05:43 +00:00
|
|
|
|
db.RegisterType(typeof(Series));
|
|
|
|
|
db.RegisterType(typeof(Episode));
|
2013-02-06 06:40:51 +00:00
|
|
|
|
}
|
2013-02-03 22:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|