support delete per library

This commit is contained in:
Luke Pulverenti
2017-10-16 02:10:55 -04:00
parent 6f15141d73
commit 4ef9f68837
13 changed files with 104 additions and 15 deletions

View File

@@ -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>