diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations')
5 files changed, 3 insertions, 166 deletions
diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs index 9ad04ebbd..af81b4eea 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs @@ -10,6 +10,7 @@ using System.IO; using System.Net; using System.Text; using System.Threading; +using System.Threading.Tasks; using CommonIO; using MediaBrowser.Common.IO; @@ -40,7 +41,7 @@ namespace MediaBrowser.Server.Implementations.Connect public void Run() { - LoadCachedAddress(); + Task.Run(() => LoadCachedAddress()); _timer = new Timer(TimerCallback, null, TimeSpan.FromSeconds(5), TimeSpan.FromHours(3)); } diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index f1de09d56..fdc7e9ee2 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -1073,11 +1073,6 @@ namespace MediaBrowser.Server.Implementations.Connect public async Task<ConnectSupporterSummary> GetConnectSupporterSummary() { - if (!_securityManager.IsMBSupporter) - { - return new ConnectSupporterSummary(); - } - var url = GetConnectUrl("keyAssociation"); var options = new HttpRequestOptions @@ -1106,11 +1101,6 @@ namespace MediaBrowser.Server.Implementations.Connect public async Task AddConnectSupporter(string id) { - if (!_securityManager.IsMBSupporter) - { - throw new InvalidOperationException(); - } - var url = GetConnectUrl("keyAssociation"); var options = new HttpRequestOptions @@ -1139,11 +1129,6 @@ namespace MediaBrowser.Server.Implementations.Connect public async Task RemoveConnectSupporter(string id) { - if (!_securityManager.IsMBSupporter) - { - throw new InvalidOperationException(); - } - var url = GetConnectUrl("keyAssociation"); var options = new HttpRequestOptions diff --git a/MediaBrowser.Server.Implementations/EntryPoints/LoadRegistrations.cs b/MediaBrowser.Server.Implementations/EntryPoints/LoadRegistrations.cs index 27170ced9..701cf21fb 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/LoadRegistrations.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/LoadRegistrations.cs @@ -41,7 +41,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// </summary> public void Run() { - _timer = new Timer(s => LoadAllRegistrations(), null, TimeSpan.FromMilliseconds(100), TimeSpan.FromHours(24)); + _timer = new Timer(s => LoadAllRegistrations(), null, TimeSpan.FromMilliseconds(100), TimeSpan.FromHours(12)); } private async Task LoadAllRegistrations() diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/RemoteNotifications.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/RemoteNotifications.cs deleted file mode 100644 index 9a20505a5..000000000 --- a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/RemoteNotifications.cs +++ /dev/null @@ -1,148 +0,0 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.IO; -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Notifications; -using MediaBrowser.Controller.Plugins; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Notifications; -using MediaBrowser.Model.Serialization; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using CommonIO; - -namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications -{ - public class RemoteNotifications : IServerEntryPoint - { - private const string Url = "http://www.mb3admin.com/admin/service/MB3ServerNotifications.json"; - - private Timer _timer; - private readonly IHttpClient _httpClient; - private readonly IApplicationPaths _appPaths; - private readonly ILogger _logger; - private readonly IJsonSerializer _json; - private readonly IUserManager _userManager; - private readonly IFileSystem _fileSystem; - - private readonly TimeSpan _frequency = TimeSpan.FromHours(6); - private readonly TimeSpan _maxAge = TimeSpan.FromDays(31); - - private readonly INotificationManager _notificationManager; - - public RemoteNotifications(IApplicationPaths appPaths, ILogger logger, IHttpClient httpClient, IJsonSerializer json, IUserManager userManager, IFileSystem fileSystem, INotificationManager notificationManager) - { - _appPaths = appPaths; - _logger = logger; - _httpClient = httpClient; - _json = json; - _userManager = userManager; - _fileSystem = fileSystem; - _notificationManager = notificationManager; - } - - /// <summary> - /// Runs this instance. - /// </summary> - public void Run() - { - _timer = new Timer(OnTimerFired, null, TimeSpan.FromMilliseconds(500), _frequency); - } - - /// <summary> - /// Called when [timer fired]. - /// </summary> - /// <param name="state">The state.</param> - private async void OnTimerFired(object state) - { - var dataPath = Path.Combine(_appPaths.DataPath, "remotenotifications.json"); - - var lastRunTime = _fileSystem.FileExists(dataPath) ? _fileSystem.GetLastWriteTimeUtc(dataPath) : DateTime.MinValue; - - try - { - await DownloadNotifications(dataPath, lastRunTime).ConfigureAwait(false); - } - catch (Exception ex) - { - _logger.ErrorException("Error downloading remote notifications", ex); - } - } - - /// <summary> - /// Downloads the notifications. - /// </summary> - /// <param name="dataPath">The data path.</param> - /// <param name="lastRunTime">The last run time.</param> - /// <returns>Task.</returns> - private async Task DownloadNotifications(string dataPath, DateTime lastRunTime) - { - using (var stream = await _httpClient.Get(new HttpRequestOptions - { - Url = Url - - }).ConfigureAwait(false)) - { - var notifications = _json.DeserializeFromStream<RemoteNotification[]>(stream); - - _fileSystem.WriteAllText(dataPath, string.Empty); - - await CreateNotifications(notifications, lastRunTime).ConfigureAwait(false); - } - } - - /// <summary> - /// Creates the notifications. - /// </summary> - /// <param name="notifications">The notifications.</param> - /// <param name="lastRunTime">The last run time.</param> - /// <returns>Task.</returns> - private async Task CreateNotifications(IEnumerable<RemoteNotification> notifications, DateTime lastRunTime) - { - // Only show notifications that are active, new since last download, and not older than max age - var notificationList = notifications - .Where(i => string.Equals(i.active, "1") && i.date.ToUniversalTime() > lastRunTime && (DateTime.UtcNow - i.date.ToUniversalTime()) <= _maxAge) - .ToList(); - - var userIds = _userManager.Users.Select(i => i.Id.ToString("N")).ToList(); - - foreach (var notification in notificationList) - { - await _notificationManager.SendNotification(new NotificationRequest - { - Date = notification.date, - Name = notification.name, - Description = notification.description, - Url = notification.url, - UserIds = userIds - - }, CancellationToken.None).ConfigureAwait(false); - } - } - - public void Dispose() - { - if (_timer != null) - { - _timer.Dispose(); - _timer = null; - } - } - - private class RemoteNotification - { - public string id { get; set; } - public DateTime date { get; set; } - public string name { get; set; } - public string description { get; set; } - public string category { get; set; } - public string url { get; set; } - public object imageUrl { get; set; } - public string active { get; set; } - } - } -} diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index bec2abdc4..52adae14c 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -131,7 +131,6 @@ <Compile Include="EntryPoints\LibraryChangedNotifier.cs" /> <Compile Include="EntryPoints\LoadRegistrations.cs" /> <Compile Include="EntryPoints\Notifications\Notifications.cs" /> - <Compile Include="EntryPoints\Notifications\RemoteNotifications.cs" /> <Compile Include="EntryPoints\Notifications\WebSocketNotifier.cs" /> <Compile Include="EntryPoints\RefreshUsersMetadata.cs" /> <Compile Include="EntryPoints\UsageEntryPoint.cs" /> |
