diff --git a/NzbDrone.Common/EnvironmentProvider.cs b/NzbDrone.Common/EnvironmentProvider.cs index 2e3346bf6..616819ab4 100644 --- a/NzbDrone.Common/EnvironmentProvider.cs +++ b/NzbDrone.Common/EnvironmentProvider.cs @@ -36,11 +36,6 @@ 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 9c3c0ff52..b2766df7a 100644 --- a/NzbDrone.Core.Test/CentralDispatchFixture.cs +++ b/NzbDrone.Core.Test/CentralDispatchFixture.cs @@ -5,7 +5,6 @@ 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; @@ -29,10 +28,9 @@ namespace NzbDrone.Core.Test public CentralDispatchFixture() { - if (EnvironmentProvider.IsMono) - { - throw new IgnoreException("SqlCe is not supported"); - } +#if __MonoCS__ + throw new IgnoreException("SqlCe is not supported"); +#endif InitLogging(); var dispatch = new CentralDispatch(); diff --git a/NzbDrone.Core.Test/Framework/SqlCeTest.cs b/NzbDrone.Core.Test/Framework/SqlCeTest.cs index 18659548b..57c881f7e 100644 --- a/NzbDrone.Core.Test/Framework/SqlCeTest.cs +++ b/NzbDrone.Core.Test/Framework/SqlCeTest.cs @@ -1,7 +1,6 @@ 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; @@ -17,10 +16,10 @@ namespace NzbDrone.Core.Test.Framework [SetUp] public void CoreTestSetup() { - if (EnvironmentProvider.IsMono) - { - throw new IgnoreException("SqlCe is not supported in mono."); - } + +#if __MonoCS__ + throw new IgnoreException("SqlCe is not supported in mono."); +#endif if (NCrunch.Framework.NCrunchEnvironment.NCrunchIsResident()) { diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 2a4408ee0..81b13e7ec 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -440,9 +440,8 @@ - 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 d68ffaaab..35a131ab2 100644 --- a/NzbDrone.Core/Datastore/ConnectionFactory.cs +++ b/NzbDrone.Core/Datastore/ConnectionFactory.cs @@ -2,6 +2,8 @@ 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; @@ -19,16 +21,22 @@ namespace NzbDrone.Core.Datastore { Database.Mapper = new CustomeMapper(); - if (EnvironmentProvider.IsMono) return; + +#if __MonoCS__ +#else 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 - _factory = SqlCeProxy.GetSqlCeProviderFactory(); } @@ -75,10 +83,9 @@ namespace NzbDrone.Core.Datastore public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true) { - if (EnvironmentProvider.IsMono) - { - throw new NotSupportedException("SqlCe is not supported in mono"); - } +#if __MonoCS__ + throw new NotSupportedException("SqlCe is not supported in mono"); +#endif lock (initilized) { diff --git a/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs b/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs index d846b4ea0..3e44c4025 100644 --- a/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs +++ b/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs @@ -1,8 +1,6 @@ using System; -using System.Data.Common; using System.Data.SqlClient; using System.Linq; -using System.Reflection; using Migrator.Framework; using NzbDrone.Common; @@ -37,8 +35,8 @@ namespace NzbDrone.Core.Datastore.Migrations protected EloqueraDb GetObjectDb() { - var sqlCeConnection = SqlCeProxy.EnsureDatabase(Database.ConnectionString); - + var sqlCeConnection = new SqlConnection(Database.ConnectionString); + var eqPath = sqlCeConnection.Database.Replace(".sdf", ".eq"); return new EloqueraDbFactory(new EnvironmentProvider()).Create(eqPath); } diff --git a/NzbDrone.Core/Datastore/MigrationsHelper.cs b/NzbDrone.Core/Datastore/MigrationsHelper.cs index 6e7cc5e14..5d0c41f6f 100644 --- a/NzbDrone.Core/Datastore/MigrationsHelper.cs +++ b/NzbDrone.Core/Datastore/MigrationsHelper.cs @@ -1,5 +1,6 @@ using System.Linq; using System; +using System.IO; using System.Reflection; using NLog; @@ -12,7 +13,7 @@ namespace NzbDrone.Core.Datastore public static void Run(string connectionString, bool trace) { - SqlCeProxy.EnsureDatabase(connectionString); + EnsureDatabase(connectionString); logger.Trace("Preparing to run database migration"); @@ -28,6 +29,8 @@ namespace NzbDrone.Core.Datastore migrator = new Migrator.Migrator("sqlserverce", connectionString, Assembly.GetAssembly(typeof(MigrationsHelper))); } + + migrator.MigrateToLastVersion(); logger.Info("Database migration completed"); @@ -40,7 +43,10 @@ namespace NzbDrone.Core.Datastore } } - + private static void EnsureDatabase(string constr) + { + + } public static string GetIndexName(string tableName, params string[] columns) { diff --git a/NzbDrone.Core/Datastore/SqlCeProxy.cs b/NzbDrone.Core/Datastore/SqlCeProxy.cs deleted file mode 100644 index 99c2f8ccc..000000000 --- a/NzbDrone.Core/Datastore/SqlCeProxy.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Data.Common; -using System.Linq; -using System.Reflection; - -namespace NzbDrone.Core.Datastore -{ - public static class SqlCeProxy - { - private static readonly object instance; - private static readonly Type proxyType; - - static SqlCeProxy() - { - proxyType = Assembly.Load("NzbDrone.SqlCe").GetExportedTypes()[0]; - instance = Activator.CreateInstance(proxyType); - } - - public static DbConnection EnsureDatabase(string connectionString) - { - var factoryMethod = proxyType.GetMethod("EnsureDatabase"); - return (DbConnection)factoryMethod.Invoke(instance, new object[] { connectionString }); - } - - public static DbProviderFactory GetSqlCeProviderFactory() - { - var factoryMethod = proxyType.GetMethod("GetSqlCeProviderFactory"); - return (DbProviderFactory)factoryMethod.Invoke(instance, null); - } - } - -} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 43a517c9b..654a42ea9 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -297,7 +297,6 @@ - diff --git a/NzbDrone.SqlCe/SqlCeProxy.cs b/NzbDrone.SqlCe/SqlCeProxy.cs index c5944fb50..fb405083a 100644 --- a/NzbDrone.SqlCe/SqlCeProxy.cs +++ b/NzbDrone.SqlCe/SqlCeProxy.cs @@ -6,17 +6,15 @@ namespace NzbDrone.SqlCe { public class SqlCeProxy { - public SqlCeConnection EnsureDatabase(string connectionString) + public void EnsureDatabase(string constr) { - var connection = new SqlCeConnection(connectionString); + var connection = new SqlCeConnection(constr); if (!File.Exists(connection.Database)) { - var engine = new SqlCeEngine(connectionString); + var engine = new SqlCeEngine(constr); engine.CreateDatabase(); } - - return connection; } public DbProviderFactory GetSqlCeProviderFactory() diff --git a/SqlCe/NzbDrone.SqlCe.dll b/SqlCe/NzbDrone.SqlCe.dll index 9cde16324..03d109822 100644 Binary files a/SqlCe/NzbDrone.SqlCe.dll and b/SqlCe/NzbDrone.SqlCe.dll differ