aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/IO/FileRefresher.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Server.Implementations/IO/FileRefresher.cs')
-rw-r--r--MediaBrowser.Server.Implementations/IO/FileRefresher.cs49
1 files changed, 45 insertions, 4 deletions
diff --git a/MediaBrowser.Server.Implementations/IO/FileRefresher.cs b/MediaBrowser.Server.Implementations/IO/FileRefresher.cs
index 74dfbc679..18c52ab29 100644
--- a/MediaBrowser.Server.Implementations/IO/FileRefresher.cs
+++ b/MediaBrowser.Server.Implementations/IO/FileRefresher.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
+using MediaBrowser.Common.Events;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
@@ -24,9 +25,14 @@ namespace MediaBrowser.Server.Implementations.IO
private readonly List<string> _affectedPaths = new List<string>();
private Timer _timer;
private readonly object _timerLock = new object();
+ public string Path { get; private set; }
+
+ public event EventHandler<EventArgs> Completed;
public FileRefresher(string path, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ITaskManager taskManager, ILogger logger)
{
+ logger.Debug("New file refresher created for {0}", path);
+ Path = path;
_affectedPaths.Add(path);
_fileSystem = fileSystem;
@@ -36,7 +42,24 @@ namespace MediaBrowser.Server.Implementations.IO
Logger = logger;
}
- private void RestartTimer()
+ private void AddAffectedPath(string path)
+ {
+ if (!_affectedPaths.Contains(path, StringComparer.Ordinal))
+ {
+ _affectedPaths.Add(path);
+ }
+ }
+
+ public void AddPath(string path)
+ {
+ lock (_timerLock)
+ {
+ AddAffectedPath(path);
+ }
+ RestartTimer();
+ }
+
+ public void RestartTimer()
{
lock (_timerLock)
{
@@ -51,6 +74,23 @@ namespace MediaBrowser.Server.Implementations.IO
}
}
+ public void ResetPath(string path, string affectedFile)
+ {
+ lock (_timerLock)
+ {
+ Logger.Debug("Resetting file refresher from {0} to {1}", Path, path);
+
+ Path = path;
+ AddAffectedPath(path);
+
+ if (!string.IsNullOrWhiteSpace(affectedFile))
+ {
+ AddAffectedPath(affectedFile);
+ }
+ }
+ RestartTimer();
+ }
+
private async void OnTimerCallback(object state)
{
// Extend the timer as long as any of the paths are still being written to.
@@ -64,10 +104,11 @@ namespace MediaBrowser.Server.Implementations.IO
Logger.Debug("Timer stopped.");
DisposeTimer();
+ EventHelper.FireEventIfNotNull(Completed, this, EventArgs.Empty, Logger);
try
{
- await ProcessPathChanges(_affectedPaths).ConfigureAwait(false);
+ await ProcessPathChanges(_affectedPaths.ToList()).ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -130,7 +171,7 @@ namespace MediaBrowser.Server.Implementations.IO
{
item = LibraryManager.FindByPath(path, null);
- path = Path.GetDirectoryName(path);
+ path = System.IO.Path.GetDirectoryName(path);
}
if (item != null)
@@ -222,7 +263,7 @@ namespace MediaBrowser.Server.Implementations.IO
}
}
- public void DisposeTimer()
+ private void DisposeTimer()
{
lock (_timerLock)
{