1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone.Core/Datastore/Connection.cs

73 lines
2.0 KiB
C#
Raw Normal View History

2011-05-24 02:29:14 +03:00
using System;
using NzbDrone.Common;
2011-06-15 05:31:41 +03:00
using PetaPoco;
2011-05-24 02:29:14 +03:00
namespace NzbDrone.Core.Datastore
{
public class Connection
2011-05-24 02:29:14 +03:00
{
2011-11-13 10:27:16 +03:00
private readonly EnviromentProvider _enviromentProvider;
2011-05-24 02:29:14 +03:00
2011-11-13 10:27:16 +03:00
public Connection(EnviromentProvider enviromentProvider)
2011-05-24 02:29:14 +03:00
{
2011-11-13 10:27:16 +03:00
_enviromentProvider = enviromentProvider;
2011-05-24 02:29:14 +03:00
}
static Connection()
2011-05-24 02:29:14 +03:00
{
Database.Mapper = new CustomeMapper();
2011-05-24 02:29:14 +03:00
}
public String MainConnectionString
2011-05-24 02:29:14 +03:00
{
get
{
2011-11-13 10:27:16 +03:00
return GetConnectionString(_enviromentProvider.GetNzbDronoeDbFile());
2011-05-24 02:29:14 +03:00
}
}
public String LogConnectionString
2011-05-24 02:29:14 +03:00
{
get
{
2011-11-13 10:27:16 +03:00
return GetConnectionString(_enviromentProvider.GetLogDbFileDbFile());
2011-05-24 02:29:14 +03: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);
}
2011-11-13 10:27:16 +03:00
public IDatabase GetMainPetaPocoDb(Boolean profiled = true)
{
return GetPetaPocoDb(MainConnectionString, profiled);
}
public IDatabase GetLogPetaPocoDb(Boolean profiled = true)
{
return GetPetaPocoDb(LogConnectionString, profiled);
}
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
2011-06-15 05:31:41 +03:00
{
MigrationsHelper.Run(connectionString, true);
2011-06-23 09:56:17 +03:00
var factory = new PetaDbProviderFactory
{
IsProfiled = profiled
};
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
}
}