mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-27 02:43:57 +02:00
more dynamic binding to sqlce
This commit is contained in:
parent
2873fc9f6d
commit
885688f4c2
@ -36,11 +36,6 @@ public static bool IsProduction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsMono
|
|
||||||
{
|
|
||||||
get { return Type.GetType("Mono.Runtime") != null; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsDebug
|
public static bool IsDebug
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NCrunch.Framework;
|
using NCrunch.Framework;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Common;
|
|
||||||
using NzbDrone.Core.Jobs;
|
using NzbDrone.Core.Jobs;
|
||||||
using NzbDrone.Core.Providers;
|
using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Providers.ExternalNotification;
|
using NzbDrone.Core.Providers.ExternalNotification;
|
||||||
@ -29,10 +28,9 @@ class CentralDispatchFixture : SqlCeTest
|
|||||||
|
|
||||||
public CentralDispatchFixture()
|
public CentralDispatchFixture()
|
||||||
{
|
{
|
||||||
if (EnvironmentProvider.IsMono)
|
#if __MonoCS__
|
||||||
{
|
|
||||||
throw new IgnoreException("SqlCe is not supported");
|
throw new IgnoreException("SqlCe is not supported");
|
||||||
}
|
#endif
|
||||||
|
|
||||||
InitLogging();
|
InitLogging();
|
||||||
var dispatch = new CentralDispatch();
|
var dispatch = new CentralDispatch();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Common;
|
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Model.Notification;
|
using NzbDrone.Core.Model.Notification;
|
||||||
using NzbDrone.Core.Providers.Core;
|
using NzbDrone.Core.Providers.Core;
|
||||||
@ -17,10 +16,10 @@ public abstract class SqlCeTest : CoreTest
|
|||||||
[SetUp]
|
[SetUp]
|
||||||
public void CoreTestSetup()
|
public void CoreTestSetup()
|
||||||
{
|
{
|
||||||
if (EnvironmentProvider.IsMono)
|
|
||||||
{
|
#if __MonoCS__
|
||||||
throw new IgnoreException("SqlCe is not supported in mono.");
|
throw new IgnoreException("SqlCe is not supported in mono.");
|
||||||
}
|
#endif
|
||||||
|
|
||||||
if (NCrunch.Framework.NCrunchEnvironment.NCrunchIsResident())
|
if (NCrunch.Framework.NCrunchEnvironment.NCrunchIsResident())
|
||||||
{
|
{
|
||||||
|
@ -440,9 +440,8 @@
|
|||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PreBuildEvent>if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
|
<PreBuildEvent>
|
||||||
|
</PreBuildEvent>
|
||||||
xcopy /s /y "$(SolutionDir)\SqlCe\*.*" "$(TargetDir)"</PreBuildEvent>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
|
<PostBuildEvent>if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
using System.Data.OleDb;
|
||||||
|
using System.Data.SqlClient;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
@ -19,19 +21,22 @@ static ConnectionFactory()
|
|||||||
{
|
{
|
||||||
Database.Mapper = new CustomeMapper();
|
Database.Mapper = new CustomeMapper();
|
||||||
|
|
||||||
if (EnvironmentProvider.IsMono) return;
|
|
||||||
|
#if __MonoCS__
|
||||||
|
#else
|
||||||
|
|
||||||
var dataSet = (System.Data.DataSet)ConfigurationManager.GetSection("system.data");
|
var dataSet = (System.Data.DataSet)ConfigurationManager.GetSection("system.data");
|
||||||
dataSet.Tables[0].Rows.Add("Microsoft SQL Server Compact Data Provider 4.0"
|
dataSet.Tables[0].Rows.Add("Microsoft SQL Server Compact Data Provider 4.0"
|
||||||
, "System.Data.SqlServerCe.4.0"
|
, "System.Data.SqlServerCe.4.0"
|
||||||
, ".NET Framework Data Provider for Microsoft SQL Server Compact"
|
, ".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");
|
||||||
"System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91");
|
|
||||||
|
|
||||||
var proxyType = Assembly.Load("NzbDrone.SqlCe").GetExportedTypes()[0];
|
var proxyType = Assembly.Load("NzbDrone.SqlCe").GetExportedTypes()[0];
|
||||||
var instance = Activator.CreateInstance(proxyType);
|
var instance = Activator.CreateInstance(proxyType);
|
||||||
var factoryMethod = proxyType.GetMethod("GetSqlCeProviderFactory");
|
var factoryMethod = proxyType.GetMethod("GetSqlCeProviderFactory");
|
||||||
_factory = (DbProviderFactory)factoryMethod.Invoke(instance, null);
|
_factory = (DbProviderFactory)factoryMethod.Invoke(instance, null);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -78,10 +83,9 @@ public IDatabase GetLogPetaPocoDb(Boolean profiled = true)
|
|||||||
|
|
||||||
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
|
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
|
||||||
{
|
{
|
||||||
if (EnvironmentProvider.IsMono)
|
#if __MonoCS__
|
||||||
{
|
|
||||||
throw new NotSupportedException("SqlCe is not supported in mono");
|
throw new NotSupportedException("SqlCe is not supported in mono");
|
||||||
}
|
#endif
|
||||||
|
|
||||||
lock (initilized)
|
lock (initilized)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
@ -28,6 +29,8 @@ public static void Run(string connectionString, bool trace)
|
|||||||
migrator = new Migrator.Migrator("sqlserverce", connectionString, Assembly.GetAssembly(typeof(MigrationsHelper)));
|
migrator = new Migrator.Migrator("sqlserverce", connectionString, Assembly.GetAssembly(typeof(MigrationsHelper)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
migrator.MigrateToLastVersion();
|
migrator.MigrateToLastVersion();
|
||||||
logger.Info("Database migration completed");
|
logger.Info("Database migration completed");
|
||||||
|
|
||||||
@ -42,10 +45,7 @@ public static void Run(string connectionString, bool trace)
|
|||||||
|
|
||||||
private static void EnsureDatabase(string constr)
|
private static void EnsureDatabase(string constr)
|
||||||
{
|
{
|
||||||
var proxyType = Assembly.Load("NzbDrone.SqlCe").GetExportedTypes()[0];
|
|
||||||
var instance = Activator.CreateInstance(proxyType);
|
|
||||||
var factoryMethod = proxyType.GetMethod("EnsureDatabase");
|
|
||||||
factoryMethod.Invoke(instance, new object[] { constr });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetIndexName(string tableName, params string[] columns)
|
public static string GetIndexName(string tableName, params string[] columns)
|
||||||
|
@ -6,13 +6,13 @@ namespace NzbDrone.SqlCe
|
|||||||
{
|
{
|
||||||
public class SqlCeProxy
|
public class SqlCeProxy
|
||||||
{
|
{
|
||||||
public void EnsureDatabase(string connectionString)
|
public void EnsureDatabase(string constr)
|
||||||
{
|
{
|
||||||
var connection = new SqlCeConnection(connectionString);
|
var connection = new SqlCeConnection(constr);
|
||||||
|
|
||||||
if (!File.Exists(connection.Database))
|
if (!File.Exists(connection.Database))
|
||||||
{
|
{
|
||||||
var engine = new SqlCeEngine(connectionString);
|
var engine = new SqlCeEngine(constr);
|
||||||
engine.CreateDatabase();
|
engine.CreateDatabase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user