From 31a119fa424d23a557c5c4e1bfaae043ab8089ba Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 10 Feb 2016 13:13:15 -0500 Subject: [PATCH 1/5] update naming project --- .../MediaBrowser.Server.Implementations.csproj | 4 ++-- MediaBrowser.Server.Implementations/packages.config | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index d4e3bcd77d..f3c28b61ca 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -51,9 +51,9 @@ ..\packages\Interfaces.IO.1.0.0.5\lib\portable-net45+sl4+wp71+win8+wpa81\Interfaces.IO.dll - + False - ..\packages\MediaBrowser.Naming.1.0.0.46\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll + ..\packages\MediaBrowser.Naming.1.0.0.47\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll ..\packages\morelinq.1.4.0\lib\net35\MoreLinq.dll diff --git a/MediaBrowser.Server.Implementations/packages.config b/MediaBrowser.Server.Implementations/packages.config index 14df2f718a..98c27786f2 100644 --- a/MediaBrowser.Server.Implementations/packages.config +++ b/MediaBrowser.Server.Implementations/packages.config @@ -3,7 +3,7 @@ - + From 0216742945f2d2a2dda1b0da35d3c90a3bda06a2 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 10 Feb 2016 13:13:24 -0500 Subject: [PATCH 2/5] update db inheritance --- .../Activity/ActivityRepository.cs | 60 ++--- .../Persistence/BaseSqliteRepository.cs | 38 +++ .../Persistence/SqliteItemRepository.cs | 253 +++++++----------- .../Sync/SyncRepository.cs | 20 +- .../ApplicationHost.cs | 2 +- 5 files changed, 157 insertions(+), 216 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs b/MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs index f491a5c442..3a89d6928c 100644 --- a/MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs +++ b/MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs @@ -14,19 +14,17 @@ using System.Threading.Tasks; namespace MediaBrowser.Server.Implementations.Activity { - public class ActivityRepository : IActivityRepository, IDisposable + public class ActivityRepository : BaseSqliteRepository, IActivityRepository { private IDbConnection _connection; - private readonly ILogger _logger; - private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1); private readonly IServerApplicationPaths _appPaths; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private IDbCommand _saveActivityCommand; - public ActivityRepository(ILogger logger, IServerApplicationPaths appPaths) + public ActivityRepository(ILogManager logManager, IServerApplicationPaths appPaths) + : base(logManager) { - _logger = logger; _appPaths = appPaths; } @@ -34,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.Activity { var dbFile = Path.Combine(_appPaths.DataPath, "activitylog.db"); - _connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false); + _connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); string[] queries = { @@ -47,7 +45,7 @@ namespace MediaBrowser.Server.Implementations.Activity "pragma shrink_memory" }; - _connection.RunQueries(queries, _logger); + _connection.RunQueries(queries, Logger); PrepareStatements(); } @@ -82,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.Activity throw new ArgumentNullException("entry"); } - await _writeLock.WaitAsync().ConfigureAwait(false); + await WriteLock.WaitAsync().ConfigureAwait(false); IDbTransaction transaction = null; @@ -119,7 +117,7 @@ namespace MediaBrowser.Server.Implementations.Activity } catch (Exception e) { - _logger.ErrorException("Failed to save record:", e); + Logger.ErrorException("Failed to save record:", e); if (transaction != null) { @@ -135,7 +133,7 @@ namespace MediaBrowser.Server.Implementations.Activity transaction.Dispose(); } - _writeLock.Release(); + WriteLock.Release(); } } @@ -264,45 +262,17 @@ namespace MediaBrowser.Server.Implementations.Activity return info; } - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() + protected override void CloseConnection() { - Dispose(true); - GC.SuppressFinalize(this); - } - - private readonly object _disposeLock = new object(); - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - if (dispose) + if (_connection != null) { - try + if (_connection.IsOpen()) { - lock (_disposeLock) - { - if (_connection != null) - { - if (_connection.IsOpen()) - { - _connection.Close(); - } + _connection.Close(); + } - _connection.Dispose(); - _connection = null; - } - } - } - catch (Exception ex) - { - _logger.ErrorException("Error disposing database", ex); - } + _connection.Dispose(); + _connection = null; } } } diff --git a/MediaBrowser.Server.Implementations/Persistence/BaseSqliteRepository.cs b/MediaBrowser.Server.Implementations/Persistence/BaseSqliteRepository.cs index cac112b6c3..3959078449 100644 --- a/MediaBrowser.Server.Implementations/Persistence/BaseSqliteRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/BaseSqliteRepository.cs @@ -1,6 +1,8 @@ using MediaBrowser.Model.Logging; using System; +using System.Data; using System.Threading; +using System.Threading.Tasks; namespace MediaBrowser.Server.Implementations.Persistence { @@ -14,12 +16,48 @@ namespace MediaBrowser.Server.Implementations.Persistence Logger = logManager.GetLogger(GetType().Name); } + private bool _disposed; + protected void CheckDisposed() + { + if (_disposed) + { + throw new ObjectDisposedException(GetType().Name + " has been disposed and cannot be accessed."); + } + } + public void Dispose() { + _disposed = true; Dispose(true); GC.SuppressFinalize(this); } + protected async Task Vacuum(IDbConnection connection) + { + CheckDisposed(); + + await WriteLock.WaitAsync().ConfigureAwait(false); + + try + { + using (var cmd = connection.CreateCommand()) + { + cmd.CommandText = "vacuum"; + cmd.ExecuteNonQuery(); + } + } + catch (Exception e) + { + Logger.ErrorException("Failed to vacuum:", e); + + throw; + } + finally + { + WriteLock.Release(); + } + } + private readonly object _disposeLock = new object(); /// diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 7898dc1ef5..ed1aeac9f0 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -26,12 +26,10 @@ namespace MediaBrowser.Server.Implementations.Persistence /// /// Class SQLiteItemRepository /// - public class SqliteItemRepository : IItemRepository + public class SqliteItemRepository : BaseSqliteRepository, IItemRepository { private IDbConnection _connection; - private readonly ILogger _logger; - private readonly TypeMapper _typeMapper = new TypeMapper(); /// @@ -96,6 +94,7 @@ namespace MediaBrowser.Server.Implementations.Persistence /// jsonSerializer /// public SqliteItemRepository(IApplicationPaths appPaths, IJsonSerializer jsonSerializer, ILogManager logManager) + : base(logManager) { if (appPaths == null) { @@ -110,8 +109,6 @@ namespace MediaBrowser.Server.Implementations.Persistence _jsonSerializer = jsonSerializer; _criticReviewsPath = Path.Combine(_appPaths.DataPath, "critic-reviews"); - - _logger = logManager.GetLogger(GetType().Name); } private const string ChaptersTableName = "Chapters2"; @@ -124,7 +121,7 @@ namespace MediaBrowser.Server.Implementations.Persistence { var dbFile = Path.Combine(_appPaths.DataPath, "library.db"); - _connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false); + _connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); var createMediaStreamsTableCommand = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, CodecTag TEXT NULL, Comment TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))"; @@ -158,76 +155,76 @@ namespace MediaBrowser.Server.Implementations.Persistence "pragma shrink_memory" }; - _connection.RunQueries(queries, _logger); + _connection.RunQueries(queries, Logger); - _connection.AddColumn(_logger, "AncestorIds", "AncestorIdText", "Text"); + _connection.AddColumn(Logger, "AncestorIds", "AncestorIdText", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "Path", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "StartDate", "DATETIME"); - _connection.AddColumn(_logger, "TypedBaseItems", "EndDate", "DATETIME"); - _connection.AddColumn(_logger, "TypedBaseItems", "ChannelId", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsMovie", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsSports", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsKids", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "CommunityRating", "Float"); - _connection.AddColumn(_logger, "TypedBaseItems", "CustomRating", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "IndexNumber", "INT"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsLocked", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "Name", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "OfficialRating", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "Path", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "StartDate", "DATETIME"); + _connection.AddColumn(Logger, "TypedBaseItems", "EndDate", "DATETIME"); + _connection.AddColumn(Logger, "TypedBaseItems", "ChannelId", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsMovie", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsSports", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsKids", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "CommunityRating", "Float"); + _connection.AddColumn(Logger, "TypedBaseItems", "CustomRating", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "IndexNumber", "INT"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsLocked", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "Name", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "OfficialRating", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "MediaType", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "Overview", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "ParentIndexNumber", "INT"); - _connection.AddColumn(_logger, "TypedBaseItems", "PremiereDate", "DATETIME"); - _connection.AddColumn(_logger, "TypedBaseItems", "ProductionYear", "INT"); - _connection.AddColumn(_logger, "TypedBaseItems", "ParentId", "GUID"); - _connection.AddColumn(_logger, "TypedBaseItems", "Genres", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "ParentalRatingValue", "INT"); - _connection.AddColumn(_logger, "TypedBaseItems", "SchemaVersion", "INT"); - _connection.AddColumn(_logger, "TypedBaseItems", "SortName", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "RunTimeTicks", "BIGINT"); + _connection.AddColumn(Logger, "TypedBaseItems", "MediaType", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "Overview", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "ParentIndexNumber", "INT"); + _connection.AddColumn(Logger, "TypedBaseItems", "PremiereDate", "DATETIME"); + _connection.AddColumn(Logger, "TypedBaseItems", "ProductionYear", "INT"); + _connection.AddColumn(Logger, "TypedBaseItems", "ParentId", "GUID"); + _connection.AddColumn(Logger, "TypedBaseItems", "Genres", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "ParentalRatingValue", "INT"); + _connection.AddColumn(Logger, "TypedBaseItems", "SchemaVersion", "INT"); + _connection.AddColumn(Logger, "TypedBaseItems", "SortName", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "RunTimeTicks", "BIGINT"); - _connection.AddColumn(_logger, "TypedBaseItems", "OfficialRatingDescription", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "HomePageUrl", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "VoteCount", "INT"); - _connection.AddColumn(_logger, "TypedBaseItems", "DisplayMediaType", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "DateCreated", "DATETIME"); - _connection.AddColumn(_logger, "TypedBaseItems", "DateModified", "DATETIME"); + _connection.AddColumn(Logger, "TypedBaseItems", "OfficialRatingDescription", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "HomePageUrl", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "VoteCount", "INT"); + _connection.AddColumn(Logger, "TypedBaseItems", "DisplayMediaType", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "DateCreated", "DATETIME"); + _connection.AddColumn(Logger, "TypedBaseItems", "DateModified", "DATETIME"); - _connection.AddColumn(_logger, "TypedBaseItems", "ForcedSortName", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsOffline", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "LocationType", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "ForcedSortName", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsOffline", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "LocationType", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsSeries", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsLive", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsNews", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsPremiere", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsSeries", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsLive", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsNews", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsPremiere", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "EpisodeTitle", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsRepeat", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "EpisodeTitle", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsRepeat", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "PreferredMetadataLanguage", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "PreferredMetadataCountryCode", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsHD", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "ExternalEtag", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "DateLastRefreshed", "DATETIME"); + _connection.AddColumn(Logger, "TypedBaseItems", "PreferredMetadataLanguage", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "PreferredMetadataCountryCode", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsHD", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "ExternalEtag", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "DateLastRefreshed", "DATETIME"); - _connection.AddColumn(_logger, "TypedBaseItems", "DateLastSaved", "DATETIME"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsInMixedFolder", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "LockedFields", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "Studios", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "Audio", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "ExternalServiceId", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "Tags", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "IsFolder", "BIT"); - _connection.AddColumn(_logger, "TypedBaseItems", "InheritedParentalRatingValue", "INT"); - _connection.AddColumn(_logger, "TypedBaseItems", "UnratedType", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "TopParentId", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "DateLastSaved", "DATETIME"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsInMixedFolder", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "LockedFields", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "Studios", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "Audio", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "ExternalServiceId", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "Tags", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsFolder", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "InheritedParentalRatingValue", "INT"); + _connection.AddColumn(Logger, "TypedBaseItems", "UnratedType", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "TopParentId", "Text"); PrepareStatements(); - new MediaStreamColumns(_connection, _logger).AddColumns(); + new MediaStreamColumns(_connection, Logger).AddColumns(); var chapterDbFile = Path.Combine(_appPaths.DataPath, "chapters.db"); if (File.Exists(chapterDbFile)) @@ -256,11 +253,11 @@ namespace MediaBrowser.Server.Implementations.Persistence "REPLACE INTO mediastreams("+columns+") SELECT "+columns+" FROM MediaInfoOld.mediastreams;" }; - _connection.RunQueries(queries, _logger); + _connection.RunQueries(queries, Logger); } catch (Exception ex) { - _logger.ErrorException("Error migrating media info database", ex); + Logger.ErrorException("Error migrating media info database", ex); } finally { @@ -280,11 +277,11 @@ namespace MediaBrowser.Server.Implementations.Persistence "REPLACE INTO "+ChaptersTableName+"(ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath) SELECT ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath FROM ChaptersOld.Chapters;" }; - _connection.RunQueries(queries, _logger); + _connection.RunQueries(queries, Logger); } catch (Exception ex) { - _logger.ErrorException("Error migrating chapter database", ex); + Logger.ErrorException("Error migrating chapter database", ex); } finally { @@ -300,15 +297,10 @@ namespace MediaBrowser.Server.Implementations.Persistence } catch (Exception ex) { - _logger.ErrorException("Error deleting file {0}", ex, file); + Logger.ErrorException("Error deleting file {0}", ex, file); } } - /// - /// The _write lock - /// - private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1); - private readonly string[] _retriveItemColumns = { "type", @@ -583,7 +575,7 @@ namespace MediaBrowser.Server.Implementations.Persistence CheckDisposed(); - await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); + await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; @@ -761,7 +753,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } catch (Exception e) { - _logger.ErrorException("Failed to save items:", e); + Logger.ErrorException("Failed to save items:", e); if (transaction != null) { @@ -777,7 +769,7 @@ namespace MediaBrowser.Server.Implementations.Persistence transaction.Dispose(); } - _writeLock.Release(); + WriteLock.Release(); } } @@ -821,7 +813,7 @@ namespace MediaBrowser.Server.Implementations.Persistence if (type == null) { - _logger.Debug("Unknown type {0}", typeString); + Logger.Debug("Unknown type {0}", typeString); return null; } @@ -836,7 +828,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } catch (SerializationException ex) { - _logger.ErrorException("Error deserializing item", ex); + Logger.ErrorException("Error deserializing item", ex); } if (item == null) @@ -1237,7 +1229,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cancellationToken.ThrowIfCancellationRequested(); - await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); + await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; @@ -1284,7 +1276,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } catch (Exception e) { - _logger.ErrorException("Failed to save chapters:", e); + Logger.ErrorException("Failed to save chapters:", e); if (transaction != null) { @@ -1300,62 +1292,21 @@ namespace MediaBrowser.Server.Implementations.Persistence transaction.Dispose(); } - _writeLock.Release(); + WriteLock.Release(); } } - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() + protected override void CloseConnection() { - Dispose(true); - GC.SuppressFinalize(this); - } - - private readonly object _disposeLock = new object(); - - private bool _disposed; - private void CheckDisposed() - { - if (_disposed) + if (_connection != null) { - throw new ObjectDisposedException(GetType().Name + " has been disposed and cannot be accessed."); - } - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - if (dispose) - { - _disposed = true; - - try + if (_connection.IsOpen()) { - lock (_disposeLock) - { - _writeLock.Wait(); - - if (_connection != null) - { - if (_connection.IsOpen()) - { - _connection.Close(); - } - - _connection.Dispose(); - _connection = null; - } - } - } - catch (Exception ex) - { - _logger.ErrorException("Error disposing database", ex); + _connection.Close(); } + + _connection.Dispose(); + _connection = null; } } @@ -1399,7 +1350,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.Parameters.Add(cmd, "@ParentId", DbType.Guid).Value = parentId; - //_logger.Debug(cmd.CommandText); + //Logger.Debug(cmd.CommandText); using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) { @@ -1474,7 +1425,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture); } - //_logger.Debug(cmd.CommandText); + //Logger.Debug(cmd.CommandText); using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) { @@ -1526,7 +1477,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.CommandText += "; select count (guid) from TypedBaseItems" + whereTextWithoutPaging; - _logger.Debug(cmd.CommandText); + Logger.Debug(cmd.CommandText); var list = new List(); var count = 0; @@ -1609,7 +1560,7 @@ namespace MediaBrowser.Server.Implementations.Persistence var list = new List(); - _logger.Debug(cmd.CommandText); + Logger.Debug(cmd.CommandText); using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) { @@ -1662,7 +1613,7 @@ namespace MediaBrowser.Server.Implementations.Persistence var list = new List>(); var count = 0; - _logger.Debug(cmd.CommandText); + Logger.Debug(cmd.CommandText); using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { @@ -1731,7 +1682,7 @@ namespace MediaBrowser.Server.Implementations.Persistence var list = new List(); var count = 0; - _logger.Debug(cmd.CommandText); + Logger.Debug(cmd.CommandText); using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { @@ -2075,7 +2026,7 @@ namespace MediaBrowser.Server.Implementations.Persistence return; } - await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); + await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; @@ -2107,7 +2058,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } catch (Exception e) { - _logger.ErrorException("Error running query:", e); + Logger.ErrorException("Error running query:", e); if (transaction != null) { @@ -2123,7 +2074,7 @@ namespace MediaBrowser.Server.Implementations.Persistence transaction.Dispose(); } - _writeLock.Release(); + WriteLock.Release(); } } @@ -2168,7 +2119,7 @@ namespace MediaBrowser.Server.Implementations.Persistence CheckDisposed(); - await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); + await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; @@ -2219,7 +2170,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } catch (Exception e) { - _logger.ErrorException("Failed to save children:", e); + Logger.ErrorException("Failed to save children:", e); if (transaction != null) { @@ -2235,7 +2186,7 @@ namespace MediaBrowser.Server.Implementations.Persistence transaction.Dispose(); } - _writeLock.Release(); + WriteLock.Release(); } } @@ -2253,7 +2204,7 @@ namespace MediaBrowser.Server.Implementations.Persistence CheckDisposed(); - await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); + await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; @@ -2292,7 +2243,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } catch (Exception e) { - _logger.ErrorException("Failed to save children:", e); + Logger.ErrorException("Failed to save children:", e); if (transaction != null) { @@ -2308,7 +2259,7 @@ namespace MediaBrowser.Server.Implementations.Persistence transaction.Dispose(); } - _writeLock.Release(); + WriteLock.Release(); } } @@ -2482,7 +2433,7 @@ namespace MediaBrowser.Server.Implementations.Persistence var cancellationToken = CancellationToken.None; - await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); + await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; @@ -2528,7 +2479,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } catch (Exception e) { - _logger.ErrorException("Failed to save people:", e); + Logger.ErrorException("Failed to save people:", e); if (transaction != null) { @@ -2544,7 +2495,7 @@ namespace MediaBrowser.Server.Implementations.Persistence transaction.Dispose(); } - _writeLock.Release(); + WriteLock.Release(); } } @@ -2631,7 +2582,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cancellationToken.ThrowIfCancellationRequested(); - await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); + await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; @@ -2703,7 +2654,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } catch (Exception e) { - _logger.ErrorException("Failed to save media streams:", e); + Logger.ErrorException("Failed to save media streams:", e); if (transaction != null) { @@ -2719,7 +2670,7 @@ namespace MediaBrowser.Server.Implementations.Persistence transaction.Dispose(); } - _writeLock.Release(); + WriteLock.Release(); } } diff --git a/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs b/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs index d266a534d7..7a1f276f91 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs @@ -64,7 +64,7 @@ namespace MediaBrowser.Server.Implementations.Sync _connection.AddColumn(Logger, "SyncJobs", "Profile", "TEXT"); _connection.AddColumn(Logger, "SyncJobs", "Bitrate", "INT"); - + PrepareStatements(); } @@ -800,24 +800,6 @@ namespace MediaBrowser.Server.Implementations.Sync return item; } - private bool _disposed; - private void CheckDisposed() - { - if (_disposed) - { - throw new ObjectDisposedException(GetType().Name + " has been disposed and cannot be accessed."); - } - } - - protected override void Dispose(bool dispose) - { - if (dispose) - { - _disposed = true; - } - base.Dispose(dispose); - } - protected override void CloseConnection() { if (_connection != null) diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index b17f10af3d..735748e08b 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -692,7 +692,7 @@ namespace MediaBrowser.Server.Startup.Common private async Task GetActivityLogRepository() { - var repo = new ActivityRepository(LogManager.GetLogger("ActivityRepository"), ServerConfigurationManager.ApplicationPaths); + var repo = new ActivityRepository(LogManager, ServerConfigurationManager.ApplicationPaths); await repo.Initialize().ConfigureAwait(false); From 13852b78310f7ed9013c59c7e6b529fbbd1938d9 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 10 Feb 2016 14:16:48 -0500 Subject: [PATCH 3/5] update translations --- MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index c68126a4e6..e6ac237637 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -2185,6 +2185,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest From 232d0eb14c10003a98b33c1d9c7a26c69f852d21 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 11 Feb 2016 00:37:07 -0500 Subject: [PATCH 4/5] make photos downloadable --- MediaBrowser.Controller/Entities/Photo.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MediaBrowser.Controller/Entities/Photo.cs b/MediaBrowser.Controller/Entities/Photo.cs index 308e61590c..aa9e44297b 100644 --- a/MediaBrowser.Controller/Entities/Photo.cs +++ b/MediaBrowser.Controller/Entities/Photo.cs @@ -53,6 +53,11 @@ namespace MediaBrowser.Controller.Entities } } + public override bool CanDownload() + { + return true; + } + public int? Width { get; set; } public int? Height { get; set; } public string CameraMake { get; set; } From 9e8d35dadc2859d39c3daab98458fd9d1be03865 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 11 Feb 2016 13:29:42 -0500 Subject: [PATCH 5/5] update recording sync fields --- MediaBrowser.Controller/Dto/IDtoService.cs | 7 ++++--- MediaBrowser.Controller/Library/ILibraryManager.cs | 1 - MediaBrowser.Providers/People/MovieDbPersonProvider.cs | 2 +- MediaBrowser.Server.Implementations/Dto/DtoService.cs | 8 ++++---- .../LiveTv/LiveTvManager.cs | 10 ++++++---- .../Sync/SyncManager.cs | 5 +++++ 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/MediaBrowser.Controller/Dto/IDtoService.cs b/MediaBrowser.Controller/Dto/IDtoService.cs index 77a81d0c88..5f0442f934 100644 --- a/MediaBrowser.Controller/Dto/IDtoService.cs +++ b/MediaBrowser.Controller/Dto/IDtoService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using System; +using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Querying; using System.Collections.Generic; @@ -44,10 +45,10 @@ namespace MediaBrowser.Controller.Dto /// /// Fills the synchronize information. /// - /// The dtos. + /// The tuples. /// The options. /// The user. - void FillSyncInfo(IEnumerable dtos, DtoOptions options, User user); + void FillSyncInfo(IEnumerable> tuples, DtoOptions options, User user); /// /// Gets the base item dto. diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 3b45d7764d..1c515edd58 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -329,7 +329,6 @@ namespace MediaBrowser.Controller.Library /// The parent identifier. /// Type of the view. /// Name of the sort. - /// The unique identifier. /// The cancellation token. /// Task<UserView>. Task GetNamedView(User user, diff --git a/MediaBrowser.Providers/People/MovieDbPersonProvider.cs b/MediaBrowser.Providers/People/MovieDbPersonProvider.cs index 14304c2eb5..5525b547fa 100644 --- a/MediaBrowser.Providers/People/MovieDbPersonProvider.cs +++ b/MediaBrowser.Providers/People/MovieDbPersonProvider.cs @@ -99,7 +99,7 @@ namespace MediaBrowser.Providers.People var requestCount = _requestCount; - if (requestCount >= 5) + if (requestCount >= 10) { //_logger.Debug("Throttling Tmdb people"); diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index ec54033df8..89f572a549 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -212,17 +212,17 @@ namespace MediaBrowser.Server.Implementations.Dto }).Items; } - public void FillSyncInfo(IEnumerable dtos, DtoOptions options, User user) + public void FillSyncInfo(IEnumerable> tuples, DtoOptions options, User user) { if (options.Fields.Contains(ItemFields.SyncInfo)) { var syncProgress = GetSyncedItemProgress(options); - foreach (var dto in dtos) + foreach (var tuple in tuples) { - var item = _libraryManager.GetItemById(dto.Id); + var item = tuple.Item1; - FillSyncInfo(dto, item, syncProgress, options, user); + FillSyncInfo(tuple.Item2, item, syncProgress, options, user); } } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 1e878f28c9..dcebc0c42e 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1592,18 +1592,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv var internalResult = await GetInternalRecordings(query, cancellationToken).ConfigureAwait(false); - var returnArray = internalResult.Items - .Select(i => _dtoService.GetBaseItemDto(i, options, user)) + var tuples = internalResult.Items + .Select(i => new Tuple(i, _dtoService.GetBaseItemDto(i, options, user))) .ToArray(); if (user != null) { - _dtoService.FillSyncInfo(returnArray, new DtoOptions(), user); + _dtoService.FillSyncInfo(tuples, new DtoOptions(), user); } return new QueryResult { - Items = returnArray, + Items = tuples.Select(i => i.Item2).ToArray(), TotalRecordCount = internalResult.TotalRecordCount }; } @@ -1684,6 +1684,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv } + _lastRecordingRefreshTime = DateTime.MinValue; + // This is the responsibility of the live tv service await _libraryManager.DeleteItem((BaseItem)recording, new DeleteOptions { diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index 21377da7ee..50a960956f 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -491,6 +491,11 @@ namespace MediaBrowser.Server.Implementations.Sync public bool SupportsSync(BaseItem item) { + if (item == null) + { + throw new ArgumentNullException("item"); + } + if (item is Playlist) { return true;