|
|
@ -17,12 +17,9 @@ using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class SyncRepository : ISyncRepository, IDisposable
|
|
|
|
public class SyncRepository : BaseSqliteRepository, ISyncRepository
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private IDbConnection _connection;
|
|
|
|
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 readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
|
|
|
|
|
|
|
|
|
|
private IDbCommand _insertJobCommand;
|
|
|
|
private IDbCommand _insertJobCommand;
|
|
|
@ -34,19 +31,20 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
private IDbCommand _updateJobItemCommand;
|
|
|
|
private IDbCommand _updateJobItemCommand;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IJsonSerializer _json;
|
|
|
|
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;
|
|
|
|
_json = json;
|
|
|
|
|
|
|
|
_appPaths = appPaths;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task Initialize()
|
|
|
|
public async Task Initialize()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var dbFile = Path.Combine(_appPaths.DataPath, "sync14.db");
|
|
|
|
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 = {
|
|
|
|
string[] queries = {
|
|
|
|
|
|
|
|
|
|
|
@ -62,10 +60,10 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
"pragma shrink_memory"
|
|
|
|
"pragma shrink_memory"
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_connection.RunQueries(queries, _logger);
|
|
|
|
_connection.RunQueries(queries, Logger);
|
|
|
|
|
|
|
|
|
|
|
|
_connection.AddColumn(_logger, "SyncJobs", "Profile", "TEXT");
|
|
|
|
_connection.AddColumn(Logger, "SyncJobs", "Profile", "TEXT");
|
|
|
|
_connection.AddColumn(_logger, "SyncJobs", "Bitrate", "INT");
|
|
|
|
_connection.AddColumn(Logger, "SyncJobs", "Bitrate", "INT");
|
|
|
|
|
|
|
|
|
|
|
|
PrepareStatements();
|
|
|
|
PrepareStatements();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -298,7 +296,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
|
|
|
|
|
|
|
|
CheckDisposed();
|
|
|
|
CheckDisposed();
|
|
|
|
|
|
|
|
|
|
|
|
await _writeLock.WaitAsync().ConfigureAwait(false);
|
|
|
|
await WriteLock.WaitAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
IDbTransaction transaction = null;
|
|
|
|
IDbTransaction transaction = null;
|
|
|
|
|
|
|
|
|
|
|
@ -344,7 +342,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.ErrorException("Failed to save record:", e);
|
|
|
|
Logger.ErrorException("Failed to save record:", e);
|
|
|
|
|
|
|
|
|
|
|
|
if (transaction != null)
|
|
|
|
if (transaction != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -360,7 +358,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
transaction.Dispose();
|
|
|
|
transaction.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_writeLock.Release();
|
|
|
|
WriteLock.Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -373,7 +371,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
|
|
|
|
|
|
|
|
CheckDisposed();
|
|
|
|
CheckDisposed();
|
|
|
|
|
|
|
|
|
|
|
|
await _writeLock.WaitAsync().ConfigureAwait(false);
|
|
|
|
await WriteLock.WaitAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
IDbTransaction transaction = null;
|
|
|
|
IDbTransaction transaction = null;
|
|
|
|
|
|
|
|
|
|
|
@ -405,7 +403,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.ErrorException("Failed to save record:", e);
|
|
|
|
Logger.ErrorException("Failed to save record:", e);
|
|
|
|
|
|
|
|
|
|
|
|
if (transaction != null)
|
|
|
|
if (transaction != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -421,7 +419,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
transaction.Dispose();
|
|
|
|
transaction.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_writeLock.Release();
|
|
|
|
WriteLock.Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -656,7 +654,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
|
|
|
|
|
|
|
|
CheckDisposed();
|
|
|
|
CheckDisposed();
|
|
|
|
|
|
|
|
|
|
|
|
await _writeLock.WaitAsync().ConfigureAwait(false);
|
|
|
|
await WriteLock.WaitAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
IDbTransaction transaction = null;
|
|
|
|
IDbTransaction transaction = null;
|
|
|
|
|
|
|
|
|
|
|
@ -699,7 +697,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.ErrorException("Failed to save record:", e);
|
|
|
|
Logger.ErrorException("Failed to save record:", e);
|
|
|
|
|
|
|
|
|
|
|
|
if (transaction != null)
|
|
|
|
if (transaction != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -715,7 +713,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
transaction.Dispose();
|
|
|
|
transaction.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_writeLock.Release();
|
|
|
|
WriteLock.Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -802,15 +800,6 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
return item;
|
|
|
|
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 bool _disposed;
|
|
|
|
private void CheckDisposed()
|
|
|
|
private void CheckDisposed()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -820,38 +809,26 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private readonly object _disposeLock = new object();
|
|
|
|
protected override void Dispose(bool dispose)
|
|
|
|
|
|
|
|
|
|
|
|
/// <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 (dispose)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_disposed = true;
|
|
|
|
_disposed = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
base.Dispose(dispose);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
protected override void CloseConnection()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock (_disposeLock)
|
|
|
|
if (_connection != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_connection != null)
|
|
|
|
if (_connection.IsOpen())
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_connection.IsOpen())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_connection.Close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_connection.Dispose();
|
|
|
|
|
|
|
|
_connection = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.ErrorException("Error disposing database", ex);
|
|
|
|
_connection.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_connection.Dispose();
|
|
|
|
|
|
|
|
_connection = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|