diff --git a/NzbDrone.Common/EnvironmentProvider.cs b/NzbDrone.Common/EnvironmentProvider.cs
index 616819ab4..2e3346bf6 100644
--- a/NzbDrone.Common/EnvironmentProvider.cs
+++ b/NzbDrone.Common/EnvironmentProvider.cs
@@ -36,6 +36,11 @@ namespace NzbDrone.Common
}
}
+ public static bool IsMono
+ {
+ get { return Type.GetType("Mono.Runtime") != null; }
+ }
+
public static bool IsDebug
{
get
diff --git a/NzbDrone.Core.Test/CentralDispatchFixture.cs b/NzbDrone.Core.Test/CentralDispatchFixture.cs
index b2766df7a..9c3c0ff52 100644
--- a/NzbDrone.Core.Test/CentralDispatchFixture.cs
+++ b/NzbDrone.Core.Test/CentralDispatchFixture.cs
@@ -5,6 +5,7 @@ using Autofac;
using FluentAssertions;
using NCrunch.Framework;
using NUnit.Framework;
+using NzbDrone.Common;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.ExternalNotification;
@@ -28,9 +29,10 @@ namespace NzbDrone.Core.Test
public CentralDispatchFixture()
{
-#if __MonoCS__
- throw new IgnoreException("SqlCe is not supported");
-#endif
+ if (EnvironmentProvider.IsMono)
+ {
+ throw new IgnoreException("SqlCe is not supported");
+ }
InitLogging();
var dispatch = new CentralDispatch();
diff --git a/NzbDrone.Core.Test/Framework/SqlCeTest.cs b/NzbDrone.Core.Test/Framework/SqlCeTest.cs
index 57c881f7e..18659548b 100644
--- a/NzbDrone.Core.Test/Framework/SqlCeTest.cs
+++ b/NzbDrone.Core.Test/Framework/SqlCeTest.cs
@@ -1,6 +1,7 @@
using System;
using System.IO;
using NUnit.Framework;
+using NzbDrone.Common;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Core;
@@ -16,10 +17,10 @@ namespace NzbDrone.Core.Test.Framework
[SetUp]
public void CoreTestSetup()
{
-
-#if __MonoCS__
- throw new IgnoreException("SqlCe is not supported in mono.");
-#endif
+ if (EnvironmentProvider.IsMono)
+ {
+ throw new IgnoreException("SqlCe is not supported in mono.");
+ }
if (NCrunch.Framework.NCrunchEnvironment.NCrunchIsResident())
{
diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
index 81b13e7ec..2a4408ee0 100644
--- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
+++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
@@ -440,8 +440,9 @@
-
-
+ if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
+
+xcopy /s /y "$(SolutionDir)\SqlCe\*.*" "$(TargetDir)"
if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
diff --git a/NzbDrone.Core/Datastore/ConnectionFactory.cs b/NzbDrone.Core/Datastore/ConnectionFactory.cs
index 35a131ab2..a55bcef55 100644
--- a/NzbDrone.Core/Datastore/ConnectionFactory.cs
+++ b/NzbDrone.Core/Datastore/ConnectionFactory.cs
@@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Configuration;
using System.Data.Common;
-using System.Data.OleDb;
-using System.Data.SqlClient;
using System.Reflection;
using NLog;
using NzbDrone.Common;
@@ -21,22 +19,19 @@ namespace NzbDrone.Core.Datastore
{
Database.Mapper = new CustomeMapper();
-
-#if __MonoCS__
-#else
+ if (EnvironmentProvider.IsMono) return;
var dataSet = (System.Data.DataSet)ConfigurationManager.GetSection("system.data");
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");
+ , "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");
var proxyType = Assembly.Load("NzbDrone.SqlCe").GetExportedTypes()[0];
var instance = Activator.CreateInstance(proxyType);
var factoryMethod = proxyType.GetMethod("GetSqlCeProviderFactory");
_factory = (DbProviderFactory)factoryMethod.Invoke(instance, null);
-#endif
-
}
@@ -83,9 +78,10 @@ namespace NzbDrone.Core.Datastore
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
{
-#if __MonoCS__
- throw new NotSupportedException("SqlCe is not supported in mono");
-#endif
+ if (EnvironmentProvider.IsMono)
+ {
+ throw new NotSupportedException("SqlCe is not supported in mono");
+ }
lock (initilized)
{
diff --git a/NzbDrone.Core/Datastore/MigrationsHelper.cs b/NzbDrone.Core/Datastore/MigrationsHelper.cs
index 5d0c41f6f..3d2086428 100644
--- a/NzbDrone.Core/Datastore/MigrationsHelper.cs
+++ b/NzbDrone.Core/Datastore/MigrationsHelper.cs
@@ -1,6 +1,5 @@
using System.Linq;
using System;
-using System.IO;
using System.Reflection;
using NLog;
@@ -28,9 +27,7 @@ namespace NzbDrone.Core.Datastore
{
migrator = new Migrator.Migrator("sqlserverce", connectionString, Assembly.GetAssembly(typeof(MigrationsHelper)));
}
-
-
-
+
migrator.MigrateToLastVersion();
logger.Info("Database migration completed");
@@ -45,7 +42,10 @@ namespace NzbDrone.Core.Datastore
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)
diff --git a/NzbDrone.SqlCe/SqlCeProxy.cs b/NzbDrone.SqlCe/SqlCeProxy.cs
index fb405083a..6577d8d97 100644
--- a/NzbDrone.SqlCe/SqlCeProxy.cs
+++ b/NzbDrone.SqlCe/SqlCeProxy.cs
@@ -6,13 +6,13 @@ namespace NzbDrone.SqlCe
{
public class SqlCeProxy
{
- public void EnsureDatabase(string constr)
+ public void EnsureDatabase(string connectionString)
{
- var connection = new SqlCeConnection(constr);
+ var connection = new SqlCeConnection(connectionString);
if (!File.Exists(connection.Database))
{
- var engine = new SqlCeEngine(constr);
+ var engine = new SqlCeEngine(connectionString);
engine.CreateDatabase();
}
}