Radarr/NzbDrone.Core/Datastore/EloqueraDbFactory.cs

72 lines
2.0 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;
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);
}
2013-02-06 06:40:51 +00:00
RegisterTypeRules();
RegisterTypes(db);
2013-02-03 22:01:36 +00:00
return new EloqueraDb(db);
}
2013-02-04 00:10:15 +00:00
2013-02-06 06:40:51 +00:00
private void RegisterTypeRules()
{
RootFolder rootFolder = null;
DB.TypeRules
.IgnoreProperty(() => rootFolder.FreeSpace)
.IgnoreProperty(() => rootFolder.UnmappedFolders);
}
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-03 22:01:36 +00:00
}
}