2011-05-24 01:29:14 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2011-06-14 03:35:44 +02:00
|
|
|
|
using MvcMiniProfiler.Data;
|
2011-05-24 01:29:14 +02:00
|
|
|
|
using SubSonic.DataProviders;
|
2011-06-14 03:35:44 +02:00
|
|
|
|
using SubSonic.DataProviders.SQLite;
|
2011-05-24 01:29:14 +02:00
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
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-04 20:19:22 +02:00
|
|
|
|
public static string GetConnectionString(string path)
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
2011-06-05 22:01:28 +02:00
|
|
|
|
return String.Format("Data Source={0};Version=3;Cache Size=30000;", path);
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-04 20:19:22 +02:00
|
|
|
|
public static String MainConnectionString
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2011-06-04 20:19:22 +02:00
|
|
|
|
return GetConnectionString(Path.Combine(AppDataPath.FullName, "nzbdrone.db"));
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-04 20:19:22 +02:00
|
|
|
|
public static String LogConnectionString
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2011-06-04 20:19:22 +02:00
|
|
|
|
return GetConnectionString(Path.Combine(AppDataPath.FullName, "log.db"));
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-04 20:19:22 +02:00
|
|
|
|
public static IDataProvider GetDataProvider(string connectionString)
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
2011-06-14 03:35:44 +02:00
|
|
|
|
return new ProfiledSQLiteProvider(connectionString, "System.Data.SQLite");
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-05 08:02:31 +02:00
|
|
|
|
public static IRepository CreateSimpleRepository(IDataProvider dataProvider)
|
|
|
|
|
{
|
|
|
|
|
return new SimpleRepository(dataProvider, SimpleRepositoryOptions.RunMigrations);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-04 20:19:22 +02:00
|
|
|
|
public static IRepository CreateSimpleRepository(string connectionString)
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
2011-06-04 20:19:22 +02:00
|
|
|
|
return new SimpleRepository(GetDataProvider(connectionString), SimpleRepositoryOptions.RunMigrations);
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2011-06-14 03:35:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class ProfiledSQLiteProvider : SQLiteProvider
|
|
|
|
|
{
|
|
|
|
|
public ProfiledSQLiteProvider(string connectionString, string providerName)
|
|
|
|
|
: base(connectionString, providerName)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override System.Data.Common.DbConnection CreateConnection(string connectionString)
|
|
|
|
|
{
|
|
|
|
|
return ProfiledDbConnection.Get(base.CreateConnection(connectionString));
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|