show more music favorites

This commit is contained in:
Luke Pulverenti 2015-11-08 22:41:45 -05:00
parent 7760f022af
commit f9e9f5bef6

View File

@ -17,12 +17,9 @@ using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Sync
{
public class SyncRepository : ISyncRepository, IDisposable
public class SyncRepository : BaseSqliteRepository, ISyncRepository
{
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 _insertJobCommand;
@ -34,19 +31,20 @@ namespace MediaBrowser.Server.Implementations.Sync
private IDbCommand _updateJobItemCommand;
private readonly IJsonSerializer _json;
private readonly IServerApplicationPaths _appPaths;
public SyncRepository(ILogger logger, IServerApplicationPaths appPaths, IJsonSerializer json)
public SyncRepository(ILogManager logManager, IJsonSerializer json, IServerApplicationPaths appPaths)
: base(logManager)
{
_logger = logger;
_appPaths = appPaths;
_json = json;
_appPaths = appPaths;
}
public async Task Initialize()
{
var dbFile = Path.Combine(_appPaths.DataPath, "sync14.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false);
string[] queries = {
@ -62,10 +60,10 @@ namespace MediaBrowser.Server.Implementations.Sync
"pragma shrink_memory"
};
_connection.RunQueries(queries, _logger);
_connection.RunQueries(queries, Logger);
_connection.AddColumn(_logger, "SyncJobs", "Profile", "TEXT");
_connection.AddColumn(_logger, "SyncJobs", "Bitrate", "INT");
_connection.AddColumn(Logger, "SyncJobs", "Profile", "TEXT");
_connection.AddColumn(Logger, "SyncJobs", "Bitrate", "INT");
PrepareStatements();
}
@ -298,7 +296,7 @@ namespace MediaBrowser.Server.Implementations.Sync
CheckDisposed();
await _writeLock.WaitAsync().ConfigureAwait(false);
await WriteLock.WaitAsync().ConfigureAwait(false);
IDbTransaction transaction = null;
@ -344,7 +342,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
catch (Exception e)
{
_logger.ErrorException("Failed to save record:", e);
Logger.ErrorException("Failed to save record:", e);
if (transaction != null)
{
@ -360,7 +358,7 @@ namespace MediaBrowser.Server.Implementations.Sync
transaction.Dispose();
}
_writeLock.Release();
WriteLock.Release();
}
}
@ -373,7 +371,7 @@ namespace MediaBrowser.Server.Implementations.Sync
CheckDisposed();
await _writeLock.WaitAsync().ConfigureAwait(false);
await WriteLock.WaitAsync().ConfigureAwait(false);
IDbTransaction transaction = null;
@ -405,7 +403,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
catch (Exception e)
{
_logger.ErrorException("Failed to save record:", e);
Logger.ErrorException("Failed to save record:", e);
if (transaction != null)
{
@ -421,7 +419,7 @@ namespace MediaBrowser.Server.Implementations.Sync
transaction.Dispose();
}
_writeLock.Release();
WriteLock.Release();
}
}
@ -656,7 +654,7 @@ namespace MediaBrowser.Server.Implementations.Sync
CheckDisposed();
await _writeLock.WaitAsync().ConfigureAwait(false);
await WriteLock.WaitAsync().ConfigureAwait(false);
IDbTransaction transaction = null;
@ -699,7 +697,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
catch (Exception e)
{
_logger.ErrorException("Failed to save record:", e);
Logger.ErrorException("Failed to save record:", e);
if (transaction != null)
{
@ -715,7 +713,7 @@ namespace MediaBrowser.Server.Implementations.Sync
transaction.Dispose();
}
_writeLock.Release();
WriteLock.Release();
}
}
@ -802,15 +800,6 @@ namespace MediaBrowser.Server.Implementations.Sync
return item;
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private bool _disposed;
private void CheckDisposed()
{
@ -820,21 +809,16 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
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)
protected override void Dispose(bool dispose)
{
if (dispose)
{
_disposed = true;
}
base.Dispose(dispose);
}
try
{
lock (_disposeLock)
protected override void CloseConnection()
{
if (_connection != null)
{
@ -848,11 +832,4 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
}
catch (Exception ex)
{
_logger.ErrorException("Error disposing database", ex);
}
}
}
}
}