commit
b673054c8d
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
namespace MediaBrowser.Model.Tasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum SystemEvent
|
||||
/// </summary>
|
||||
public enum SystemEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// The wake from sleep
|
||||
/// </summary>
|
||||
WakeFromSleep = 0
|
||||
}
|
||||
}
|
Loading…
Reference in new issue