From 2903d5d58128a7ef84527e922b055062c1e1d9bd Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 16 Feb 2013 15:29:21 -0800 Subject: [PATCH] WTFFFFF! --- NzbDrone.Common/EnvironmentProvider.cs | 11 ++++++ NzbDrone.Core.Test/CentralDispatchFixture.cs | 8 +++-- NzbDrone.Core.Test/Framework/SqlCeTest.cs | 9 ++--- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 5 +-- NzbDrone.Core/Datastore/ConnectionFactory.cs | 27 ++++++--------- .../Datastore/Migrations/NzbDroneMigration.cs | 6 ++-- NzbDrone.Core/Datastore/MigrationsHelper.cs | 10 ++---- NzbDrone.Core/Datastore/SqlCeProxy.cs | 32 ++++++++++++++++++ NzbDrone.Core/NzbDrone.Core.csproj | 1 + NzbDrone.SqlCe/SqlCeProxy.cs | 8 +++-- SqlCe/NzbDrone.SqlCe.dll | Bin 4096 -> 4096 bytes 11 files changed, 78 insertions(+), 39 deletions(-) create mode 100644 NzbDrone.Core/Datastore/SqlCeProxy.cs diff --git a/NzbDrone.Common/EnvironmentProvider.cs b/NzbDrone.Common/EnvironmentProvider.cs index 616819ab4..cb3585c85 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 @@ -60,6 +65,12 @@ namespace NzbDrone.Common { get { + + if(IsMono) + { + return AppDomain.CurrentDomain.BaseDirectory; + } + string applicationPath; applicationPath = CrawlToRoot(StartUpPath); 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..d68ffaaab 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,16 @@ 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"); - - 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 + , "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"); + _factory = SqlCeProxy.GetSqlCeProviderFactory(); } @@ -83,9 +75,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/Migrations/NzbDroneMigration.cs b/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs index 3e44c4025..d846b4ea0 100644 --- a/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs +++ b/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs @@ -1,6 +1,8 @@ using System; +using System.Data.Common; using System.Data.SqlClient; using System.Linq; +using System.Reflection; using Migrator.Framework; using NzbDrone.Common; @@ -35,8 +37,8 @@ namespace NzbDrone.Core.Datastore.Migrations protected EloqueraDb GetObjectDb() { - var sqlCeConnection = new SqlConnection(Database.ConnectionString); - + var sqlCeConnection = SqlCeProxy.EnsureDatabase(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 5d0c41f6f..6e7cc5e14 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; @@ -13,7 +12,7 @@ namespace NzbDrone.Core.Datastore public static void Run(string connectionString, bool trace) { - EnsureDatabase(connectionString); + SqlCeProxy.EnsureDatabase(connectionString); logger.Trace("Preparing to run database migration"); @@ -29,8 +28,6 @@ namespace NzbDrone.Core.Datastore migrator = new Migrator.Migrator("sqlserverce", connectionString, Assembly.GetAssembly(typeof(MigrationsHelper))); } - - migrator.MigrateToLastVersion(); logger.Info("Database migration completed"); @@ -43,10 +40,7 @@ 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 new file mode 100644 index 000000000..99c2f8ccc --- /dev/null +++ b/NzbDrone.Core/Datastore/SqlCeProxy.cs @@ -0,0 +1,32 @@ +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 654a42ea9..43a517c9b 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -297,6 +297,7 @@ + diff --git a/NzbDrone.SqlCe/SqlCeProxy.cs b/NzbDrone.SqlCe/SqlCeProxy.cs index fb405083a..c5944fb50 100644 --- a/NzbDrone.SqlCe/SqlCeProxy.cs +++ b/NzbDrone.SqlCe/SqlCeProxy.cs @@ -6,15 +6,17 @@ namespace NzbDrone.SqlCe { public class SqlCeProxy { - public void EnsureDatabase(string constr) + public SqlCeConnection 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(); } + + return connection; } public DbProviderFactory GetSqlCeProviderFactory() diff --git a/SqlCe/NzbDrone.SqlCe.dll b/SqlCe/NzbDrone.SqlCe.dll index 03d1098229d39305176a24a08e0511bd4554670f..9cde163247f3eb5ccd06a0f566eec29be6e6b53f 100644 GIT binary patch delta 632 zcmX|Cz-s6D?t5w5>IXTGSw-))J6H4c3r^Kno3`QjkR2;K73p zQfpc;ba@v+kG%-JMHInTHV6;Wyt5Z{{)cUe&5vOEnSq z*o$G>vLEHmLB}oL_n+ibky_S?0 zghEl775zSSVE2px7z1I^-{E*!7lTK<0*GcR(^I9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