Remove remnants of system events

This commit is contained in:
Bond_009 2019-01-25 22:41:43 +01:00
parent e0315b5695
commit fd7f420af2
14 changed files with 19 additions and 264 deletions

View File

@ -244,8 +244,6 @@ namespace Emby.Server.Implementations
/// </summary>
protected readonly SimpleInjector.Container Container = new SimpleInjector.Container();
protected ISystemEvents SystemEvents { get; set; }
/// <summary>
/// Gets the server configuration manager.
/// </summary>
@ -371,7 +369,6 @@ namespace Emby.Server.Implementations
IFileSystem fileSystem,
IEnvironmentInfo environmentInfo,
IImageEncoder imageEncoder,
ISystemEvents systemEvents,
INetworkManager networkManager)
{
@ -383,7 +380,6 @@ namespace Emby.Server.Implementations
NetworkManager = networkManager;
networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets;
EnvironmentInfo = environmentInfo;
SystemEvents = systemEvents;
ApplicationPaths = applicationPaths;
LoggerFactory = loggerFactory;
@ -762,7 +758,6 @@ namespace Emby.Server.Implementations
RegisterSingleInstance<IApplicationPaths>(ApplicationPaths);
RegisterSingleInstance(JsonSerializer);
RegisterSingleInstance(SystemEvents);
RegisterSingleInstance(LoggerFactory, false);
RegisterSingleInstance(Logger);
@ -779,7 +774,7 @@ namespace Emby.Server.Implementations
IsoManager = new IsoManager();
RegisterSingleInstance(IsoManager);
TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LoggerFactory, FileSystemManager, SystemEvents);
TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LoggerFactory, FileSystemManager);
RegisterSingleInstance(TaskManager);
RegisterSingleInstance(XmlSerializer);
@ -853,7 +848,7 @@ namespace Emby.Server.Implementations
var musicManager = new MusicManager(LibraryManager);
RegisterSingleInstance<IMusicManager>(new MusicManager(LibraryManager));
LibraryMonitor = new LibraryMonitor(LoggerFactory, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, TimerFactory, SystemEvents, EnvironmentInfo);
LibraryMonitor = new LibraryMonitor(LoggerFactory, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, TimerFactory, EnvironmentInfo);
RegisterSingleInstance(LibraryMonitor);
RegisterSingleInstance<ISearchEngine>(() => new SearchEngine(LoggerFactory, LibraryManager, UserManager));

View File

@ -1,34 +0,0 @@
using System;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.System;
namespace Emby.Server.Implementations.EntryPoints
{
public class SystemEvents : IServerEntryPoint
{
private readonly ISystemEvents _systemEvents;
private readonly IServerApplicationHost _appHost;
public SystemEvents(ISystemEvents systemEvents, IServerApplicationHost appHost)
{
_systemEvents = systemEvents;
_appHost = appHost;
}
public void Run()
{
_systemEvents.SystemShutdown += _systemEvents_SystemShutdown;
}
private void _systemEvents_SystemShutdown(object sender, EventArgs e)
{
_appHost.Shutdown();
}
public void Dispose()
{
_systemEvents.SystemShutdown -= _systemEvents_SystemShutdown;
}
}
}

View File

