@ -25,9 +25,11 @@ namespace MediaBrowser.Server.Implementations.Sync
private readonly IServerApplicationPaths _appPaths ;
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 _updateJobCommand ;
private IDbCommand _deleteJobCommand ;
private IDbCommand _deleteJobCommand ;
private IDbCommand _deleteJobItemsCommand ;
private IDbCommand _deleteJobItemsCommand ;
private IDbCommand _saveJobCommand ;
private IDbCommand _saveJobItemCommand ;
private IDbCommand _saveJobItemCommand ;
private readonly IJsonSerializer _json ;
private readonly IJsonSerializer _json ;
@ -66,34 +68,59 @@ namespace MediaBrowser.Server.Implementations.Sync
private void PrepareStatements ( )
private void PrepareStatements ( )
{
{
// _deleteJobCommand
_deleteJobCommand = _connection . CreateCommand ( ) ;
_deleteJobCommand = _connection . CreateCommand ( ) ;
_deleteJobCommand . CommandText = "delete from SyncJobs where Id=@Id" ;
_deleteJobCommand . CommandText = "delete from SyncJobs where Id=@Id" ;
_deleteJobCommand . Parameters . Add ( _deleteJobCommand , "@Id" ) ;
_deleteJobCommand . Parameters . Add ( _deleteJobCommand , "@Id" ) ;
// _deleteJobItemsCommand
_deleteJobItemsCommand = _connection . CreateCommand ( ) ;
_deleteJobItemsCommand = _connection . CreateCommand ( ) ;
_deleteJobItemsCommand . CommandText = "delete from SyncJobItems where JobId=@JobId" ;
_deleteJobItemsCommand . CommandText = "delete from SyncJobItems where JobId=@JobId" ;
_deleteJobItemsCommand . Parameters . Add ( _deleteJobItemsCommand , "@JobId" ) ;
_deleteJobItemsCommand . Parameters . Add ( _deleteJobItemsCommand , "@JobId" ) ;
_saveJobCommand = _connection . CreateCommand ( ) ;
// _insertJobCommand
_saveJobCommand . CommandText = "replace into SyncJobs (Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Quality, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)" ;
_insertJobCommand = _connection . CreateCommand ( ) ;
_insertJobCommand . CommandText = "insert into SyncJobs (Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Quality, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)" ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@Id" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@TargetId" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@Id" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@Name" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@TargetId" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@Quality" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@Name" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@Status" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@Quality" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@Progress" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@Status" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@UserId" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@Progress" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@ItemIds" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@UserId" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@Category" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@ItemIds" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@ParentId" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@Category" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@UnwatchedOnly" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@ParentId" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@ItemLimit" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@UnwatchedOnly" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@SyncNewContent" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@ItemLimit" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@DateCreated" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@SyncNewContent" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@DateLastModified" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@DateCreated" ) ;
_saveJobCommand . Parameters . Add ( _saveJobCommand , "@ItemCount" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@DateLastModified" ) ;
_insertJobCommand . Parameters . Add ( _insertJobCommand , "@ItemCount" ) ;
// _updateJobCommand
_updateJobCommand = _connection . CreateCommand ( ) ;
_updateJobCommand . CommandText = "update SyncJobs set TargetId=@TargetId,Name=@Name,Quality=@Quality,Status=@Status,Progress=@Progress,UserId=@UserId,ItemIds=@ItemIds,Category=@Category,ParentId=@ParentId,UnwatchedOnly=@UnwatchedOnly,ItemLimit=@ItemLimit,SyncNewContent=@SyncNewContent,DateCreated=@DateCreated,DateLastModified=@DateLastModified,ItemCount=@ItemCount where Id=@ID" ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@Id" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@TargetId" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@Name" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@Quality" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@Status" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@Progress" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@UserId" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@ItemIds" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@Category" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@ParentId" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@UnwatchedOnly" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@ItemLimit" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@SyncNewContent" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@DateCreated" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@DateLastModified" ) ;
_updateJobCommand . Parameters . Add ( _updateJobCommand , "@ItemCount" ) ;
// _saveJobItemCommand
_saveJobItemCommand = _connection . CreateCommand ( ) ;
_saveJobItemCommand = _connection . CreateCommand ( ) ;
_saveJobItemCommand . CommandText = "replace into SyncJobItems (Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval, JobItemIndex) values (@Id, @ItemId, @ItemName, @MediaSourceId, @JobId, @TemporaryPath, @OutputPath, @Status, @TargetId, @DateCreated, @Progress, @AdditionalFiles, @MediaSource, @IsMarkedForRemoval, @JobItemIndex)" ;
_saveJobItemCommand . CommandText = "replace into SyncJobItems (Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval, JobItemIndex) values (@Id, @ItemId, @ItemName, @MediaSourceId, @JobId, @TemporaryPath, @OutputPath, @Status, @TargetId, @DateCreated, @Progress, @AdditionalFiles, @MediaSource, @IsMarkedForRemoval, @JobItemIndex)" ;
@ -214,10 +241,15 @@ namespace MediaBrowser.Server.Implementations.Sync
public Task Create ( SyncJob job )
public Task Create ( SyncJob job )
{
{
return Update ( job ) ;
return InsertOrUpdate ( job , _insertJobCommand ) ;
}
public Task Update ( SyncJob job )
{
return InsertOrUpdate ( job , _updateJobCommand ) ;
}
}
public async Task Update ( SyncJob job )
p rivate async Task InsertOrUpdate ( SyncJob job , IDbCommand cmd )
{
{
if ( job = = null )
if ( job = = null )
{
{
@ -234,26 +266,26 @@ namespace MediaBrowser.Server.Implementations.Sync
var index = 0 ;
var index = 0 ;
_saveJobComman d. GetParameter ( index + + ) . Value = new Guid ( job . Id ) ;
cm d. GetParameter ( index + + ) . Value = new Guid ( job . Id ) ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . TargetId ;
cm d. GetParameter ( index + + ) . Value = job . TargetId ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . Name ;
cm d. GetParameter ( index + + ) . Value = job . Name ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . Quality ;
cm d. GetParameter ( index + + ) . Value = job . Quality ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . Status . ToString ( ) ;
cm d. GetParameter ( index + + ) . Value = job . Status . ToString ( ) ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . Progress ;
cm d. GetParameter ( index + + ) . Value = job . Progress ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . UserId ;
cm d. GetParameter ( index + + ) . Value = job . UserId ;
_saveJobComman d. GetParameter ( index + + ) . Value = string . Join ( "," , job . RequestedItemIds . ToArray ( ) ) ;
cm d. GetParameter ( index + + ) . Value = string . Join ( "," , job . RequestedItemIds . ToArray ( ) ) ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . Category ;
cm d. GetParameter ( index + + ) . Value = job . Category ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . ParentId ;
cm d. GetParameter ( index + + ) . Value = job . ParentId ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . UnwatchedOnly ;
cm d. GetParameter ( index + + ) . Value = job . UnwatchedOnly ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . ItemLimit ;
cm d. GetParameter ( index + + ) . Value = job . ItemLimit ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . SyncNewContent ;
cm d. GetParameter ( index + + ) . Value = job . SyncNewContent ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . DateCreated ;
cm d. GetParameter ( index + + ) . Value = job . DateCreated ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . DateLastModified ;
cm d. GetParameter ( index + + ) . Value = job . DateLastModified ;
_saveJobComman d. GetParameter ( index + + ) . Value = job . ItemCount ;
cm d. GetParameter ( index + + ) . Value = job . ItemCount ;
_saveJobComman d. Transaction = transaction ;
cm d. Transaction = transaction ;
_saveJobComman d. ExecuteNonQuery ( ) ;
cm d. ExecuteNonQuery ( ) ;
transaction . Commit ( ) ;
transaction . Commit ( ) ;
}
}