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