@ -140,7 +140,14 @@ namespace Emby.Server.Implementations.IO
/// <summary>
/// Initializes a new instance of the <see cref="LibraryMonitor" /> class.
/// </summary>
public LibraryMonitor(ILoggerFactory loggerFactory, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ITimerFactory timerFactory, ISystemEvents systemEvents, IEnvironmentInfo environmentInfo)
public LibraryMonitor(
ILoggerFactory loggerFactory,
ITaskManager taskManager,
ILibraryManager libraryManager,
IServerConfigurationManager configurationManager,
IFileSystem fileSystem,
ITimerFactory timerFactory,
IEnvironmentInfo environmentInfo)
{
if (taskManager == null)
{
@ -154,26 +161,9 @@ namespace Emby.Server.Implementations.IO
_fileSystem = fileSystem;
_timerFactory = timerFactory;
_environmentInfo = environmentInfo;
systemEvents.Resume += _systemEvents_Resume;
}
private void _systemEvents_Resume(object sender, EventArgs e)
{
Restart();
}
private void Restart()
{
Stop();
if (!_disposed)
{
Start();
}
}
private bool IsLibraryMonitorEnabaled(BaseItem item)
private bool IsLibraryMonitorEnabled(BaseItem item)
{
if (item is BasePluginFolder)
{
@ -200,7 +190,7 @@ namespace Emby.Server.Implementations.IO
var paths = LibraryManager
.RootFolder
.Children
.Where(IsLibraryMonitorEnabaled)
.Where(IsLibraryMonitorEnabled)
.OfType<Folder>()
.SelectMany(f => f.PhysicalLocations)
.Distinct(StringComparer.OrdinalIgnoreCase)
@ -223,7 +213,7 @@ namespace Emby.Server.Implementations.IO
private void StartWatching(BaseItem item)
{
if (IsLibraryMonitorEnabaled(item))
if (IsLibraryMonitorEnabled(item))
{
StartWatchingPath(item.Path);
}

View File

@ -60,7 +60,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
private readonly IProviderManager _providerManager;
private readonly IMediaEncoder _mediaEncoder;
private readonly IProcessFactory _processFactory;
private readonly ISystemEvents _systemEvents;
private readonly IAssemblyInfo _assemblyInfo;
private IMediaSourceManager _mediaSourceManager;
@ -90,8 +89,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
IProviderManager providerManager,
IMediaEncoder mediaEncoder,
ITimerFactory timerFactory,
IProcessFactory processFactory,
ISystemEvents systemEvents)
IProcessFactory processFactory)
{
Current = this;
@ -105,7 +103,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
_providerManager = providerManager;
_mediaEncoder = mediaEncoder;
_processFactory = processFactory;
_systemEvents = systemEvents;
_liveTvManager = (LiveTvManager)liveTvManager;
_jsonSerializer = jsonSerializer;
_assemblyInfo = assemblyInfo;
@ -131,15 +128,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
_timerProvider.RestartTimers();
_systemEvents.Resume += _systemEvents_Resume;
await CreateRecordingFolders().ConfigureAwait(false);
}
private void _systemEvents_Resume(object sender, EventArgs e)
{
_timerProvider.RestartTimers();
}
private async void OnRecordingFoldersChanged()
{
await CreateRecordingFolders().ConfigureAwait(false);

View File

@ -53,7 +53,6 @@ namespace Emby.Server.Implementations.ScheduledTasks
/// <value>The task manager.</value>
private ITaskManager TaskManager { get; set; }
private readonly IFileSystem _fileSystem;
private readonly ISystemEvents _systemEvents;
/// <summary>
/// Initializes a new instance of the <see cref="ScheduledTaskWorker" /> class.
@ -74,7 +73,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
/// or
/// logger
/// </exception>
public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem, ISystemEvents systemEvents)
public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem)
{
if (scheduledTask == null)
{
@ -103,7 +102,6 @@ namespace Emby.Server.Implementations.ScheduledTasks
JsonSerializer = jsonSerializer;
Logger = logger;
_fileSystem = fileSystem;
_systemEvents = systemEvents;
InitTriggerEvents();
}
@ -762,20 +760,6 @@ namespace Emby.Server.Implementations.ScheduledTasks
};
}
if (info.Type.Equals(typeof(SystemEventTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
if (!info.SystemEvent.HasValue)
{
throw new ArgumentException("Info did not contain a SystemEvent.", nameof(info));
}
return new SystemEventTrigger(_systemEvents)
{
SystemEvent = info.SystemEvent.Value,
TaskOptions = options
};
}
if (info.Type.Equals(typeof(StartupTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
return new StartupTrigger();

View File

@ -1,82 +0,0 @@
using System;
using System.Threading.Tasks;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.ScheduledTasks
{
/// <summary>
/// Class SystemEventTrigger
/// </summary>
public class SystemEventTrigger : ITaskTrigger
{
/// <summary>
/// Gets or sets the system event.
/// </summary>
/// <value>The system event.</value>
public SystemEvent SystemEvent { get; set; }
/// <summary>
/// Gets or sets the options of this task.
/// </summary>
public TaskOptions TaskOptions { get; set; }
private readonly ISystemEvents _systemEvents;
public SystemEventTrigger(ISystemEvents systemEvents)
{
_systemEvents = systemEvents;
}
/// <summary>
/// Stars waiting for the trigger action
/// </summary>
/// <param name="lastResult">The last result.</param>
/// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
public void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup)
{
switch (SystemEvent)
{
case SystemEvent.WakeFromSleep:
_systemEvents.Resume += _systemEvents_Resume;
break;
}
}
private async void _systemEvents_Resume(object sender, EventArgs e)
{
if (SystemEvent == SystemEvent.WakeFromSleep)
{
// This value is a bit arbitrary, but add a delay to help ensure network connections have been restored before running the task
await Task.Delay(10000).ConfigureAwait(false);
OnTriggered();
}
}
/// <summary>
/// Stops waiting for the trigger action
/// </summary>
public void Stop()
{
_systemEvents.Resume -= _systemEvents_Resume;
}
/// <summary>
/// Occurs when [triggered].
/// </summary>
public event EventHandler<EventArgs> Triggered;
/// <summary>
/// Called when [triggered].
/// </summary>
private void OnTriggered()
{
if (Triggered != null)
{
Triggered(this, EventArgs.Empty);
}
}
}
}

View File

@ -46,8 +46,6 @@ namespace Emby.Server.Implementations.ScheduledTasks
/// <value>The application paths.</value>
private IApplicationPaths ApplicationPaths { get; set; }
private readonly ISystemEvents _systemEvents;
/// <summary>
/// Gets the logger.
/// </summary>
@ -66,54 +64,16 @@ namespace Emby.Server.Implementations.ScheduledTasks
IApplicationPaths applicationPaths,
IJsonSerializer jsonSerializer,
ILoggerFactory loggerFactory,
IFileSystem fileSystem,
ISystemEvents systemEvents)
IFileSystem fileSystem)
{
ApplicationPaths = applicationPaths;
JsonSerializer = jsonSerializer;
Logger = loggerFactory.CreateLogger(nameof(TaskManager));
_fileSystem = fileSystem;
_systemEvents = systemEvents;
ScheduledTasks = new IScheduledTaskWorker[] { };
}
private void BindToSystemEvent()
{
_systemEvents.Resume += _systemEvents_Resume;
}
private void _systemEvents_Resume(object sender, EventArgs e)
{
foreach (var task in ScheduledTasks)
{
task.ReloadTriggerEvents();
}
}
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");
@ -290,12 +250,10 @@ namespace Emby.Server.Implementations.ScheduledTasks
var myTasks = ScheduledTasks.ToList();
var list = tasks.ToList();
myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger, _fileSystem, _systemEvents)));
myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger, _fileSystem)));
ScheduledTasks = myTasks.ToArray();
BindToSystemEvent();
RunStartupTasks();
}

