commit
d258ce107d
|
@ -767,8 +767,21 @@ namespace MediaBrowser.Api.Playback
|
|||
if (request.Width.HasValue || request.Height.HasValue || request.MaxHeight.HasValue || request.MaxWidth.HasValue)
|
||||
{
|
||||
outputSizeParam = GetOutputSizeParam(state, outputVideoCodec).TrimEnd('"');
|
||||
|
||||
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
outputSizeParam = "," + outputSizeParam.Substring(outputSizeParam.IndexOf("format", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
else
|
||||
{
|
||||
outputSizeParam = "," + outputSizeParam.Substring(outputSizeParam.IndexOf("scale", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
|
||||
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase) && outputSizeParam.Length == 0)
|
||||
{
|
||||
outputSizeParam = ",format=nv12|vaapi,hwupload";
|
||||
}
|
||||
|
||||
var videoSizeParam = string.Empty;
|
||||
|
||||
|
@ -1022,7 +1035,7 @@ namespace MediaBrowser.Api.Playback
|
|||
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
|
||||
if (GetVideoEncoder(state).IndexOf("vaapi", StringComparison.OrdinalIgnoreCase) != -1)
|
||||
{
|
||||
arg = "-hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device " + encodingOptions.VaapiDevice + " " + arg;
|
||||
arg = "-hwaccel vaapi -hwaccel_output_format yuv420p -vaapi_device " + encodingOptions.VaapiDevice + " " + arg;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -266,7 +266,6 @@
|
|||
<Compile Include="Playlists\IPlaylistManager.cs" />
|
||||
<Compile Include="Playlists\Playlist.cs" />
|
||||
<Compile Include="Plugins\ILocalizablePlugin.cs" />
|
||||
<Compile Include="Power\IPowerManagement.cs" />
|
||||
<Compile Include="Providers\AlbumInfo.cs" />
|
||||
<Compile Include="Providers\ArtistInfo.cs" />
|
||||
<Compile Include="Providers\BookInfo.cs" />
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace MediaBrowser.Controller.Power
|
||||
{
|
||||
public interface IPowerManagement
|
||||
{
|
||||
/// <summary>
|
||||
/// Schedules the wake.
|
||||
/// </summary>
|
||||
/// <param name="utcTime">The UTC time.</param>
|
||||
void ScheduleWake(DateTime utcTime);
|
||||
}
|
||||
}
|
|
@ -50,8 +50,6 @@ namespace MediaBrowser.Dlna.Ssdp
|
|||
// Connect our event handler so we process devices as they are found
|
||||
_DeviceLocator.DeviceAvailable += deviceLocator_DeviceAvailable;
|
||||
_DeviceLocator.DeviceUnavailable += _DeviceLocator_DeviceUnavailable;
|
||||
// Enable listening for notifications (optional)
|
||||
_DeviceLocator.StartListeningForNotifications();
|
||||
|
||||
// Perform a search so we don't have to wait for devices to broadcast notifications
|
||||
// again to get any results right away (notifications are broadcast periodically).
|
||||
|
@ -61,26 +59,26 @@ namespace MediaBrowser.Dlna.Ssdp
|
|||
private void StartAsyncSearch()
|
||||
{
|
||||
Task.Factory.StartNew(async (o) =>
|
||||
{
|
||||
while (!_tokenSource.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// Enable listening for notifications (optional)
|
||||
_DeviceLocator.StartListeningForNotifications();
|
||||
|
||||
await _DeviceLocator.SearchAsync().ConfigureAwait(false);
|
||||
|
||||
var delay = _config.GetDlnaConfiguration().ClientDiscoveryIntervalSeconds * 1000;
|
||||
|
||||
await Task.Delay(delay, _tokenSource.Token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error searching for devices", ex);
|
||||
}
|
||||
|
||||
var delay = _config.GetDlnaConfiguration().ClientDiscoveryIntervalSeconds * 1000;
|
||||
|
||||
await Task.Delay(delay, _tokenSource.Token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
}, CancellationToken.None, TaskCreationOptions.LongRunning);
|
||||
}
|
||||
|
||||
|
|
|
@ -487,7 +487,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
|||
var videoEncoder = EncodingJobFactory.GetVideoEncoder(MediaEncoder, state, encodingOptions);
|
||||
if (videoEncoder.IndexOf("vaapi", StringComparison.OrdinalIgnoreCase) != -1)
|
||||
{
|
||||
arg = "-hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device " + encodingOptions.VaapiDevice + " " + arg;
|
||||
arg = "-hwaccel vaapi -hwaccel_output_format yuv420p -vaapi_device " + encodingOptions.VaapiDevice + " " + arg;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -565,8 +565,21 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
|||
{
|
||||
outputSizeParam = await GetOutputSizeParam(state, outputVideoCodec).ConfigureAwait(false);
|
||||
outputSizeParam = outputSizeParam.TrimEnd('"');
|
||||
|
||||
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
outputSizeParam = "," + outputSizeParam.Substring(outputSizeParam.IndexOf("format", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
else
|
||||
{
|
||||
outputSizeParam = "," + outputSizeParam.Substring(outputSizeParam.IndexOf("scale", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
|
||||
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase) && outputSizeParam.Length == 0)
|
||||
{
|
||||
outputSizeParam = ",format=nv12|vaapi,hwupload";
|
||||
}
|
||||
|
||||
var videoSizeParam = string.Empty;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.30723.0
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Model", "MediaBrowser.Model\MediaBrowser.Model.csproj", "{7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B}"
|
||||
EndProject
|
||||
|
@ -35,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Server.Startup
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emby.Drawing", "Emby.Drawing\Emby.Drawing.csproj", "{08FFF49B-F175-4807-A2B5-73B0EBD9F716}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Nat", "Mono.Nat\Mono.Nat.csproj", "{D7453B88-2266-4805-B39B-2B5A2A33E1BA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -203,6 +205,18 @@ Global
|
|||
{08FFF49B-F175-4807-A2B5-73B0EBD9F716}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{08FFF49B-F175-4807-A2B5-73B0EBD9F716}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{08FFF49B-F175-4807-A2B5-73B0EBD9F716}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Release Mono|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Release Mono|Any CPU.Build.0 = Release|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Release Mono|x86.ActiveCfg = Release|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Release Mono|x86.Build.0 = Release|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{D7453B88-2266-4805-B39B-2B5A2A33E1BA}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -450,7 +450,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
|||
|
||||
if (!string.IsNullOrWhiteSpace(user.ConnectUserId))
|
||||
{
|
||||
await RemoveConnect(user, connectUser.Id).ConfigureAwait(false);
|
||||
await RemoveConnect(user, user.ConnectUserId).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var url = GetConnectUrl("ServerAuthorizations");
|
||||
|
|
|
@ -27,7 +27,6 @@ using System.Threading.Tasks;
|
|||
using CommonIO;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Power;
|
||||
using MediaBrowser.Model.Configuration;
|
||||
using Microsoft.Win32;
|
||||
|
||||
|
@ -61,7 +60,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
|||
private readonly ConcurrentDictionary<string, ActiveRecordingInfo> _activeRecordings =
|
||||
new ConcurrentDictionary<string, ActiveRecordingInfo>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public EmbyTV(IApplicationHost appHost, ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient, IServerConfigurationManager config, ILiveTvManager liveTvManager, IFileSystem fileSystem, ILibraryManager libraryManager, ILibraryMonitor libraryMonitor, IProviderManager providerManager, IFileOrganizationService organizationService, IMediaEncoder mediaEncoder, IPowerManagement powerManagement)
|
||||
public EmbyTV(IApplicationHost appHost, ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient, IServerConfigurationManager config, ILiveTvManager liveTvManager, IFileSystem fileSystem, ILibraryManager libraryManager, ILibraryMonitor libraryMonitor, IProviderManager providerManager, IFileOrganizationService organizationService, IMediaEncoder mediaEncoder)
|
||||
{
|
||||
Current = this;
|
||||
|
||||
|
@ -79,7 +78,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
|||
_jsonSerializer = jsonSerializer;
|
||||
|
||||
_seriesTimerProvider = new SeriesTimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "seriestimers"));
|
||||
_timerProvider = new TimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "timers"), powerManagement, _logger);
|
||||
_timerProvider = new TimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "timers"), _logger);
|
||||
_timerProvider.TimerFired += _timerProvider_TimerFired;
|
||||
|
||||
_config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated;
|
||||
|
|
|
@ -9,7 +9,6 @@ using System.Globalization;
|
|||
using System.Linq;
|
||||
using System.Threading;
|
||||
using CommonIO;
|
||||
using MediaBrowser.Controller.Power;
|
||||
using MediaBrowser.Model.LiveTv;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
||||
|
@ -17,15 +16,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
|||
public class TimerManager : ItemDataProvider<TimerInfo>
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, Timer> _timers = new ConcurrentDictionary<string, Timer>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly IPowerManagement _powerManagement;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public event EventHandler<GenericEventArgs<TimerInfo>> TimerFired;
|
||||
|
||||
public TimerManager(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath, IPowerManagement powerManagement, ILogger logger1)
|
||||
public TimerManager(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath, ILogger logger1)
|
||||
: base(fileSystem, jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_powerManagement = powerManagement;
|
||||
_logger = logger1;
|
||||
}
|
||||
|
||||
|
@ -64,7 +61,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
|||
{
|
||||
var timespan = RecordingHelper.GetStartTime(item) - DateTime.UtcNow;
|
||||
timer.Change(timespan, TimeSpan.Zero);
|
||||
ScheduleWake(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -101,7 +97,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
|||
|
||||
base.Add(item);
|
||||
AddTimer(item);
|
||||
ScheduleWake(item);
|
||||
}
|
||||
|
||||
private void AddTimer(TimerInfo item)
|
||||
|
@ -124,25 +119,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
|||
StartTimer(item, timerLength);
|
||||
}
|
||||
|
||||
private void ScheduleWake(TimerInfo info)
|
||||
{
|
||||
var startDate = RecordingHelper.GetStartTime(info).AddMinutes(-5);
|
||||
|
||||
try
|
||||
{
|
||||
_powerManagement.ScheduleWake(startDate);
|
||||
_logger.Info("Scheduled system wake timer at {0} (UTC)", startDate);
|
||||
}
|
||||
catch (NotImplementedException)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error scheduling wake timer", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartTimer(TimerInfo item, TimeSpan dueTime)
|
||||
{
|
||||
StopTimer(item);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
DE-0,1
|
||||
FSK-0,1
|
||||
DE-6,5
|
||||
FSK-6,5
|
||||
DE-12,7
|
||||
FSK-12,7
|
||||
DE-16,8
|
||||
FSK-16,8
|
||||
DE-18,9
|
||||
FSK-18,9
|
|
@ -8,7 +8,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using MediaBrowser.Controller.Power;
|
||||
using MediaBrowser.Model.System;
|
||||
using MediaBrowser.Server.Implementations.Persistence;
|
||||
using MediaBrowser.Server.Startup.Common.FFMpeg;
|
||||
|
@ -232,11 +231,6 @@ namespace MediaBrowser.Server.Mono.Native
|
|||
public string machine = string.Empty;
|
||||
}
|
||||
|
||||
public IPowerManagement GetPowerManagement()
|
||||
{
|
||||
return new NullPowerManagement();
|
||||
}
|
||||
|
||||
public FFMpegInstallInfo GetFfmpegInstallInfo()
|
||||
{
|
||||
return GetInfo(Environment);
|
||||
|
@ -289,12 +283,4 @@ namespace MediaBrowser.Server.Mono.Native
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class NullPowerManagement : IPowerManagement
|
||||
{
|
||||
public void ScheduleWake(DateTime utcTime)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -561,8 +561,6 @@ namespace MediaBrowser.Server.Startup.Common
|
|||
EncodingManager = new EncodingManager(FileSystemManager, Logger, MediaEncoder, ChapterManager, LibraryManager);
|
||||
RegisterSingleInstance(EncodingManager);
|
||||
|
||||
RegisterSingleInstance(NativeApp.GetPowerManagement());
|
||||
|
||||
var sharingRepo = new SharingRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector());
|
||||
await sharingRepo.Initialize().ConfigureAwait(false);
|
||||
RegisterSingleInstance<ISharingManager>(new SharingManager(sharingRepo, ServerConfigurationManager, LibraryManager, this));
|
||||
|
@ -1177,20 +1175,24 @@ namespace MediaBrowser.Server.Startup.Common
|
|||
|
||||
public async Task<List<IPAddress>> GetLocalIpAddresses()
|
||||
{
|
||||
var localAddresses = NetworkManager.GetLocalIpAddresses()
|
||||
.Where(IsIpAddressValid)
|
||||
.ToList();
|
||||
var addresses = NetworkManager.GetLocalIpAddresses().ToList();
|
||||
var list = new List<IPAddress>();
|
||||
|
||||
return localAddresses;
|
||||
foreach (var address in addresses)
|
||||
{
|
||||
var valid = await IsIpAddressValidAsync(address).ConfigureAwait(false);
|
||||
if (valid)
|
||||
{
|
||||
list.Add(address);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private readonly ConcurrentDictionary<string, bool> _validAddressResults = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
|
||||
private DateTime _lastAddressCacheClear;
|
||||
private bool IsIpAddressValid(IPAddress address)
|
||||
{
|
||||
return IsIpAddressValidInternal(address).Result;
|
||||
}
|
||||
private async Task<bool> IsIpAddressValidInternal(IPAddress address)
|
||||
private async Task<bool> IsIpAddressValidAsync(IPAddress address)
|
||||
{
|
||||
if (IPAddress.IsLoopback(address))
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
using MediaBrowser.Model.Logging;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using MediaBrowser.Controller.Power;
|
||||
using MediaBrowser.Server.Implementations.Persistence;
|
||||
using MediaBrowser.Server.Startup.Common.FFMpeg;
|
||||
|
||||
|
@ -98,12 +97,6 @@ namespace MediaBrowser.Server.Startup.Common
|
|||
|
||||
void AllowSystemStandby();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the power management.
|
||||
/// </summary>
|
||||
/// <returns>IPowerManagement.</returns>
|
||||
IPowerManagement GetPowerManagement();
|
||||
|
||||
FFMpegInstallInfo GetFfmpegInstallInfo();
|
||||
|
||||
void LaunchUrl(string url);
|
||||
|
|
|
@ -123,7 +123,6 @@
|
|||
<Compile Include="Native\Standby.cs" />
|
||||
<Compile Include="Native\ServerAuthorization.cs" />
|
||||
<Compile Include="Native\WindowsApp.cs" />
|
||||
<Compile Include="Native\WindowsPowerManagement.cs" />
|
||||
<Compile Include="Networking\CertificateGenerator.cs" />
|
||||
<Compile Include="Networking\NativeMethods.cs" />
|
||||
<Compile Include="Networking\NetworkManager.cs" />
|
||||
|
|
|
@ -9,7 +9,6 @@ using System.IO;
|
|||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using CommonIO;
|
||||
using MediaBrowser.Controller.Power;
|
||||
using MediaBrowser.Model.System;
|
||||
using MediaBrowser.Server.Implementations.Persistence;
|
||||
using MediaBrowser.Server.Startup.Common.FFMpeg;
|
||||
|
@ -148,11 +147,6 @@ namespace MediaBrowser.ServerApplication.Native
|
|||
MainStartup.Invoke(Standby.AllowSleep);
|
||||
}
|
||||
|
||||
public IPowerManagement GetPowerManagement()
|
||||
{
|
||||
return new WindowsPowerManagement(_logger);
|
||||
}
|
||||
|
||||
public FFMpegInstallInfo GetFfmpegInstallInfo()
|
||||
{
|
||||
var info = new FFMpegInstallInfo();
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using MediaBrowser.Controller.Power;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace MediaBrowser.ServerApplication.Native
|
||||
{
|
||||
public class WindowsPowerManagement : IPowerManagement
|
||||
{
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern SafeWaitHandle CreateWaitableTimer(IntPtr lpTimerAttributes,
|
||||
bool bManualReset,
|
||||
string lpTimerName);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetWaitableTimer(SafeWaitHandle hTimer,
|
||||
[In] ref long pDueTime,
|
||||
int lPeriod,
|
||||
IntPtr pfnCompletionRoutine,
|
||||
IntPtr lpArgToCompletionRoutine,
|
||||
bool fResume);
|
||||
|
||||
private BackgroundWorker _bgWorker;
|
||||
private readonly ILogger _logger;
|
||||
private readonly object _initLock = new object();
|
||||
|
||||
public WindowsPowerManagement(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void ScheduleWake(DateTime utcTime)
|
||||
{
|
||||
//Initialize();
|
||||
//_bgWorker.RunWorkerAsync(utcTime.ToFileTime());
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
lock (_initLock)
|
||||
{
|
||||
if (_bgWorker == null)
|
||||
{
|
||||
_bgWorker = new BackgroundWorker();
|
||||
|
||||
_bgWorker.DoWork += bgWorker_DoWork;
|
||||
_bgWorker.RunWorkerCompleted += bgWorker_RunWorkerCompleted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
//if (Woken != null)
|
||||
//{
|
||||
// Woken(this, new EventArgs());
|
||||
//}
|
||||
}
|
||||
|
||||
private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
long waketime = (long)e.Argument;
|
||||
|
||||
using (SafeWaitHandle handle = CreateWaitableTimer(IntPtr.Zero, true, GetType().Assembly.GetName().Name + "Timer"))
|
||||
{
|
||||
if (SetWaitableTimer(handle, ref waketime, 0, IntPtr.Zero, IntPtr.Zero, true))
|
||||
{
|
||||
using (EventWaitHandle wh = new EventWaitHandle(false,
|
||||
EventResetMode.AutoReset))
|
||||
{
|
||||
wh.SafeWaitHandle = handle;
|
||||
wh.WaitOne();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error scheduling wake timer", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user