2013-02-04 01:01:36 +03:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using Eloquera.Client;
|
2013-02-04 07:18:59 +03:00
|
|
|
using NzbDrone.Common;
|
2013-02-06 09:40:51 +03:00
|
|
|
using NzbDrone.Core.RootFolders;
|
2013-02-04 01:01:36 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore
|
|
|
|
{
|
|
|
|
public class EloqueraDbFactory
|
|
|
|
{
|
2013-02-04 07:18:59 +03: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 03:10:15 +03:00
|
|
|
public EloqueraDb CreateMemoryDb()
|
2013-02-04 01:01:36 +03:00
|
|
|
{
|
2013-02-04 07:18:59 +03:00
|
|
|
return InternalCreate("server=(local);password=;options=inmemory;uselocalpath=" + dllPath, Guid.NewGuid().ToString());
|
2013-02-04 01:01:36 +03:00
|
|
|
}
|
|
|
|
|
2013-02-04 07:18:59 +03:00
|
|
|
public EloqueraDb Create(string dbPath = null)
|
2013-02-04 01:01:36 +03:00
|
|
|
{
|
2013-02-04 07:18:59 +03: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 03:10:15 +03:00
|
|
|
}
|
2013-02-04 01:01:36 +03:00
|
|
|
|
2013-02-04 03:10:15 +03:00
|
|
|
private EloqueraDb InternalCreate(string connectionString, string databaseName)
|
|
|
|
{
|
|
|
|
var db = new DB(connectionString);
|
2013-02-04 07:18:59 +03:00
|
|
|
try
|
|
|
|
{
|
|
|
|
db.OpenDatabase(databaseName);
|
|
|
|
}
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
{
|
|
|
|
db.CreateDatabase(databaseName);
|
|
|
|
db.OpenDatabase(databaseName);
|
|
|
|
}
|
|
|
|
|
2013-02-06 09:40:51 +03:00
|
|
|
RegisterTypeRules();
|
|
|
|
RegisterTypes(db);
|
|
|
|
|
2013-02-04 01:01:36 +03:00
|
|
|
return new EloqueraDb(db);
|
|
|
|
}
|
2013-02-04 03:10:15 +03:00
|
|
|
|
2013-02-06 09:40:51 +03:00
|
|
|
private void RegisterTypeRules()
|
|
|
|
{
|
|
|
|
RootFolder rootFolder = null;
|
|
|
|
DB.TypeRules
|
|
|
|
.IgnoreProperty(() => rootFolder.FreeSpace)
|
|
|
|
.IgnoreProperty(() => rootFolder.UnmappedFolders);
|
|
|
|
}
|
2013-02-04 03:10:15 +03:00
|
|
|
|
2013-02-06 09:40:51 +03:00
|
|
|
private void RegisterTypes(DB db)
|
|
|
|
{
|
|
|
|
db.RegisterType(typeof(RootFolder));
|
|
|
|
}
|
2013-02-04 01:01:36 +03:00
|
|
|
}
|
|
|
|
}
|