aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Startup.Common
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2016-11-03 18:53:02 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2016-11-03 18:53:02 -0400
commit8ef442c2e8f39307f72bc98d6c79a9b5f09e6d72 (patch)
treee830632342c9b9c5da81f86e382d131c4cda50c5 /MediaBrowser.Server.Startup.Common
parentf52373609eac871c2883e1052020ff5327b19707 (diff)
move classes
Diffstat (limited to 'MediaBrowser.Server.Startup.Common')
-rw-r--r--MediaBrowser.Server.Startup.Common/ApplicationHost.cs4
-rw-r--r--MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs2
-rw-r--r--MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj1
-rw-r--r--MediaBrowser.Server.Startup.Common/Threading/PeriodicTimer.cs72
4 files changed, 76 insertions, 3 deletions
diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
index 11d401670f..19b8ad2f97 100644
--- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
+++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
@@ -62,7 +62,6 @@ using MediaBrowser.Server.Implementations.Localization;
using MediaBrowser.Server.Implementations.Notifications;
using MediaBrowser.Server.Implementations.Persistence;
using MediaBrowser.Server.Implementations.Security;
-using MediaBrowser.Server.Implementations.ServerManager;
using MediaBrowser.Server.Implementations.Session;
using MediaBrowser.Server.Implementations.Social;
using MediaBrowser.Server.Implementations.Sync;
@@ -113,6 +112,7 @@ using Emby.Server.Implementations.MediaEncoder;
using Emby.Server.Implementations.Notifications;
using Emby.Server.Implementations.Persistence;
using Emby.Server.Implementations.Playlists;
+using Emby.Server.Implementations.ServerManager;
using Emby.Server.Implementations.Sync;
using Emby.Server.Implementations.TV;
using Emby.Server.Implementations.Updates;
@@ -603,7 +603,7 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance(HttpServer, false);
progress.Report(10);
- ServerManager = new ServerManager(this, JsonSerializer, LogManager.GetLogger("ServerManager"), ServerConfigurationManager, MemoryStreamProvider);
+ ServerManager = new ServerManager(this, JsonSerializer, LogManager.GetLogger("ServerManager"), ServerConfigurationManager, MemoryStreamProvider, textEncoding);
RegisterSingleInstance(ServerManager);
var innerProgress = new ActionableProgress<double>();
diff --git a/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs b/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs
index 79debce8da..95b42afbf9 100644
--- a/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs
+++ b/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs
@@ -4,7 +4,7 @@ using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Logging;
using System;
using System.Linq;
-using MediaBrowser.Server.Implementations.Threading;
+using MediaBrowser.Server.Startup.Common.Threading;
namespace MediaBrowser.Server.Startup.Common.EntryPoints
{
diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj
index 6a84ee0c5a..4aecb11dc9 100644
--- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj
+++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj
@@ -95,6 +95,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StartupOptions.cs" />
<Compile Include="SystemEvents.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
new file mode 100644
index 0000000000..3e898adfdf
--- /dev/null
+++ b/MediaBrowser.Server.Startup.Common/Threading/PeriodicTimer.cs
@@ -0,0 +1,72 @@
+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();
+ }
+ }
+}