1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-14 06:52:36 +01:00
Radarr/NzbDrone.Core/Datastore/Connection.cs

94 lines
2.8 KiB
C#
Raw Normal View History

2011-05-24 01:29:14 +02:00
using System;
2011-11-23 07:15:02 +01:00
using System.Configuration;
using System.Data.Common;
using System.Data.SqlServerCe;
using NzbDrone.Common;
using NzbDrone.Core.Instrumentation;
2011-06-15 04:31:41 +02:00
using PetaPoco;
2011-05-24 01:29:14 +02:00
namespace NzbDrone.Core.Datastore
{
public class Connection
2011-05-24 01:29:14 +02:00
{
private readonly EnvironmentProvider _environmentProvider;
2011-05-24 01:29:14 +02:00
2011-12-02 08:07:18 +01:00
static Connection()
2011-11-23 07:15:02 +01:00
{
2011-12-02 08:07:18 +01:00
Database.Mapper = new CustomeMapper();
2011-11-23 07:15:02 +01:00
2011-12-02 08:07:18 +01:00
var dataSet = ConfigurationManager.GetSection("system.data") as System.Data.DataSet;
dataSet.Tables[0].Rows.Add("Microsoft SQL Server Compact Data Provider 4.0"
, "System.Data.SqlServerCe.4.0"
, ".NET Framework Data Provider for Microsoft SQL Server Compact"
, "System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91");
2011-11-23 07:15:02 +01:00
}
public Connection(EnvironmentProvider environmentProvider)
2011-05-24 01:29:14 +02:00
{
_environmentProvider = environmentProvider;
2011-05-24 01:29:14 +02:00
}
2011-12-02 08:07:18 +01:00
public String MainConnectionString
2011-05-24 01:29:14 +02:00
{
get
{
return GetConnectionString(_environmentProvider.GetNzbDronoeDbFile());
2011-05-24 01:29:14 +02:00
}
}
public String LogConnectionString
2011-05-24 01:29:14 +02:00
{
get
{
return GetConnectionString(_environmentProvider.GetLogDbFileDbFile());
2011-05-24 01:29:14 +02:00
}
}
public static string GetConnectionString(string path)
{
return String.Format("Data Source={0}", path);
}
2011-11-13 08:27:16 +01:00
public IDatabase GetMainPetaPocoDb(Boolean profiled = true)
{
return GetPetaPocoDb(MainConnectionString, profiled);
}
public IDatabase GetLogPetaPocoDb(Boolean profiled = true)
{
return GetPetaPocoDb(LogConnectionString, profiled);
}
public LogDbContext GetLogEfContext()
{
return GetLogDbContext(LogConnectionString);
}
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
2011-06-15 04:31:41 +02:00
{
MigrationsHelper.Run(connectionString, true);
2011-06-23 08:56:17 +02:00
var factory = new DbProviderFactory
{
IsProfiled = profiled
};
var db = new Database(connectionString, factory, Database.DBType.SqlServerCE)
{
KeepConnectionAlive = true,
ForceDateTimesToUtc = false,
};
2011-06-15 04:31:41 +02:00
return db;
}
public static LogDbContext GetLogDbContext(string connectionString)
{
MigrationsHelper.Run(connectionString, true);
DbConnection connection = new SqlCeConnection(connectionString);
return new LogDbContext(connection);
}
2011-05-24 01:29:14 +02:00
}
}