diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-10-16 02:10:55 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-10-16 02:10:55 -0400 |
| commit | 4ef9f68837d0c2d2b371239d8568edb6473c6072 (patch) | |
| tree | 8932031cbdc4cf46a7ef6b03a013345fdf3aba21 /Emby.Server.Implementations/ScheduledTasks/TaskManager.cs | |
| parent | 6f15141d73aae2fa78511077580fdc2cd895694f (diff) | |
support delete per library
Diffstat (limited to 'Emby.Server.Implementations/ScheduledTasks/TaskManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/ScheduledTasks/TaskManager.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs b/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs index 5f9bf3731..c0fcb459d 100644 --- a/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs +++ b/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs @@ -11,6 +11,7 @@ using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.System; using MediaBrowser.Model.Tasks; +using System.IO; namespace Emby.Server.Implementations.ScheduledTasks { @@ -86,6 +87,57 @@ namespace Emby.Server.Implementations.ScheduledTasks } } + public void RunTaskOnNextStartup(string key) + { + var path = Path.Combine(ApplicationPaths.CachePath, "startuptasks.txt"); + + List<string> lines; + + try + { + lines = _fileSystem.ReadAllLines(path).ToList() ; + } + catch + { + lines = new List<string>(); + } + + if (!lines.Contains(key, StringComparer.OrdinalIgnoreCase)) + { + lines.Add(key); + _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path)); + _fileSystem.WriteAllLines(path, lines); + } + } + + private void RunStartupTasks() + { + var path = Path.Combine(ApplicationPaths.CachePath, "startuptasks.txt"); + + List<string> lines; + + try + { + lines = _fileSystem.ReadAllLines(path).Where(i => !string.IsNullOrWhiteSpace(i)).Distinct(StringComparer.OrdinalIgnoreCase).ToList(); + + foreach (var key in lines) + { + var task = ScheduledTasks.FirstOrDefault(i => string.Equals(i.ScheduledTask.Key, key, StringComparison.OrdinalIgnoreCase)); + + if (task != null) + { + QueueScheduledTask(task, new TaskExecutionOptions()); + } + } + + _fileSystem.DeleteFile(path); + } + catch + { + return; + } + } + /// <summary> /// Cancels if running and queue. /// </summary> @@ -235,6 +287,8 @@ namespace Emby.Server.Implementations.ScheduledTasks ScheduledTasks = myTasks.ToArray(); BindToSystemEvent(); + + RunStartupTasks(); } /// <summary> |
