2011-05-23 23:29:14 +00:00
|
|
|
|
using System;
|
2011-06-17 03:36:52 +00:00
|
|
|
|
using System.Data;
|
2011-06-18 02:51:53 +00:00
|
|
|
|
using System.Data.Common;
|
2011-06-15 02:31:41 +00:00
|
|
|
|
using System.Data.SQLite;
|
2011-05-23 23:29:14 +00:00
|
|
|
|
using System.IO;
|
2011-06-14 01:35:44 +00:00
|
|
|
|
using MvcMiniProfiler.Data;
|
2011-06-15 02:31:41 +00:00
|
|
|
|
using PetaPoco;
|
2011-05-23 23:29:14 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore
|
|
|
|
|
{
|
|
|
|
|
public static class Connection
|
|
|
|
|
{
|
|
|
|
|
private static readonly DirectoryInfo AppDataPath = new DirectoryInfo(Path.Combine(CentralDispatch.AppPath, "App_Data"));
|
|
|
|
|
|
|
|
|
|
static Connection()
|
|
|
|
|
{
|
|
|
|
|
if (!AppDataPath.Exists) AppDataPath.Create();
|
2011-06-18 02:51:53 +00:00
|
|
|
|
Database.Mapper = new CustomeMapper();
|
2011-05-23 23:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-06-04 18:19:22 +00:00
|
|
|
|
public static string GetConnectionString(string path)
|
2011-05-23 23:29:14 +00:00
|
|
|
|
{
|
2011-06-22 05:43:45 +00:00
|
|
|
|
return String.Format("Data Source={0};Version=3;Cache Size=30000;Pooling=true;Default Timeout=2", path);
|
2011-05-23 23:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-04 18:19:22 +00:00
|
|
|
|
public static String MainConnectionString
|
2011-05-23 23:29:14 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2011-06-04 18:19:22 +00:00
|
|
|
|
return GetConnectionString(Path.Combine(AppDataPath.FullName, "nzbdrone.db"));
|
2011-05-23 23:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-04 18:19:22 +00:00
|
|
|
|
public static String LogConnectionString
|
2011-05-23 23:29:14 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2011-06-04 18:19:22 +00:00
|
|
|
|
return GetConnectionString(Path.Combine(AppDataPath.FullName, "log.db"));
|
2011-05-23 23:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-18 02:51:53 +00:00
|
|
|
|
|
|
|
|
|
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
|
2011-06-15 02:31:41 +00:00
|
|
|
|
{
|
2011-06-17 06:58:50 +00:00
|
|
|
|
MigrationsHelper.Run(connectionString, true);
|
2011-06-22 05:43:45 +00:00
|
|
|
|
var sqliteConnection = new SQLiteConnection(connectionString);
|
|
|
|
|
DbConnection connection = sqliteConnection;
|
|
|
|
|
|
2011-06-18 02:51:53 +00:00
|
|
|
|
if (profiled)
|
|
|
|
|
{
|
2011-06-22 05:43:45 +00:00
|
|
|
|
connection = ProfiledDbConnection.Get(sqliteConnection);
|
2011-06-18 02:51:53 +00:00
|
|
|
|
}
|
2011-06-17 06:58:50 +00:00
|
|
|
|
|
2011-06-18 02:51:53 +00:00
|
|
|
|
var db = new Database(connection);
|
2011-06-18 20:30:30 +00:00
|
|
|
|
db.ForceDateTimesToUtc = false;
|
2011-06-17 03:36:52 +00:00
|
|
|
|
|
2011-06-18 02:51:53 +00:00
|
|
|
|
if (connection.State != ConnectionState.Open)
|
|
|
|
|
connection.Open();
|
2011-06-15 02:31:41 +00:00
|
|
|
|
|
|
|
|
|
return db;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-23 23:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|