The Free Software Media System - Server Backend & API
Add WanAddress to SystemInfo
Luke Pulverentif856e166ff1a
diff --git a/MediaBrowser.Model/System/SystemInfo.cs b/MediaBrowser.Model/System/SystemInfo.csindex 6a17ad133a..ade4e96fdf 100644--- a/MediaBrowser.Model/System/SystemInfo.cs+++ b/MediaBrowser.Model/System/SystemInfo.cs@@ -110,6 +110,12 @@ namespace MediaBrowser.Model.System/// <value>The HTTP server port number.</value>public int HttpServerPortNumber { get; set; }+ /// <summary>+ /// Gets or sets the wan address.+ /// </summary>+ /// <value>The wan address.</value>+ public string WanAddress { get; set; }+/// <summary>/// Initializes a new instance of the <see cref="SystemInfo" /> class./// </summary>diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteChapterRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteChapterRepository.csindex 075ef42398..5842b05a34 100644--- a/MediaBrowser.Server.Implementations/Persistence/SqliteChapterRepository.cs+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteChapterRepository.cs@@ -32,6 +32,8 @@ namespace MediaBrowser.Server.Implementations.Persistence_logger = logManager.GetLogger(GetType().Name);}+ private SqliteShrinkMemoryTimer _shrinkMemoryTimer;+/// <summary>/// Opens the connection to the database/// </summary>@@ -52,6 +54,8 @@ namespace MediaBrowser.Server.Implementations.Persistence_connection.RunQueries(queries, _logger);PrepareStatements();++ _shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);}/// <summary>@@ -282,6 +286,12 @@ namespace MediaBrowser.Server.Implementations.Persistence{lock (_disposeLock){+ if (_shrinkMemoryTimer != null)+ {+ _shrinkMemoryTimer.Dispose();+ _shrinkMemoryTimer = null;+ }+if (_connection != null){if (_connection.IsOpen())diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteProviderInfoRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteProviderInfoRepository.csindex 5d836b090d..9971c74605 100644--- a/MediaBrowser.Server.Implementations/Persistence/SqliteProviderInfoRepository.cs+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteProviderInfoRepository.cs@@ -25,6 +25,8 @@ namespace MediaBrowser.Server.Implementations.Persistence_logger = logManager.GetLogger(GetType().Name);}+ private SqliteShrinkMemoryTimer _shrinkMemoryTimer;+/// <summary>/// Opens the connection to the database/// </summary>@@ -50,6 +52,8 @@ namespace MediaBrowser.Server.Implementations.Persistence_connection.RunQueries(queries, _logger);PrepareStatements();++ _shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);}private static readonly string[] SaveColumns =@@ -240,6 +244,12 @@ namespace MediaBrowser.Server.Implementations.Persistence{lock (_disposeLock){+ if (_shrinkMemoryTimer != null)+ {+ _shrinkMemoryTimer.Dispose();+ _shrinkMemoryTimer = null;+ }+if (_connection != null){if (_connection.IsOpen())diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.csindex 6058c59581..46a7430b02 100644--- a/MediaBrowser.ServerApplication/ApplicationHost.cs+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs@@ -28,7 +28,6 @@ using MediaBrowser.Controller.Session;using MediaBrowser.Controller.Sorting;using MediaBrowser.Model.Logging;using MediaBrowser.Model.MediaInfo;-using MediaBrowser.Model.Serialization;using MediaBrowser.Model.System;using MediaBrowser.Model.Updates;using MediaBrowser.Providers;@@ -49,6 +48,7 @@ using MediaBrowser.Server.Implementations.Providers;using MediaBrowser.Server.Implementations.ServerManager;using MediaBrowser.Server.Implementations.Session;using MediaBrowser.Server.Implementations.WebSocket;+using MediaBrowser.ServerApplication.EntryPoints;using MediaBrowser.ServerApplication.FFMpeg;using MediaBrowser.ServerApplication.IO;using MediaBrowser.ServerApplication.Native;@@ -616,7 +616,8 @@ namespace MediaBrowser.ServerApplicationHttpServerPortNumber = ServerConfigurationManager.Configuration.HttpServerPortNumber,OperatingSystem = Environment.OSVersion.ToString(),CanSelfRestart = CanSelfRestart,- CanSelfUpdate = CanSelfUpdate+ CanSelfUpdate = CanSelfUpdate,+ WanAddress = WanAddressEntryPoint.WanAddress};}diff --git a/MediaBrowser.ServerApplication/EntryPoints/WanAddressEntryPoint.cs b/MediaBrowser.ServerApplication/EntryPoints/WanAddressEntryPoint.csnew file mode 100644index 0000000000..44819b3903--- /dev/null+++ b/MediaBrowser.ServerApplication/EntryPoints/WanAddressEntryPoint.cs@@ -0,0 +1,56 @@+using MediaBrowser.Common.Net;+using MediaBrowser.Controller.Plugins;+using System;+using System.IO;+using System.Threading;++namespace MediaBrowser.ServerApplication.EntryPoints+{+ public class WanAddressEntryPoint : IServerEntryPoint+ {+ public static string WanAddress;+ private Timer _timer;+ private readonly IHttpClient _httpClient;++ public WanAddressEntryPoint(IHttpClient httpClient)+ {+ _httpClient = httpClient;+ }++ public void Run()+ {+ _timer = new Timer(TimerCallback, null, TimeSpan.FromMinutes(1), TimeSpan.FromHours(24));+ }++ private async void TimerCallback(object state)+ {+ try+ {+ using (var stream = await _httpClient.Get(new HttpRequestOptions+ {+ Url = "http://bot.whatismyipaddress.com/"++ }).ConfigureAwait(false))+ {+ using (var reader = new StreamReader(stream))+ {+ WanAddress = await reader.ReadToEndAsync().ConfigureAwait(false);+ }+ }+ }+ catch (Exception ex)+ {+ var b = true;+ }+ }++ public void Dispose()+ {+ if (_timer != null)+ {+ _timer.Dispose();+ _timer = null;+ }+ }+ }+}diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csprojindex e02bb1d69a..38e082f12e 100644--- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj+++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj@@ -162,6 +162,7 @@</Compile><Compile Include="EntryPoints\ResourceEntryPoint.cs" /><Compile Include="EntryPoints\StartupWizard.cs" />+ <Compile Include="EntryPoints\WanAddressEntryPoint.cs" /><Compile Include="FFMpeg\FFMpegDownloadInfo.cs" /><Compile Include="FFMpeg\FFMpegInfo.cs" /><Compile Include="IO\FileSystemFactory.cs" />