From 52e6d0932563deea957251ab318cb3a9968fc8b3 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 28 Aug 2011 10:43:01 -0700 Subject: [PATCH 1/2] Fixed port, added broken parser test --- IISExpress/AppServer/applicationhost.config | 2 +- NzbDrone.Core.Test/ParserTest.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/IISExpress/AppServer/applicationhost.config b/IISExpress/AppServer/applicationhost.config index c04eb1d2c..f1e3a3538 100644 --- a/IISExpress/AppServer/applicationhost.config +++ b/IISExpress/AppServer/applicationhost.config @@ -125,7 +125,7 @@ - + diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index 665cea1de..f75a66f7f 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -59,6 +59,7 @@ namespace NzbDrone.Core.Test [TestCase(@"D:\shares\TV Shows\Parks And Recreation\Season 2\S02E21 - 94 Meetings - 720p TV.mkv", 2, 21)] [TestCase(@"D:\shares\TV Shows\Battlestar Galactica (2003)\Season 2\S02E21.avi", 2, 21)] [TestCase("C:/Test/TV/Chuck.4x05.HDTV.XviD-LOL", 4, 5)] + [TestCase(@"P:\TV Shows\House\Season 6\S06E13 - 5 to 9 - 720p BluRay.mkv", 6, 13)] public void PathParse_tests(string path, int season, int episode) { var result = Parser.ParsePath(path); From a5527df584dd19c30b4f1061d8e4fd379e21bfdd Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 28 Aug 2011 10:43:33 -0700 Subject: [PATCH 2/2] Fixed petapoco's craptastic connection management. --- NzbDrone.Core/Datastore/Connection.cs | 20 ++++++------- .../Datastore/PetaDbProviderFactory.cs | 28 +++++++++++++++++++ NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs | 25 ++++++----------- NzbDrone.Core/NzbDrone.Core.csproj | 1 + 4 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 NzbDrone.Core/Datastore/PetaDbProviderFactory.cs diff --git a/NzbDrone.Core/Datastore/Connection.cs b/NzbDrone.Core/Datastore/Connection.cs index 12682555d..7c76e2b3b 100644 --- a/NzbDrone.Core/Datastore/Connection.cs +++ b/NzbDrone.Core/Datastore/Connection.cs @@ -45,19 +45,17 @@ namespace NzbDrone.Core.Datastore 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; + var factory = new PetaDbProviderFactory + { + IsProfiled = profiled + }; - if (connection.State != ConnectionState.Open) - connection.Open(); + var db = new Database(connectionString, factory, Database.DBType.SqlServerCE) + { + KeepConnectionAlive = true, + ForceDateTimesToUtc = false, + }; return db; } diff --git a/NzbDrone.Core/Datastore/PetaDbProviderFactory.cs b/NzbDrone.Core/Datastore/PetaDbProviderFactory.cs new file mode 100644 index 000000000..593f0c6fa --- /dev/null +++ b/NzbDrone.Core/Datastore/PetaDbProviderFactory.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Data.SqlServerCe; +using System.Linq; +using System.Text; +using MvcMiniProfiler.Data; + +namespace NzbDrone.Core.Datastore +{ + class PetaDbProviderFactory : DbProviderFactory + { + public Boolean IsProfiled { get; set; } + + public override DbConnection CreateConnection() + { + var sqliteConnection = new SqlCeConnection(); + DbConnection connection = sqliteConnection; + + if (IsProfiled) + { + connection = ProfiledDbConnection.Get(sqliteConnection); + } + + return connection; + } + } +} diff --git a/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs b/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs index 9dee00131..3497f2794 100644 --- a/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs +++ b/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs @@ -282,7 +282,7 @@ namespace PetaPoco { _sharedConnection = connection; _connectionString = connection.ConnectionString; - _sharedConnectionDepth = 2; // Prevent closing external connection + _dbType = dbType; CommonConstruct(); } @@ -294,10 +294,11 @@ namespace PetaPoco CommonConstruct(); } - public Database(string connectionString, DbProviderFactory provider) + public Database(string connectionString, DbProviderFactory provider, DBType dbType) { _connectionString = connectionString; _factory = provider; + _dbType = dbType; CommonConstruct(); } @@ -375,6 +376,7 @@ namespace PetaPoco { // Automatically close one open connection reference // (Works with KeepConnectionAlive and manually opening a shared connection) + KeepConnectionAlive = false; CloseSharedConnection(); } @@ -384,18 +386,14 @@ namespace PetaPoco // Open a connection (can be nested) public void OpenSharedConnection() { - if (_sharedConnectionDepth == 0) + if (_sharedConnection == null || _sharedConnection.State == ConnectionState.Closed || _sharedConnection.State == ConnectionState.Broken) { _sharedConnection = _factory.CreateConnection(); _sharedConnection.ConnectionString = _connectionString; _sharedConnection.Open(); _sharedConnection = OnConnectionOpened(_sharedConnection); - - if (KeepConnectionAlive) - _sharedConnectionDepth++; // Make sure you call Dispose } - _sharedConnectionDepth++; } /// @@ -404,15 +402,11 @@ namespace PetaPoco // Close a previously opened connection public void CloseSharedConnection() { - if (_sharedConnectionDepth > 0) + if (!KeepConnectionAlive && _sharedConnection != null) { - _sharedConnectionDepth--; - if (_sharedConnectionDepth == 0) - { - OnConnectionClosing(_sharedConnection); - _sharedConnection.Dispose(); - _sharedConnection = null; - } + OnConnectionClosing(_sharedConnection); + _sharedConnection.Dispose(); + _sharedConnection = null; } } @@ -2530,7 +2524,6 @@ namespace PetaPoco DbProviderFactory _factory; IDbConnection _sharedConnection; IDbTransaction _transaction; - int _sharedConnectionDepth; int _transactionDepth; bool _transactionCancelled; string _lastSql; diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index b08a5880e..4e316ab6f 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -178,6 +178,7 @@ +