1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-03-05 15:15:59 +02:00
Sonarr/NzbDrone.Core/Datastore/EloqueraDbFactory.cs

57 lines
1.6 KiB
C#
Raw Normal View History

2013-02-03 14:01:36 -08:00
using System;
using System.IO;
using System.Linq;
using Eloquera.Client;
2013-02-03 20:18:59 -08:00
using NzbDrone.Common;
2013-02-03 14:01:36 -08:00
namespace NzbDrone.Core.Datastore
{
public class EloqueraDbFactory
{
2013-02-03 20:18:59 -08: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-03 16:10:15 -08:00
public EloqueraDb CreateMemoryDb()
2013-02-03 14:01:36 -08:00
{
2013-02-03 20:18:59 -08:00
return InternalCreate("server=(local);password=;options=inmemory;uselocalpath=" + dllPath, Guid.NewGuid().ToString());
2013-02-03 14:01:36 -08:00
}
2013-02-03 20:18:59 -08:00
public EloqueraDb Create(string dbPath = null)
2013-02-03 14:01:36 -08:00
{
2013-02-03 20:18:59 -08: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-03 16:10:15 -08:00
}
2013-02-03 14:01:36 -08:00
2013-02-03 16:10:15 -08:00
private EloqueraDb InternalCreate(string connectionString, string databaseName)
{
var db = new DB(connectionString);
2013-02-03 20:18:59 -08:00
try
{
db.OpenDatabase(databaseName);
}
catch (FileNotFoundException)
{
db.CreateDatabase(databaseName);
db.OpenDatabase(databaseName);
}
2013-02-03 14:01:36 -08:00
return new EloqueraDb(db);
}
2013-02-03 16:10:15 -08:00
2013-02-03 14:01:36 -08:00
}
}