diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-02-10 13:13:24 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-02-10 13:13:24 -0500 |
| commit | 0216742945f2d2a2dda1b0da35d3c90a3bda06a2 (patch) | |
| tree | 50231de8c440cda5b8f1e7fe0b4d1f0ce113cdbf /MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs | |
| parent | 31a119fa424d23a557c5c4e1bfaae043ab8089ba (diff) | |
update db inheritance
Diffstat (limited to 'MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs | 60 |
1 files changed, 15 insertions, 45 deletions
diff --git a/MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs b/MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs index f491a5c44..3a89d6928 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; } - /// <summary> - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// </summary> - public void Dispose() + protected override void CloseConnection() { - Dispose(true); - GC.SuppressFinalize(this); - } - - private readonly object _disposeLock = new object(); - - /// <summary> - /// Releases unmanaged and - optionally - managed resources. - /// </summary> - /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> - 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.Dispose(); - _connection = null; - } - } - } - catch (Exception ex) - { - _logger.ErrorException("Error disposing database", ex); + _connection.Close(); } + + _connection.Dispose(); + _connection = null; } } } |
