aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Startup.Common
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2016-11-08 23:58:58 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2016-11-08 23:58:58 -0500
commit24532f3e2d7de2542b664383c5e0bc0cce61d7fc (patch)
treebe7f3db9c582a7ce2810879ca8e1351cb4038bfb /MediaBrowser.Server.Startup.Common
parent15ebff2b3a738855d6c35fafc37d40a72293eef8 (diff)
update power management
Diffstat (limited to 'MediaBrowser.Server.Startup.Common')
-rw-r--r--MediaBrowser.Server.Startup.Common/ApplicationHost.cs28
-rw-r--r--MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs60
-rw-r--r--MediaBrowser.Server.Startup.Common/INativeApp.cs7
-rw-r--r--MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj2
-rw-r--r--MediaBrowser.Server.Startup.Common/Threading/PeriodicTimer.cs72
5 files changed, 18 insertions, 151 deletions
diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
index 1c811ed113..c09e028ea8 100644
--- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
+++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
@@ -119,6 +119,7 @@ using Emby.Server.Implementations.Sync;
using Emby.Server.Implementations.TV;
using Emby.Server.Implementations.Updates;
using MediaBrowser.Model.Activity;
+using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Net;
@@ -260,26 +261,24 @@ namespace MediaBrowser.Server.Startup.Common
internal INativeApp NativeApp { get; set; }
+ internal IPowerManagement PowerManagement { get; private set; }
+
/// <summary>
/// Initializes a new instance of the <see cref="ApplicationHost" /> class.
/// </summary>
- /// <param name="applicationPaths">The application paths.</param>
- /// <param name="logManager">The log manager.</param>
- /// <param name="options">The options.</param>
- /// <param name="fileSystem">The file system.</param>
- /// <param name="releaseAssetFilename">The release asset filename.</param>
- /// <param name="nativeApp">The native application.</param>
public ApplicationHost(ServerApplicationPaths applicationPaths,
ILogManager logManager,
StartupOptions options,
IFileSystem fileSystem,
- string releaseAssetFilename,
- INativeApp nativeApp)
+ INativeApp nativeApp,
+ IPowerManagement powerManagement,
+ string releaseAssetFilename)
: base(applicationPaths, logManager, fileSystem)
{
_startupOptions = options;
_releaseAssetFilename = releaseAssetFilename;
NativeApp = nativeApp;
+ PowerManagement = powerManagement;
SetBaseExceptionMessage();
}
@@ -485,6 +484,13 @@ namespace MediaBrowser.Server.Startup.Common
HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber;
HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber;
+ // Safeguard against invalid configuration
+ if (HttpPort == HttpsPort)
+ {
+ HttpPort = ServerConfiguration.DefaultHttpPort;
+ HttpsPort = ServerConfiguration.DefaultHttpsPort;
+ }
+
return base.Init(progress);
}
@@ -535,6 +541,8 @@ namespace MediaBrowser.Server.Startup.Common
{
await base.RegisterResources(progress).ConfigureAwait(false);
+ RegisterSingleInstance(PowerManagement);
+
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LogManager, FileSystemManager, CryptographyProvider);
RegisterSingleInstance(SecurityManager);
@@ -999,13 +1007,13 @@ namespace MediaBrowser.Server.Startup.Common
{
Logger.ErrorException("Error starting http server", ex);
- if (HttpPort == 8096)
+ if (HttpPort == ServerConfiguration.DefaultHttpPort)
{
throw;
}
}
- HttpPort = 8096;
+ HttpPort = ServerConfiguration.DefaultHttpPort;
try
{
diff --git a/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs b/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs
deleted file mode 100644
index 95b42afbf9..0000000000
--- a/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-using MediaBrowser.Controller;
-using MediaBrowser.Controller.Plugins;
-using MediaBrowser.Controller.Session;
-using MediaBrowser.Model.Logging;
-using System;
-using System.Linq;
-using MediaBrowser.Server.Startup.Common.Threading;
-
-namespace MediaBrowser.Server.Startup.Common.EntryPoints
-{
- public class KeepServerAwake : IServerEntryPoint
- {
- private readonly ISessionManager _sessionManager;
- private readonly ILogger _logger;
- private PeriodicTimer _timer;
- private readonly IServerApplicationHost _appHost;
-
- public KeepServerAwake(ISessionManager sessionManager, ILogger logger, IServerApplicationHost appHost)
- {
- _sessionManager = sessionManager;
- _logger = logger;
- _appHost = appHost;
- }
-
- public void Run()
- {
- _timer = new PeriodicTimer(obj =>
- {
- var now = DateTime.UtcNow;
- var nativeApp = ((ApplicationHost)_appHost).NativeApp;
-
- try
- {
- if (_sessionManager.Sessions.Any(i => (now - i.LastActivityDate).TotalMinutes < 15))
- {
- nativeApp.PreventSystemStandby();
- }
- else
- {
- nativeApp.AllowSystemStandby();
- }
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error resetting system standby timer", ex);
- }
-
- }, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
- }
-
- public void Dispose()
- {
- if (_timer != null)
- {
- _timer.Dispose();
- _timer = null;
- }
- }
- }
-}
diff --git a/MediaBrowser.Server.Startup.Common/INativeApp.cs b/MediaBrowser.Server.Startup.Common/INativeApp.cs
index c56bb9b4bc..df29dfde42 100644
--- a/MediaBrowser.Server.Startup.Common/INativeApp.cs
+++ b/MediaBrowser.Server.Startup.Common/INativeApp.cs
@@ -88,13 +88,6 @@ namespace MediaBrowser.Server.Startup.Common
/// <returns>INetworkManager.</returns>
INetworkManager CreateNetworkManager(ILogger logger);
- /// <summary>
- /// Prevents the system stand by.
- /// </summary>
- void PreventSystemStandby();
-
- void AllowSystemStandby();
-
FFMpegInstallInfo GetFfmpegInstallInfo();
void LaunchUrl(string url);
diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj
index aca30aa2c4..97cdddf26d 100644
--- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj
+++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj
@@ -75,7 +75,6 @@
<Compile Include="ApplicationHost.cs" />
<Compile Include="ApplicationPathHelper.cs" />
<Compile Include="Browser\BrowserLauncher.cs" />
- <Compile Include="EntryPoints\KeepServerAwake.cs" />
<Compile Include="EntryPoints\StartupWizard.cs" />
<Compile Include="FFMpeg\FFMpegLoader.cs" />
<Compile Include="FFMpeg\FFMpegInstallInfo.cs" />
@@ -90,7 +89,6 @@
<Compile Include="StartupOptions.cs" />
<Compile Include="SystemEvents.cs" />
<Compile Include="TextLocalizer.cs" />
- <Compile Include="Threading\PeriodicTimer.cs" />
<Compile Include="UnhandledExceptionWriter.cs" />
</ItemGroup>
<ItemGroup>
diff --git a/MediaBrowser.Server.Startup.Common/Threading/PeriodicTimer.cs b/MediaBrowser.Server.Startup.Common/Threading/PeriodicTimer.cs
deleted file mode 100644
index 3e898adfdf..0000000000
--- a/MediaBrowser.Server.Startup.Common/Threading/PeriodicTimer.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using System;
-using System.Threading;
-using Microsoft.Win32;
-
-namespace MediaBrowser.Server.Startup.Common.Threading
-{
- public class PeriodicTimer : IDisposable
- {
- public Action<object> Callback { get; set; }
- private Timer _timer;
- private readonly object _state;
- private readonly object _timerLock = new object();
- private readonly TimeSpan _period;
-
- public PeriodicTimer(Action<object> callback, object state, TimeSpan dueTime, TimeSpan period)
- {
- if (callback == null)
- {
- throw new ArgumentNullException("callback");
- }
-
- Callback = callback;
- _period = period;
- _state = state;
-
- StartTimer(dueTime);
- }
-
- void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
- {
- if (e.Mode == PowerModes.Resume)
- {
- DisposeTimer();
- StartTimer(Timeout.InfiniteTimeSpan);
- }
- }
-
- private void TimerCallback(object state)
- {
- Callback(state);
- }
-
- private void StartTimer(TimeSpan dueTime)
- {
- lock (_timerLock)
- {
- _timer = new Timer(TimerCallback, _state, dueTime, _period);
-
- Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
- }
- }
-
- private void DisposeTimer()
- {
- Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
-
- lock (_timerLock)
- {
- if (_timer != null)
- {
- _timer.Dispose();
- _timer = null;
- }
- }
- }
-
- public void Dispose()
- {
- DisposeTimer();
- }
- }
-}