mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-12 18:50:23 +01:00
move classes
This commit is contained in:
@@ -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>();
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user