aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MediaBrowser.Api/Library/LibraryStructureService.cs32
-rw-r--r--MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs2
-rw-r--r--MediaBrowser.Api/StartupWizardService.cs1
-rw-r--r--MediaBrowser.Api/Sync/SyncService.cs28
-rw-r--r--MediaBrowser.Controller/Channels/Channel.cs14
-rw-r--r--MediaBrowser.Controller/Entities/Folder.cs21
-rw-r--r--MediaBrowser.Controller/Library/ILibraryManager.cs9
-rw-r--r--MediaBrowser.Controller/Sync/ISyncManager.cs19
-rw-r--r--MediaBrowser.Model/Configuration/ServerConfiguration.cs1
-rw-r--r--MediaBrowser.Model/Sync/SyncJobItem.cs2
-rw-r--r--MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs12
-rw-r--r--MediaBrowser.Server.Implementations/Library/LibraryManager.cs12
-rw-r--r--MediaBrowser.Server.Implementations/Library/UserManager.cs88
-rw-r--r--MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json5
-rw-r--r--MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs20
-rw-r--r--MediaBrowser.Server.Implementations/Sync/SyncManager.cs83
-rw-r--r--MediaBrowser.Server.Implementations/Sync/SyncRepository.cs12
-rw-r--r--MediaBrowser.Server.Startup.Common/ApplicationHost.cs2
18 files changed, 206 insertions, 157 deletions
diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs
index 23f4e4e5c..27944a4ea 100644
--- a/MediaBrowser.Api/Library/LibraryStructureService.cs
+++ b/MediaBrowser.Api/Library/LibraryStructureService.cs
@@ -3,7 +3,6 @@ using MediaBrowser.Controller;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Logging;
using ServiceStack;
using System;
using System.Collections.Generic;
@@ -18,7 +17,6 @@ namespace MediaBrowser.Api.Library
/// Class GetDefaultVirtualFolders
/// </summary>
[Route("/Library/VirtualFolders", "GET")]
- [Route("/Users/{UserId}/VirtualFolders", "GET")]
public class GetVirtualFolders : IReturn<List<VirtualFolderInfo>>
{
/// <summary>
@@ -144,11 +142,6 @@ namespace MediaBrowser.Api.Library
private readonly IServerApplicationPaths _appPaths;
/// <summary>
- /// The _user manager
- /// </summary>
- private readonly IUserManager _userManager;
-
- /// <summary>
/// The _library manager
/// </summary>
private readonly ILibraryManager _libraryManager;
@@ -156,27 +149,21 @@ namespace MediaBrowser.Api.Library
private readonly ILibraryMonitor _libraryMonitor;
private readonly IFileSystem _fileSystem;
- private readonly ILogger _logger;
/// <summary>
- /// Initializes a new instance of the <see cref="LibraryStructureService"/> class.
+ /// Initializes a new instance of the <see cref="LibraryStructureService" /> class.
/// </summary>
- /// <param name="appPaths">The app paths.</param>
- /// <param name="userManager">The user manager.</param>
- /// <param name="libraryManager">The library manager.</param>
- public LibraryStructureService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, ILibraryMonitor libraryMonitor, IFileSystem fileSystem, ILogger logger)
+ public LibraryStructureService(IServerApplicationPaths appPaths, ILibraryManager libraryManager, ILibraryMonitor libraryMonitor, IFileSystem fileSystem)
{
if (appPaths == null)
{
throw new ArgumentNullException("appPaths");
}
- _userManager = userManager;
_appPaths = appPaths;
_libraryManager = libraryManager;
_libraryMonitor = libraryMonitor;
_fileSystem = fileSystem;
- _logger = logger;
}
/// <summary>
@@ -186,20 +173,9 @@ namespace MediaBrowser.Api.Library
/// <returns>System.Object.</returns>
public object Get(GetVirtualFolders request)
{
- if (string.IsNullOrEmpty(request.UserId))
- {
- var result = _libraryManager.GetDefaultVirtualFolders().OrderBy(i => i.Name).ToList();
+ var result = _libraryManager.GetVirtualFolders().OrderBy(i => i.Name).ToList();
- return ToOptimizedSerializedResultUsingCache(result);
- }
- else
- {
- var user = _userManager.GetUserById(request.UserId);
-
- var result = _libraryManager.GetVirtualFolders(user).OrderBy(i => i.Name).ToList();
-
- return ToOptimizedSerializedResultUsingCache(result);
- }
+ return ToOptimizedSerializedResultUsingCache(result);
}
/// <summary>
diff --git a/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs b/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs
index f5b3d173b..947b99d35 100644
--- a/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs
+++ b/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs
@@ -141,7 +141,7 @@ namespace MediaBrowser.Api.ScheduledTasks
result = result.Where(i =>
{
- var isEnabled = false;
+ var isEnabled = true;
var configurableTask = i.ScheduledTask as IConfigurableScheduledTask;
diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs
index 97401bbf8..cb0c54674 100644
--- a/MediaBrowser.Api/StartupWizardService.cs
+++ b/MediaBrowser.Api/StartupWizardService.cs
@@ -63,6 +63,7 @@ namespace MediaBrowser.Api
_config.Configuration.IsStartupWizardCompleted = true;
_config.Configuration.EnableLocalizedGuids = true;
_config.Configuration.StoreArtistsInMetadata = true;
+ _config.Configuration.EnableStandaloneMetadata = true;
_config.Configuration.EnableLibraryMetadataSubFolder = true;
_config.SaveConfiguration();
}
diff --git a/MediaBrowser.Api/Sync/SyncService.cs b/MediaBrowser.Api/Sync/SyncService.cs
index 8d5ec824f..c763aa8df 100644
--- a/MediaBrowser.Api/Sync/SyncService.cs
+++ b/MediaBrowser.Api/Sync/SyncService.cs
@@ -37,6 +37,20 @@ namespace MediaBrowser.Api.Sync
{
}
+ [Route("/Sync/JobItems/{Id}/Enable", "POST", Summary = "Enables a cancelled or queued sync job item")]
+ public class EnableSyncJobItem : IReturnVoid
+ {
+ [ApiMember(Name = "Id", Description = "Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
+ public string Id { get; set; }
+ }
+
+ [Route("/Sync/JobItems/{Id}", "DELETE", Summary = "Cancels a sync job item")]
+ public class CancelSyncJobItem : IReturnVoid
+ {
+ [ApiMember(Name = "Id", Description = "Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
+ public string Id { get; set; }
+ }
+
[Route("/Sync/Jobs", "GET", Summary = "Gets sync jobs.")]
public class GetSyncJobs : SyncJobQuery, IReturn<QueryResult<SyncJob>>
{
@@ -271,5 +285,19 @@ namespace MediaBrowser.Api.Sync
return ToStaticFileResult(file.Path);
}
+
+ public void Post(EnableSyncJobItem request)
+ {
+ var task = _syncManager.ReEnableJobItem(request.Id);
+
+ Task.WaitAll(task);
+ }
+
+ public void Delete(CancelSyncJobItem request)
+ {
+ var task = _syncManager.CancelJobItem(request.Id);
+
+ Task.WaitAll(task);
+ }
}
}
diff --git a/MediaBrowser.Controller/Channels/Channel.cs b/MediaBrowser.Controller/Channels/Channel.cs
index 6ee6fe006..32ad2ff12 100644
--- a/MediaBrowser.Controller/Channels/Channel.cs
+++ b/MediaBrowser.Controller/Channels/Channel.cs
@@ -14,9 +14,19 @@ namespace MediaBrowser.Controller.Channels
public override bool IsVisible(User user)
{
- if (!user.Policy.EnableAllChannels && !user.Policy.EnabledChannels.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
+ if (user.Policy.BlockedChannels != null)
{
- return false;
+ if (user.Policy.BlockedChannels.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ if (!user.Policy.EnableAllChannels && !user.Policy.EnabledChannels.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
+ {
+ return false;
+ }
}
return base.IsVisible(user);
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs
index 8faab4c36..005f263f7 100644
--- a/MediaBrowser.Controller/Entities/Folder.cs
+++ b/MediaBrowser.Controller/Entities/Folder.cs
@@ -303,9 +303,22 @@ namespace MediaBrowser.Controller.Entities
{
if (this is ICollectionFolder)
{
- if (!user.Policy.EnableAllFolders && !user.Policy.EnabledFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
+ if (user.Policy.BlockedMediaFolders != null)
{
- return false;
+ if (user.Policy.BlockedMediaFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase) ||
+
+ // Backwards compatibility
+ user.Policy.BlockedMediaFolders.Contains(Name, StringComparer.OrdinalIgnoreCase))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ if (!user.Policy.EnableAllFolders && !user.Policy.EnabledFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
+ {
+ return false;
+ }
}
}
@@ -675,12 +688,12 @@ namespace MediaBrowser.Controller.Entities
path = System.IO.Path.GetDirectoryName(path);
}
- if (ContainsPath(LibraryManager.GetDefaultVirtualFolders(), originalPath))
+ if (ContainsPath(LibraryManager.GetVirtualFolders(), originalPath))
{
return true;
}
- return UserManager.Users.Any(user => ContainsPath(LibraryManager.GetVirtualFolders(user), originalPath));
+ return ContainsPath(LibraryManager.GetVirtualFolders(), originalPath);
}
/// <summary>
diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs
index 2ebd1cab9..9871ef3c5 100644
--- a/MediaBrowser.Controller/Library/ILibraryManager.cs
+++ b/MediaBrowser.Controller/Library/ILibraryManager.cs
@@ -123,14 +123,7 @@ namespace MediaBrowser.Controller.Library
/// Gets the default view.
/// </summary>
/// <returns>IEnumerable{VirtualFolderInfo}.</returns>
- IEnumerable<VirtualFolderInfo> GetDefaultVirtualFolders();
-
- /// <summary>
- /// Gets the view.
- /// </summary>
- /// <param name="user">The user.</param>
- /// <returns>IEnumerable{VirtualFolderInfo}.</returns>
- IEnumerable<VirtualFolderInfo> GetVirtualFolders(User user);
+ IEnumerable<VirtualFolderInfo> GetVirtualFolders();
/// <summary>
/// Gets the item by id.
diff --git a/MediaBrowser.Controller/Sync/ISyncManager.cs b/MediaBrowser.Controller/Sync/ISyncManager.cs
index 59136c0e6..8e4b6a44a 100644
--- a/MediaBrowser.Controller/Sync/ISyncManager.cs
+++ b/MediaBrowser.Controller/Sync/ISyncManager.cs
@@ -1,8 +1,10 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Dlna;
+using MediaBrowser.Model.Events;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Sync;
using MediaBrowser.Model.Users;
+using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -10,6 +12,9 @@ namespace MediaBrowser.Controller.Sync
{
public interface ISyncManager
{
+ event EventHandler<GenericEventArgs<SyncJob>> SyncJobCreated;
+ event EventHandler<GenericEventArgs<SyncJob>> SyncJobCancelled;
+
/// <summary>
/// Creates the job.
/// </summary>
@@ -45,6 +50,20 @@ namespace MediaBrowser.Controller.Sync
Task UpdateJob(SyncJob job);
/// <summary>
+ /// Res the enable job item.
+ /// </summary>
+ /// <param name="id">The identifier.</param>
+ /// <returns>Task.</returns>
+ Task ReEnableJobItem(string id);
+
+ /// <summary>
+ /// Cnacels the job item.
+ /// </summary>
+ /// <param name="id">The identifier.</param>
+ /// <returns>Task.</returns>
+ Task CancelJobItem(string id);
+
+ /// <summary>
/// Cancels the job.
/// </summary>
/// <param name="id">The identifier.</param>
diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
index 71580f353..c641edff7 100644
--- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs
+++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
@@ -169,6 +169,7 @@ namespace MediaBrowser.Model.Configuration
public string DashboardSourcePath { get; set; }
public bool StoreArtistsInMetadata { get; set; }
+ public bool EnableStandaloneMetadata { get; set; }
/// <summary>
/// Gets or sets the image saving convention.
diff --git a/MediaBrowser.Model/Sync/SyncJobItem.cs b/MediaBrowser.Model/Sync/SyncJobItem.cs
index 943014c0d..133065bf9 100644
--- a/MediaBrowser.Model/Sync/SyncJobItem.cs
+++ b/MediaBrowser.Model/Sync/SyncJobItem.cs
@@ -88,6 +88,8 @@ namespace MediaBrowser.Model.Sync
public string TemporaryPath { get; set; }
public List<ItemFileInfo> AdditionalFiles { get; set; }
+ public bool IsMarkedForRemoval { get; set; }
+
public SyncJobItem()
{
AdditionalFiles = new List<ItemFileInfo>();
diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
index b3b8ccbd8..5f7ccec4b 100644
--- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
+++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
@@ -99,10 +99,20 @@ namespace MediaBrowser.Server.Implementations.Configuration
private void UpdateMetadataPath()
{
((ServerApplicationPaths)ApplicationPaths).InternalMetadataPath = string.IsNullOrEmpty(Configuration.MetadataPath) ?
- null :
+ GetInternalMetadataPath() :
Configuration.MetadataPath;
}
+ private string GetInternalMetadataPath()
+ {
+ if (Configuration.EnableStandaloneMetadata)
+ {
+ return Path.Combine(ApplicationPaths.ProgramDataPath, "metadata");
+ }
+
+ return null;
+ }
+
/// <summary>
/// Updates the transcoding temporary path.
/// </summary>
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
index eaab469f5..b28c98728 100644
--- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
@@ -1124,7 +1124,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// Gets the default view.
/// </summary>
/// <returns>IEnumerable{VirtualFolderInfo}.</returns>
- public IEnumerable<VirtualFolderInfo> GetDefaultVirtualFolders()
+ public IEnumerable<VirtualFolderInfo> GetVirtualFolders()
{
return GetView(ConfigurationManager.ApplicationPaths.DefaultUserViewsPath);
}
@@ -1132,16 +1132,6 @@ namespace MediaBrowser.Server.Implementations.Library
/// <summary>
/// Gets the view.
/// </summary>
- /// <param name="user">The user.</param>
- /// <returns>IEnumerable{VirtualFolderInfo}.</returns>
- public IEnumerable<VirtualFolderInfo> GetVirtualFolders(User user)
- {
- return GetDefaultVirtualFolders();
- }
-
- /// <summary>
- /// Gets the view.
- /// </summary>
/// <param name="path">The path.</param>
/// <returns>IEnumerable{VirtualFolderInfo}.</returns>
private IEnumerable<VirtualFolderInfo> GetView(string path)
diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs
index 3020a224d..c4c0e5395 100644
--- a/MediaBrowser.Server.Implementations/Library/UserManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs
@@ -3,7 +3,6 @@ using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
-using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Connect;
using MediaBrowser.Controller.Drawing;
@@ -13,7 +12,6 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
-using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Connect;
using MediaBrowser.Model.Dto;
@@ -72,12 +70,10 @@ namespace MediaBrowser.Server.Implementations.Library
private readonly Func<IImageProcessor> _imageProcessorFactory;
private readonly Func<IDtoService> _dtoServiceFactory;
private readonly Func<IConnectManager> _connectFactory;
- private readonly Func<IChannelManager> _channelManager;
- private readonly Func<ILibraryManager> _libraryManager;
private readonly IServerApplicationHost _appHost;
private readonly IFileSystem _fileSystem;
- public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository, IXmlSerializer xmlSerializer, INetworkManager networkManager, Func<IImageProcessor> imageProcessorFactory, Func<IDtoService> dtoServiceFactory, Func<IConnectManager> connectFactory, IServerApplicationHost appHost, IJsonSerializer jsonSerializer, IFileSystem fileSystem, Func<IChannelManager> channelManager, Func<ILibraryManager> libraryManager)
+ public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository, IXmlSerializer xmlSerializer, INetworkManager networkManager, Func<IImageProcessor> imageProcessorFactory, Func<IDtoService> dtoServiceFactory, Func<IConnectManager> connectFactory, IServerApplicationHost appHost, IJsonSerializer jsonSerializer, IFileSystem fileSystem)
{
_logger = logger;
UserRepository = userRepository;
@@ -89,8 +85,6 @@ namespace MediaBrowser.Server.Implementations.Library
_appHost = appHost;
_jsonSerializer = jsonSerializer;
_fileSystem = fileSystem;
- _channelManager = channelManager;
- _libraryManager = libraryManager;
ConfigurationManager = configurationManager;
Users = new List<User>();
@@ -174,8 +168,6 @@ namespace MediaBrowser.Server.Implementations.Library
foreach (var user in users)
{
await DoPolicyMigration(user).ConfigureAwait(false);
- await DoChannelMigration(user).ConfigureAwait(false);
- await DoLibraryMigration(user).ConfigureAwait(false);
}
// If there are no local users with admin rights, make them all admins
@@ -354,84 +346,6 @@ namespace MediaBrowser.Server.Implementations.Library
}
}
- private async Task DoChannelMigration(User user)
- {
- if (user.Policy.BlockedChannels != null)
- {
- if (user.Policy.BlockedChannels.Length > 0)
- {
- user.Policy.EnableAllChannels = false;
-
- try
- {
- var channelResult = await _channelManager().GetChannelsInternal(new ChannelQuery
- {
- UserId = user.Id.ToString("N")
-
- }, CancellationToken.None).ConfigureAwait(false);
-
- user.Policy.EnabledChannels = channelResult.Items
- .Select(i => i.Id.ToString("N"))
- .Except(user.Policy.BlockedChannels)
- .ToArray();
- }
- catch
- {
- user.Policy.EnabledChannels = new string[] { };
- }
- }
- else
- {
- user.Policy.EnableAllChannels = true;
- user.Policy.EnabledChannels = new string[] { };
- }
-
- user.Policy.BlockedChannels = null;
-
- await UpdateUserPolicy(user, user.Policy, false);
- }
- }
-
- private async Task DoLibraryMigration(User user)
- {
- if (user.Policy.BlockedMediaFolders != null)
- {
- if (user.Policy.BlockedMediaFolders.Length > 0)
- {
- user.Policy.EnableAllFolders = false;
-
- try
- {
- user.Policy.EnabledFolders = _libraryManager().RootFolder
- .Children
- .Where(i => !user.Policy.BlockedMediaFolders.Contains(i.Name, StringComparer.OrdinalIgnoreCase) && !user.Policy.BlockedMediaFolders.Contains(i.Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
- .Select(i => i.Id.ToString("N"))
- .ToArray();
- }
- catch
- {
- user.Policy.EnabledFolders = new string[] { };
- user.Policy.EnableAllFolders = true;
- }
- }
- else
- {
- user.Policy.EnableAllFolders = true;
- user.Policy.EnabledFolders = new string[] { };
- }
-
- // Just to be safe
- if (user.Policy.EnabledFolders.Length == 0)
- {
- user.Policy.EnableAllFolders = true;
- }
-
- user.Policy.BlockedMediaFolders = null;
-
- await UpdateUserPolicy(user, user.Policy, false);
- }
- }
-
public UserDto GetUserDto(User user, string remoteEndPoint = null)
{
if (user == null)
diff --git a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json
index afc9bff62..e4d20d3a1 100644
--- a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json
+++ b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json
@@ -56,6 +56,9 @@
"HeaderChannelAccess": "Channel Access",
"HeaderDeviceAccess": "Device Access",
"HeaderSelectDevices": "Select Devices",
+ "ButtonCancelItem": "Cancel item",
+ "ButtonQueueForRetry": "Queue for retry",
+ "ButtonReenable": "Re-enable",
"LabelAbortedByServerShutdown": "(Aborted by server shutdown)",
"LabelScheduledTaskLastRan": "Last ran {0}, taking {1}.",
"HeaderDeleteTaskTrigger": "Delete Task Trigger",
@@ -71,6 +74,8 @@
"LabelForcedStream": "(Forced)",
"LabelDefaultForcedStream": "(Default/Forced)",
"LabelUnknownLanguage": "Unknown language",
+ "HeaderConfirmation": "Confirmation",
+ "MessageConfirmSyncJobItemCancellation": "Are you sure you wish to cancel this item?",
"ButtonMute": "Mute",
"ButtonUnmute": "Unmute",
"ButtonStop": "Stop",
diff --git a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs
index cf0138a29..67f9d363e 100644
--- a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs
+++ b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs
@@ -1,5 +1,4 @@
-using System.Globalization;
-using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Progress;
using MediaBrowser.Controller.Entities;
@@ -361,11 +360,20 @@ namespace MediaBrowser.Server.Implementations.Sync
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(startingPercent + (percentPerItem * p)));
- var job = _syncRepo.GetJob(item.JobId);
- await ProcessJobItem(job, item, enableConversion, innerProgress, cancellationToken).ConfigureAwait(false);
+ // Pull it fresh from the db just to make sure it wasn't deleted or cancelled while another item was converting
+ var jobItem = enableConversion ? _syncRepo.GetJobItem(item.Id) : item;
- job = _syncRepo.GetJob(item.JobId);
- await UpdateJobStatus(job).ConfigureAwait(false);
+ if (jobItem != null)
+ {
+ var job = _syncRepo.GetJob(jobItem.JobId);
+ if (jobItem.Status != SyncJobItemStatus.Cancelled)
+ {
+ await ProcessJobItem(job, jobItem, enableConversion, innerProgress, cancellationToken).ConfigureAwait(false);
+ }
+
+ job = _syncRepo.GetJob(jobItem.JobId);
+ await UpdateJobStatus(job).ConfigureAwait(false);
+ }
numComplete++;
double percent = numComplete;
diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs
index b8d884cee..7e4455ab3 100644
--- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs
+++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs
@@ -1,5 +1,6 @@
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Events;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Channels;
@@ -16,6 +17,7 @@ using MediaBrowser.Controller.TV;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Events;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Sync;
@@ -47,6 +49,9 @@ namespace MediaBrowser.Server.Implementations.Sync
private ISyncProvider[] _providers = { };
+ public event EventHandler<GenericEventArgs<SyncJob>> SyncJobCreated;
+ public event EventHandler<GenericEventArgs<SyncJob>> SyncJobCancelled;
+
public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func<IDtoService> dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func<IMediaEncoder> mediaEncoder, IFileSystem fileSystem, Func<ISubtitleEncoder> subtitleEncoder, IConfigurationManager config)
{
_libraryManager = libraryManager;
@@ -144,6 +149,15 @@ namespace MediaBrowser.Server.Implementations.Sync
await processor.SyncJobItems(jobItemsResult.Items, false, new Progress<double>(), CancellationToken.None)
.ConfigureAwait(false);
+ if (SyncJobCreated != null)
+ {
+ EventHelper.FireEventIfNotNull(SyncJobCreated, this, new GenericEventArgs<SyncJob>
+ {
+ Argument = job
+
+ }, _logger);
+ }
+
return new SyncJobCreationResult
{
Job = GetJob(jobId)
@@ -275,9 +289,25 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
- public Task CancelJob(string id)
+ public async Task CancelJob(string id)
{
- return _repo.DeleteJob(id);
+ var job = GetJob(id);
+
+ if (job == null)
+ {
+ throw new ArgumentException("Job not found.");
+ }
+
+ await _repo.DeleteJob(id).ConfigureAwait(false);
+
+ if (SyncJobCancelled != null)
+ {
+ EventHelper.FireEventIfNotNull(SyncJobCancelled, this, new GenericEventArgs<SyncJob>
+ {
+ Argument = job
+
+ }, _logger);
+ }
}
public SyncJob GetJob(string id)
@@ -496,7 +526,7 @@ namespace MediaBrowser.Server.Implementations.Sync
.FirstOrDefault(i => string.Equals(i.Id, jobItem.MediaSourceId));
syncedItem.Item.MediaSources = new List<MediaSourceInfo>();
-
+
// This will be null for items that are not audio/video
if (mediaSource == null)
{
@@ -545,7 +575,12 @@ namespace MediaBrowser.Server.Implementations.Sync
var job = _repo.GetJob(jobItem.JobId);
var user = _userManager.GetUserById(job.UserId);
- if (user == null)
+ if (jobItem.IsMarkedForRemoval)
+ {
+ // Tell the device to remove it since it has been marked for removal
+ response.ItemIdsToRemove.Add(jobItem.ItemId);
+ }
+ else if (user == null)
{
// Tell the device to remove it since the user is gone now
response.ItemIdsToRemove.Add(jobItem.ItemId);
@@ -609,5 +644,45 @@ namespace MediaBrowser.Server.Implementations.Sync
return true;
}
+
+ public async Task ReEnableJobItem(string id)
+ {
+ var jobItem = _repo.GetJobItem(id);
+
+ if (jobItem.Status != SyncJobItemStatus.Failed && jobItem.Status != SyncJobItemStatus.Cancelled)
+ {
+ throw new ArgumentException("Operation is not valid for this job item");
+ }
+
+ jobItem.Status = SyncJobItemStatus.Queued;
+ jobItem.Progress = 0;
+ jobItem.IsMarkedForRemoval = false;
+
+ await _repo.Update(jobItem).ConfigureAwait(false);
+
+ var processor = GetSyncJobProcessor();
+
+ await processor.UpdateJobStatus(jobItem.JobId).ConfigureAwait(false);
+ }
+
+ public async Task CancelJobItem(string id)
+ {
+ var jobItem = _repo.GetJobItem(id);
+
+ if (jobItem.Status != SyncJobItemStatus.Queued && jobItem.Status != SyncJobItemStatus.Transferring && jobItem.Status != SyncJobItemStatus.Converting)
+ {
+ throw new ArgumentException("Operation is not valid for this job item");
+ }
+
+ jobItem.Status = SyncJobItemStatus.Cancelled;
+ jobItem.Progress = 0;
+ jobItem.IsMarkedForRemoval = true;
+
+ await _repo.Update(jobItem).ConfigureAwait(false);
+
+ var processor = GetSyncJobProcessor();
+
+ await processor.UpdateJobStatus(jobItem.JobId).ConfigureAwait(false);
+ }
}
}
diff --git a/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs b/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs
index ae9143710..1cd8e8a9d 100644
--- a/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs
+++ b/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs
@@ -41,7 +41,7 @@ namespace MediaBrowser.Server.Implementations.Sync
public async Task Initialize()
{
- var dbFile = Path.Combine(_appPaths.DataPath, "sync12.db");
+ var dbFile = Path.Combine(_appPaths.DataPath, "sync13.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
@@ -50,7 +50,7 @@ namespace MediaBrowser.Server.Implementations.Sync
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Quality TEXT NOT NULL, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
"create index if not exists idx_SyncJobs on SyncJobs(Id)",
- "create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT)",
+ "create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT)",
"create index if not exists idx_SyncJobItems on SyncJobs(Id)",
//pragmas
@@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Sync
_saveJobCommand.Parameters.Add(_saveJobCommand, "@ItemCount");
_saveJobItemCommand = _connection.CreateCommand();
- _saveJobItemCommand.CommandText = "replace into SyncJobItems (Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource) values (@Id, @ItemId, @ItemName, @MediaSourceId, @JobId, @TemporaryPath, @OutputPath, @Status, @TargetId, @DateCreated, @Progress, @AdditionalFiles, @MediaSource)";
+ _saveJobItemCommand.CommandText = "replace into SyncJobItems (Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval) values (@Id, @ItemId, @ItemName, @MediaSourceId, @JobId, @TemporaryPath, @OutputPath, @Status, @TargetId, @DateCreated, @Progress, @AdditionalFiles, @MediaSource, @IsMarkedForRemoval)";
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@Id");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@ItemId");
@@ -110,10 +110,11 @@ namespace MediaBrowser.Server.Implementations.Sync
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@Progress");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@AdditionalFiles");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@MediaSource");
+ _saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@IsMarkedForRemoval");
}
private const string BaseJobSelectText = "select Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
- private const string BaseJobItemSelectText = "select Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource from SyncJobItems";
+ private const string BaseJobItemSelectText = "select Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval from SyncJobItems";
public SyncJob GetJob(string id)
{
@@ -572,6 +573,7 @@ namespace MediaBrowser.Server.Implementations.Sync
_saveJobItemCommand.GetParameter(index++).Value = jobItem.Progress;
_saveJobItemCommand.GetParameter(index++).Value = _json.SerializeToString(jobItem.AdditionalFiles);
_saveJobItemCommand.GetParameter(index++).Value = jobItem.MediaSource == null ? null : _json.SerializeToString(jobItem.MediaSource);
+ _saveJobItemCommand.GetParameter(index++).Value = jobItem.IsMarkedForRemoval;
_saveJobItemCommand.Transaction = transaction;
@@ -673,6 +675,8 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
+ info.IsMarkedForRemoval = reader.GetBoolean(13);
+
return info;
}
diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
index f481a902d..7eb68187a 100644
--- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
+++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
@@ -407,7 +407,7 @@ namespace MediaBrowser.Server.Startup.Common
SyncRepository = await GetSyncRepository().ConfigureAwait(false);
RegisterSingleInstance(SyncRepository);
- UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, () => ConnectManager, this, JsonSerializer, FileSystemManager, () => ChannelManager, () => LibraryManager);
+ UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, () => ConnectManager, this, JsonSerializer, FileSystemManager);
RegisterSingleInstance(UserManager);
LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager);