1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core/Datastore/Connection.cs
kay.one b11a449f65 Updated PetaPoco
Upped IIS's priority
Added Byte multiplier to extention method.
2011-07-17 12:32:58 -07:00

67 lines
1.8 KiB
C#

using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlServerCe;
using System.IO;
using MvcMiniProfiler.Data;
using PetaPoco;
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();
Database.Mapper = new CustomeMapper();
}
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);
}
public static String MainConnectionString
{
get
{
return GetConnectionString(Path.Combine(AppDataPath.FullName, "nzbdrone.sdf"));
}
}
public static String LogConnectionString
{
get
{
return GetConnectionString(Path.Combine(AppDataPath.FullName, "log.sdf"));
}
}
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
{
MigrationsHelper.Run(connectionString, true);
var sqliteConnection = new SqlCeConnection(connectionString);
DbConnection connection = sqliteConnection;
if (profiled)
{
connection = ProfiledDbConnection.Get(sqliteConnection);
}
var db = new Database(connection, Database.DBType.SqlServerCE);
db.ForceDateTimesToUtc = false;
if (connection.State != ConnectionState.Open)
connection.Open();
return db;
}
}
}