#680 - episode organization

This commit is contained in:
Luke Pulverenti
2014-01-22 12:05:06 -05:00
parent cf1dac60f6
commit 9d40b684bf
21 changed files with 824 additions and 646 deletions

View File

@@ -27,6 +27,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _saveResultCommand;
private IDbCommand _deleteResultCommand;
private IDbCommand _deleteAllCommand;
public SqliteFileOrganizationRepository(ILogManager logManager, IServerApplicationPaths appPaths)
{
@@ -85,6 +86,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
_deleteResultCommand.CommandText = "delete from organizationresults where ResultId = @ResultId";
_deleteResultCommand.Parameters.Add(_saveResultCommand, "@ResultId");
_deleteAllCommand = _connection.CreateCommand();
_deleteAllCommand.CommandText = "delete from organizationresults";
}
public async Task SaveResult(FileOrganizationResult result, CancellationToken cancellationToken)
@@ -188,7 +192,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
catch (Exception e)
{
_logger.ErrorException("Failed to save FileOrganizationResult:", e);
_logger.ErrorException("Failed to delete FileOrganizationResult:", e);
if (transaction != null)
{
@@ -208,6 +212,53 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
}
public async Task DeleteAll()
{
await _writeLock.WaitAsync().ConfigureAwait(false);
IDbTransaction transaction = null;
try
{
transaction = _connection.BeginTransaction();
_deleteAllCommand.Transaction = transaction;
_deleteAllCommand.ExecuteNonQuery();
transaction.Commit();
}
catch (OperationCanceledException)
{
if (transaction != null)
{
transaction.Rollback();
}
throw;
}
catch (Exception e)
{
_logger.ErrorException("Failed to delete results", e);
if (transaction != null)
{
transaction.Rollback();
}
throw;
}
finally
{
if (transaction != null)
{
transaction.Dispose();
}
_writeLock.Release();
}
}
public QueryResult<FileOrganizationResult> GetResults(FileOrganizationResultQuery query)
{
if (query == null)