View File

@ -1,13 +0,0 @@
using System;
using MediaBrowser.Model.System;
namespace Emby.Server.Implementations
{
public class SystemEvents : ISystemEvents
{
public event EventHandler Resume;
public event EventHandler Suspend;
public event EventHandler SessionLogoff;
public event EventHandler SystemShutdown;
}
}

View File

@ -11,8 +11,8 @@ namespace Jellyfin.Server
{
public class CoreAppHost : ApplicationHost
{
public CoreAppHost(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory, StartupOptions options, IFileSystem fileSystem, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager)
: base(applicationPaths, loggerFactory, options, fileSystem, environmentInfo, imageEncoder, systemEvents, networkManager)
public CoreAppHost(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory, StartupOptions options, IFileSystem fileSystem, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, MediaBrowser.Common.Net.INetworkManager networkManager)
: base(applicationPaths, loggerFactory, options, fileSystem, environmentInfo, imageEncoder, networkManager)
{
}

View File

@ -96,7 +96,6 @@ namespace Jellyfin.Server
fileSystem,
environmentInfo,
new NullImageEncoder(),
new SystemEvents(),
new NetworkManager(_loggerFactory, environmentInfo)))
{
await appHost.InitAsync();

View File

@ -1,12 +0,0 @@
using System;
namespace MediaBrowser.Model.System
{
public interface ISystemEvents
{
event EventHandler Resume;
event EventHandler Suspend;
event EventHandler SessionLogoff;
event EventHandler SystemShutdown;
}
}

View File

@ -72,7 +72,5 @@ namespace MediaBrowser.Model.Tasks
event EventHandler<GenericEventArgs<IScheduledTaskWorker>> TaskExecuting;
event EventHandler<TaskCompletionEventArgs> TaskCompleted;
void RunTaskOnNextStartup(string key);
}
}

View File

@ -1,13 +0,0 @@
namespace MediaBrowser.Model.Tasks
{
/// <summary>
/// Enum SystemEvent
/// </summary>
public enum SystemEvent
{
/// <summary>
/// The wake from sleep
/// </summary>
WakeFromSleep = 0
}
}

View File

@ -25,12 +25,6 @@ namespace MediaBrowser.Model.Tasks
/// <value>The interval.</value>
public long? IntervalTicks { get; set; }
/// <summary>
/// Gets or sets the system event.
/// </summary>
/// <value>The system event.</value>
public SystemEvent? SystemEvent { get; set; }
/// <summary>
/// Gets or sets the day of week.
/// </summary>