2011-05-24 01:29:14 +02:00
|
|
|
|
using System;
|
2011-06-17 05:36:52 +02:00
|
|
|
|
using System.Data;
|
2011-06-18 04:51:53 +02:00
|
|
|
|
using System.Data.Common;
|
2011-06-23 08:56:17 +02:00
|
|
|
|
using System.Data.SqlServerCe;
|
2011-05-24 01:29:14 +02:00
|
|
|
|
using System.IO;
|
2011-06-14 03:35:44 +02:00
|
|
|
|
using MvcMiniProfiler.Data;
|
2011-10-29 06:54:33 +02:00
|
|
|
|
using NzbDrone.Common;
|
2011-10-21 07:04:26 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-06-15 04:31:41 +02:00
|
|
|
|
using PetaPoco;
|
2011-05-24 01:29:14 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore
|
|
|
|
|
{
|
2011-11-03 06:04:14 +01:00
|
|
|
|
public class Connection
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
2011-11-03 06:04:14 +01:00
|
|
|
|
private readonly PathProvider _pathProvider;
|
2011-05-24 01:29:14 +02:00
|
|
|
|
|
2011-11-03 06:04:14 +01:00
|
|
|
|
public Connection(PathProvider pathProvider)
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
2011-11-03 06:04:14 +01:00
|
|
|
|
_pathProvider = pathProvider;
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-03 06:04:14 +01:00
|
|
|
|
static Connection()
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
2011-11-03 06:04:14 +01:00
|
|
|
|
Database.Mapper = new CustomeMapper();
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-03 06:04:14 +01:00
|
|
|
|
public String MainConnectionString
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2011-11-03 06:04:14 +01:00
|
|
|
|
return GetConnectionString(_pathProvider.NzbDronoeDbFile);
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-03 06:04:14 +01:00
|
|
|
|
public String LogConnectionString
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2011-11-03 06:04:14 +01:00
|
|
|
|
return GetConnectionString(_pathProvider.LogDbFile);
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-03 06:04:14 +01:00
|
|
|
|
public static string GetConnectionString(string path)
|
|
|
|
|
{
|
|
|
|
|
//return String.Format("Data Source={0};Version=3;Cache Size=30000;Pooling=true;Default Timeout=2", path);
|
|
|
|
|
return String.Format("Data Source={0}", path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IDatabase GetMainPetaPocoDb(Boolean profiled = true)
|
|
|
|
|
{
|
|
|
|
|
return GetPetaPocoDb(MainConnectionString, profiled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IDatabase GetLogPetaPocoDb(Boolean profiled = true)
|
|
|
|
|
{
|
|
|
|
|
return GetPetaPocoDb(LogConnectionString, profiled);
|
|
|
|
|
}
|
2011-06-18 04:51:53 +02:00
|
|
|
|
|
|
|
|
|
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
|
2011-06-15 04:31:41 +02:00
|
|
|
|
{
|
2011-06-17 08:58:50 +02:00
|
|
|
|
MigrationsHelper.Run(connectionString, true);
|
2011-06-23 08:56:17 +02:00
|
|
|
|
|
2011-08-28 19:43:33 +02:00
|
|
|
|
var factory = new PetaDbProviderFactory
|
|
|
|
|
{
|
|
|
|
|
IsProfiled = profiled
|
|
|
|
|
};
|
2011-06-17 05:36:52 +02:00
|
|
|
|
|
2011-08-28 19:43:33 +02:00
|
|
|
|
var db = new Database(connectionString, factory, Database.DBType.SqlServerCE)
|
|
|
|
|
{
|
|
|
|
|
KeepConnectionAlive = true,
|
|
|
|
|
ForceDateTimesToUtc = false,
|
|
|
|
|
};
|
2011-06-15 04:31:41 +02:00
|
|
|
|
|
|
|
|
|
return db;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|