From 19f422fdd00bd97c316a3619b4a19500d3e68293 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 3 Feb 2015 01:57:45 -0500 Subject: [PATCH] fix web project --- .../Sync/SyncManager.cs | 7 ++ .../Sync/SyncRepository.cs | 118 +++++++++++------- .../MediaBrowser.WebDashboard.csproj | 33 ----- 3 files changed, 82 insertions(+), 76 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index bc9e5d968f..e468a5d73b 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -499,10 +499,17 @@ namespace MediaBrowser.Server.Implementations.Sync { var job = _repo.GetJob(jobItem.JobId); + if (job == null) + { + _logger.Error("GetJobItemInfo job id {0} no longer exists", jobItem.JobId); + return null; + } + var libraryItem = _libraryManager.GetItemById(jobItem.ItemId); if (libraryItem == null) { + _logger.Error("GetJobItemInfo library item with id {0} no longer exists", jobItem.ItemId); return null; } diff --git a/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs b/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs index 6d77749e03..a101f13eb3 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs @@ -25,9 +25,11 @@ namespace MediaBrowser.Server.Implementations.Sync private readonly IServerApplicationPaths _appPaths; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); + private IDbCommand _insertJobCommand; + private IDbCommand _updateJobCommand; private IDbCommand _deleteJobCommand; + private IDbCommand _deleteJobItemsCommand; - private IDbCommand _saveJobCommand; private IDbCommand _saveJobItemCommand; private readonly IJsonSerializer _json; @@ -66,34 +68,59 @@ namespace MediaBrowser.Server.Implementations.Sync private void PrepareStatements() { + // _deleteJobCommand _deleteJobCommand = _connection.CreateCommand(); _deleteJobCommand.CommandText = "delete from SyncJobs where Id=@Id"; _deleteJobCommand.Parameters.Add(_deleteJobCommand, "@Id"); + // _deleteJobItemsCommand _deleteJobItemsCommand = _connection.CreateCommand(); _deleteJobItemsCommand.CommandText = "delete from SyncJobItems where JobId=@JobId"; _deleteJobItemsCommand.Parameters.Add(_deleteJobItemsCommand, "@JobId"); - _saveJobCommand = _connection.CreateCommand(); - _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)"; - - _saveJobCommand.Parameters.Add(_saveJobCommand, "@Id"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@TargetId"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@Name"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@Quality"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@Status"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@Progress"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@UserId"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@ItemIds"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@Category"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@ParentId"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@UnwatchedOnly"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@ItemLimit"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@SyncNewContent"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@DateCreated"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@DateLastModified"); - _saveJobCommand.Parameters.Add(_saveJobCommand, "@ItemCount"); - + // _insertJobCommand + _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)"; + + _insertJobCommand.Parameters.Add(_insertJobCommand, "@Id"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@TargetId"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@Name"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@Quality"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@Status"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@Progress"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@UserId"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@ItemIds"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@Category"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@ParentId"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@UnwatchedOnly"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@ItemLimit"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@SyncNewContent"); + _insertJobCommand.Parameters.Add(_insertJobCommand, "@DateCreated"); + _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.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) { - return Update(job); + return InsertOrUpdate(job, _insertJobCommand); + } + + public Task Update(SyncJob job) + { + return InsertOrUpdate(job, _updateJobCommand); } - public async Task Update(SyncJob job) + private async Task InsertOrUpdate(SyncJob job, IDbCommand cmd) { if (job == null) { @@ -234,26 +266,26 @@ namespace MediaBrowser.Server.Implementations.Sync var index = 0; - _saveJobCommand.GetParameter(index++).Value = new Guid(job.Id); - _saveJobCommand.GetParameter(index++).Value = job.TargetId; - _saveJobCommand.GetParameter(index++).Value = job.Name; - _saveJobCommand.GetParameter(index++).Value = job.Quality; - _saveJobCommand.GetParameter(index++).Value = job.Status.ToString(); - _saveJobCommand.GetParameter(index++).Value = job.Progress; - _saveJobCommand.GetParameter(index++).Value = job.UserId; - _saveJobCommand.GetParameter(index++).Value = string.Join(",", job.RequestedItemIds.ToArray()); - _saveJobCommand.GetParameter(index++).Value = job.Category; - _saveJobCommand.GetParameter(index++).Value = job.ParentId; - _saveJobCommand.GetParameter(index++).Value = job.UnwatchedOnly; - _saveJobCommand.GetParameter(index++).Value = job.ItemLimit; - _saveJobCommand.GetParameter(index++).Value = job.SyncNewContent; - _saveJobCommand.GetParameter(index++).Value = job.DateCreated; - _saveJobCommand.GetParameter(index++).Value = job.DateLastModified; - _saveJobCommand.GetParameter(index++).Value = job.ItemCount; - - _saveJobCommand.Transaction = transaction; - - _saveJobCommand.ExecuteNonQuery(); + cmd.GetParameter(index++).Value = new Guid(job.Id); + cmd.GetParameter(index++).Value = job.TargetId; + cmd.GetParameter(index++).Value = job.Name; + cmd.GetParameter(index++).Value = job.Quality; + cmd.GetParameter(index++).Value = job.Status.ToString(); + cmd.GetParameter(index++).Value = job.Progress; + cmd.GetParameter(index++).Value = job.UserId; + cmd.GetParameter(index++).Value = string.Join(",", job.RequestedItemIds.ToArray()); + cmd.GetParameter(index++).Value = job.Category; + cmd.GetParameter(index++).Value = job.ParentId; + cmd.GetParameter(index++).Value = job.UnwatchedOnly; + cmd.GetParameter(index++).Value = job.ItemLimit; + cmd.GetParameter(index++).Value = job.SyncNewContent; + cmd.GetParameter(index++).Value = job.DateCreated; + cmd.GetParameter(index++).Value = job.DateLastModified; + cmd.GetParameter(index++).Value = job.ItemCount; + + cmd.Transaction = transaction; + + cmd.ExecuteNonQuery(); transaction.Commit(); } diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 2884a7cd05..34b0e9e88e 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -252,9 +252,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -300,36 +297,6 @@ PreserveNewest - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - PreserveNewest