From bb031f553b940d21fa89f319d294745484c2234e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 8 May 2014 16:26:20 -0400 Subject: fix portable and 3.5 project references --- .../Collections/CollectionsDynamicFolder.cs | 27 -- .../Collections/ManualCollectionsFolder.cs | 31 ++ .../EntryPoints/Notifications/Notifications.cs | 381 +++++++++++++++++++++ .../EntryPoints/Notifications/Notifier.cs | 381 --------------------- .../HttpServer/DelReceiveWebRequest.cs | 6 + .../HttpServer/GetSwaggerResource.cs | 17 + .../HttpServer/HttpListenerHost.cs | 2 - .../HttpServer/ServerLogFactory.cs | 46 +++ .../HttpServer/ServerLogger.cs | 40 --- .../HttpServer/SwaggerService.cs | 14 - .../Library/Resolvers/BaseItemResolver.cs | 62 ---- .../Library/Resolvers/ItemResolver.cs | 62 ++++ .../Library/Validators/CountHelpers.cs | 171 --------- .../MediaBrowser.Server.Implementations.csproj | 10 +- .../Sorting/IsPlayedComparer.cs | 58 ++++ .../Sorting/IsUnplayedComparer.cs | 51 --- 16 files changed, 608 insertions(+), 751 deletions(-) create mode 100644 MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs create mode 100644 MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs delete mode 100644 MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs create mode 100644 MediaBrowser.Server.Implementations/HttpServer/DelReceiveWebRequest.cs create mode 100644 MediaBrowser.Server.Implementations/HttpServer/GetSwaggerResource.cs create mode 100644 MediaBrowser.Server.Implementations/HttpServer/ServerLogFactory.cs delete mode 100644 MediaBrowser.Server.Implementations/Library/Resolvers/BaseItemResolver.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Resolvers/ItemResolver.cs delete mode 100644 MediaBrowser.Server.Implementations/Library/Validators/CountHelpers.cs create mode 100644 MediaBrowser.Server.Implementations/Sorting/IsPlayedComparer.cs (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionsDynamicFolder.cs b/MediaBrowser.Server.Implementations/Collections/CollectionsDynamicFolder.cs index 834fbcd31..915a27c11 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionsDynamicFolder.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionsDynamicFolder.cs @@ -1,7 +1,6 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; using System.IO; -using System.Linq; namespace MediaBrowser.Server.Implementations.Collections { @@ -26,30 +25,4 @@ namespace MediaBrowser.Server.Implementations.Collections }; } } - - public class ManualCollectionsFolder : BasePluginFolder - { - public ManualCollectionsFolder() - { - Name = "Collections"; - } - - public override bool IsVisible(User user) - { - if (!GetChildren(user, true).Any()) - { - return false; - } - - return base.IsVisible(user); - } - - public override bool IsHidden - { - get - { - return !ActualChildren.Any() || base.IsHidden; - } - } - } } diff --git a/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs b/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs new file mode 100644 index 000000000..e36c63b1c --- /dev/null +++ b/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs @@ -0,0 +1,31 @@ +using System.Linq; +using MediaBrowser.Controller.Entities; + +namespace MediaBrowser.Server.Implementations.Collections +{ + public class ManualCollectionsFolder : BasePluginFolder + { + public ManualCollectionsFolder() + { + Name = "Collections"; + } + + public override bool IsVisible(User user) + { + if (!GetChildren(user, true).Any()) + { + return false; + } + + return base.IsVisible(user); + } + + public override bool IsHidden + { + get + { + return !ActualChildren.Any() || base.IsHidden; + } + } + } +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs new file mode 100644 index 000000000..9d2de0f6d --- /dev/null +++ b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs @@ -0,0 +1,381 @@ +using MediaBrowser.Common.Events; +using MediaBrowser.Common.Plugins; +using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Common.Updates; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Notifications; +using MediaBrowser.Controller.Plugins; +using MediaBrowser.Controller.Session; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Events; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Notifications; +using MediaBrowser.Model.Tasks; +using MediaBrowser.Model.Updates; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications +{ + /// + /// Creates notifications for various system events + /// + public class Notifications : IServerEntryPoint + { + private readonly IInstallationManager _installationManager; + private readonly IUserManager _userManager; + private readonly ILogger _logger; + + private readonly ITaskManager _taskManager; + private readonly INotificationManager _notificationManager; + + private readonly IServerConfigurationManager _config; + private readonly ILibraryManager _libraryManager; + private readonly ISessionManager _sessionManager; + private readonly IServerApplicationHost _appHost; + + private Timer LibraryUpdateTimer { get; set; } + private readonly object _libraryChangedSyncLock = new object(); + + public Notifications(IInstallationManager installationManager, IUserManager userManager, ILogger logger, ITaskManager taskManager, INotificationManager notificationManager, IServerConfigurationManager config, ILibraryManager libraryManager, ISessionManager sessionManager, IServerApplicationHost appHost) + { + _installationManager = installationManager; + _userManager = userManager; + _logger = logger; + _taskManager = taskManager; + _notificationManager = notificationManager; + _config = config; + _libraryManager = libraryManager; + _sessionManager = sessionManager; + _appHost = appHost; + } + + public void Run() + { + _installationManager.PluginInstalled += _installationManager_PluginInstalled; + _installationManager.PluginUpdated += _installationManager_PluginUpdated; + _installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed; + _installationManager.PluginUninstalled += _installationManager_PluginUninstalled; + + _taskManager.TaskCompleted += _taskManager_TaskCompleted; + + _userManager.UserCreated += _userManager_UserCreated; + _libraryManager.ItemAdded += _libraryManager_ItemAdded; + _sessionManager.PlaybackStart += _sessionManager_PlaybackStart; + _appHost.HasPendingRestartChanged += _appHost_HasPendingRestartChanged; + _appHost.HasUpdateAvailableChanged += _appHost_HasUpdateAvailableChanged; + _appHost.ApplicationUpdated += _appHost_ApplicationUpdated; + } + + async void _appHost_ApplicationUpdated(object sender, GenericEventArgs e) + { + var type = NotificationType.ApplicationUpdateInstalled.ToString(); + + var notification = new NotificationRequest + { + NotificationType = type + }; + + notification.Variables["Version"] = e.Argument.versionStr; + notification.Variables["ReleaseNotes"] = e.Argument.description; + + await SendNotification(notification).ConfigureAwait(false); + } + + async void _installationManager_PluginUpdated(object sender, GenericEventArgs> e) + { + var type = NotificationType.PluginUpdateInstalled.ToString(); + + var installationInfo = e.Argument.Item1; + + var notification = new NotificationRequest + { + Description = installationInfo.Description, + NotificationType = type + }; + + notification.Variables["Name"] = installationInfo.Name; + notification.Variables["Version"] = installationInfo.Version.ToString(); + notification.Variables["ReleaseNotes"] = e.Argument.Item2.description; + + await SendNotification(notification).ConfigureAwait(false); + } + + async void _installationManager_PluginInstalled(object sender, GenericEventArgs e) + { + var type = NotificationType.PluginInstalled.ToString(); + + var installationInfo = e.Argument; + + var notification = new NotificationRequest + { + Description = installationInfo.description, + NotificationType = type + }; + + notification.Variables["Name"] = installationInfo.name; + notification.Variables["Version"] = installationInfo.versionStr; + + await SendNotification(notification).ConfigureAwait(false); + } + + async void _appHost_HasUpdateAvailableChanged(object sender, EventArgs e) + { + // This notification is for users who can't auto-update (aka running as service) + if (!_appHost.HasUpdateAvailable || _appHost.CanSelfUpdate) + { + return; + } + + var type = NotificationType.ApplicationUpdateAvailable.ToString(); + + var notification = new NotificationRequest + { + Description = "Please see mediabrowser3.com for details.", + NotificationType = type + }; + + await SendNotification(notification).ConfigureAwait(false); + } + + async void _appHost_HasPendingRestartChanged(object sender, EventArgs e) + { + if (!_appHost.HasPendingRestart) + { + return; + } + + var type = NotificationType.ServerRestartRequired.ToString(); + + var notification = new NotificationRequest + { + NotificationType = type + }; + + await SendNotification(notification).ConfigureAwait(false); + } + + async void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e) + { + var user = e.Users.FirstOrDefault(); + + var item = e.MediaInfo; + + if (item == null) + { + _logger.Warn("PlaybackStart reported with null media info."); + return; + } + + if (e.Item != null && e.Item.Parent == null) + { + // Don't report theme song or local trailer playback + // TODO: This will also cause movie specials to not be reported + return; + } + + var notification = new NotificationRequest + { + NotificationType = GetPlaybackNotificationType(item.MediaType), + + ExcludeUserIds = e.Users.Select(i => i.Id.ToString("N")).ToList() + }; + + notification.Variables["ItemName"] = item.Name; + notification.Variables["UserName"] = user == null ? "Unknown user" : user.Name; + notification.Variables["AppName"] = e.ClientName; + notification.Variables["DeviceName"] = e.DeviceName; + + await SendNotification(notification).ConfigureAwait(false); + } + + private string GetPlaybackNotificationType(string mediaType) + { + if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase)) + { + return NotificationType.AudioPlayback.ToString(); + } + if (string.Equals(mediaType, MediaType.Game, StringComparison.OrdinalIgnoreCase)) + { + return NotificationType.GamePlayback.ToString(); + } + if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase)) + { + return NotificationType.VideoPlayback.ToString(); + } + + return null; + } + + private readonly List _itemsAdded = new List(); + void _libraryManager_ItemAdded(object sender, ItemChangeEventArgs e) + { + if (e.Item.LocationType == LocationType.FileSystem && !e.Item.IsFolder) + { + lock (_libraryChangedSyncLock) + { + if (LibraryUpdateTimer == null) + { + LibraryUpdateTimer = new Timer(LibraryUpdateTimerCallback, null, 5000, + Timeout.Infinite); + } + else + { + LibraryUpdateTimer.Change(5000, Timeout.Infinite); + } + + _itemsAdded.Add(e.Item); + } + } + } + + private async void LibraryUpdateTimerCallback(object state) + { + List items; + + lock (_libraryChangedSyncLock) + { + items = _itemsAdded.ToList(); + _itemsAdded.Clear(); + DisposeLibraryUpdateTimer(); + } + + var item = items.FirstOrDefault(); + + if (item != null) + { + var notification = new NotificationRequest + { + NotificationType = NotificationType.NewLibraryContent.ToString() + }; + + notification.Variables["Name"] = item.Name; + + if (items.Count > 1) + { + notification.Name = items.Count + " new library items."; + } + + await SendNotification(notification).ConfigureAwait(false); + } + } + + async void _userManager_UserCreated(object sender, GenericEventArgs e) + { + var notification = new NotificationRequest + { + UserIds = new List { e.Argument.Id.ToString("N") }, + Name = "Welcome to Media Browser!", + Description = "Check back here for more notifications." + }; + + await SendNotification(notification).ConfigureAwait(false); + } + + async void _taskManager_TaskCompleted(object sender, GenericEventArgs e) + { + var result = e.Argument; + + if (result.Status == TaskCompletionStatus.Failed) + { + var type = NotificationType.TaskFailed.ToString(); + + var notification = new NotificationRequest + { + Description = result.ErrorMessage, + Level = NotificationLevel.Error, + NotificationType = type + }; + + notification.Variables["Name"] = e.Argument.Name; + notification.Variables["ErrorMessage"] = e.Argument.ErrorMessage; + + await SendNotification(notification).ConfigureAwait(false); + } + } + + async void _installationManager_PluginUninstalled(object sender, GenericEventArgs e) + { + var type = NotificationType.PluginUninstalled.ToString(); + + var plugin = e.Argument; + + var notification = new NotificationRequest + { + NotificationType = type + }; + + notification.Variables["Name"] = plugin.Name; + notification.Variables["Version"] = plugin.Version.ToString(); + + await SendNotification(notification).ConfigureAwait(false); + } + + async void _installationManager_PackageInstallationFailed(object sender, InstallationFailedEventArgs e) + { + var installationInfo = e.InstallationInfo; + + var type = NotificationType.InstallationFailed.ToString(); + + var notification = new NotificationRequest + { + Level = NotificationLevel.Error, + Description = e.Exception.Message, + NotificationType = type + }; + + notification.Variables["Name"] = installationInfo.Name; + notification.Variables["Version"] = installationInfo.Version; + + await SendNotification(notification).ConfigureAwait(false); + } + + private async Task SendNotification(NotificationRequest notification) + { + try + { + await _notificationManager.SendNotification(notification, CancellationToken.None).ConfigureAwait(false); + } + catch (Exception ex) + { + _logger.ErrorException("Error sending notification", ex); + } + } + + public void Dispose() + { + DisposeLibraryUpdateTimer(); + + _installationManager.PluginInstalled -= _installationManager_PluginInstalled; + _installationManager.PluginUpdated -= _installationManager_PluginUpdated; + _installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed; + _installationManager.PluginUninstalled -= _installationManager_PluginUninstalled; + + _taskManager.TaskCompleted -= _taskManager_TaskCompleted; + + _userManager.UserCreated -= _userManager_UserCreated; + _libraryManager.ItemAdded -= _libraryManager_ItemAdded; + _sessionManager.PlaybackStart -= _sessionManager_PlaybackStart; + + _appHost.HasPendingRestartChanged -= _appHost_HasPendingRestartChanged; + _appHost.HasUpdateAvailableChanged -= _appHost_HasUpdateAvailableChanged; + _appHost.ApplicationUpdated -= _appHost_ApplicationUpdated; + } + + private void DisposeLibraryUpdateTimer() + { + if (LibraryUpdateTimer != null) + { + LibraryUpdateTimer.Dispose(); + LibraryUpdateTimer = null; + } + } + } +} diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs deleted file mode 100644 index 9d2de0f6d..000000000 --- a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs +++ /dev/null @@ -1,381 +0,0 @@ -using MediaBrowser.Common.Events; -using MediaBrowser.Common.Plugins; -using MediaBrowser.Common.ScheduledTasks; -using MediaBrowser.Common.Updates; -using MediaBrowser.Controller; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Notifications; -using MediaBrowser.Controller.Plugins; -using MediaBrowser.Controller.Session; -using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Events; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Notifications; -using MediaBrowser.Model.Tasks; -using MediaBrowser.Model.Updates; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications -{ - /// - /// Creates notifications for various system events - /// - public class Notifications : IServerEntryPoint - { - private readonly IInstallationManager _installationManager; - private readonly IUserManager _userManager; - private readonly ILogger _logger; - - private readonly ITaskManager _taskManager; - private readonly INotificationManager _notificationManager; - - private readonly IServerConfigurationManager _config; - private readonly ILibraryManager _libraryManager; - private readonly ISessionManager _sessionManager; - private readonly IServerApplicationHost _appHost; - - private Timer LibraryUpdateTimer { get; set; } - private readonly object _libraryChangedSyncLock = new object(); - - public Notifications(IInstallationManager installationManager, IUserManager userManager, ILogger logger, ITaskManager taskManager, INotificationManager notificationManager, IServerConfigurationManager config, ILibraryManager libraryManager, ISessionManager sessionManager, IServerApplicationHost appHost) - { - _installationManager = installationManager; - _userManager = userManager; - _logger = logger; - _taskManager = taskManager; - _notificationManager = notificationManager; - _config = config; - _libraryManager = libraryManager; - _sessionManager = sessionManager; - _appHost = appHost; - } - - public void Run() - { - _installationManager.PluginInstalled += _installationManager_PluginInstalled; - _installationManager.PluginUpdated += _installationManager_PluginUpdated; - _installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed; - _installationManager.PluginUninstalled += _installationManager_PluginUninstalled; - - _taskManager.TaskCompleted += _taskManager_TaskCompleted; - - _userManager.UserCreated += _userManager_UserCreated; - _libraryManager.ItemAdded += _libraryManager_ItemAdded; - _sessionManager.PlaybackStart += _sessionManager_PlaybackStart; - _appHost.HasPendingRestartChanged += _appHost_HasPendingRestartChanged; - _appHost.HasUpdateAvailableChanged += _appHost_HasUpdateAvailableChanged; - _appHost.ApplicationUpdated += _appHost_ApplicationUpdated; - } - - async void _appHost_ApplicationUpdated(object sender, GenericEventArgs e) - { - var type = NotificationType.ApplicationUpdateInstalled.ToString(); - - var notification = new NotificationRequest - { - NotificationType = type - }; - - notification.Variables["Version"] = e.Argument.versionStr; - notification.Variables["ReleaseNotes"] = e.Argument.description; - - await SendNotification(notification).ConfigureAwait(false); - } - - async void _installationManager_PluginUpdated(object sender, GenericEventArgs> e) - { - var type = NotificationType.PluginUpdateInstalled.ToString(); - - var installationInfo = e.Argument.Item1; - - var notification = new NotificationRequest - { - Description = installationInfo.Description, - NotificationType = type - }; - - notification.Variables["Name"] = installationInfo.Name; - notification.Variables["Version"] = installationInfo.Version.ToString(); - notification.Variables["ReleaseNotes"] = e.Argument.Item2.description; - - await SendNotification(notification).ConfigureAwait(false); - } - - async void _installationManager_PluginInstalled(object sender, GenericEventArgs e) - { - var type = NotificationType.PluginInstalled.ToString(); - - var installationInfo = e.Argument; - - var notification = new NotificationRequest - { - Description = installationInfo.description, - NotificationType = type - }; - - notification.Variables["Name"] = installationInfo.name; - notification.Variables["Version"] = installationInfo.versionStr; - - await SendNotification(notification).ConfigureAwait(false); - } - - async void _appHost_HasUpdateAvailableChanged(object sender, EventArgs e) - { - // This notification is for users who can't auto-update (aka running as service) - if (!_appHost.HasUpdateAvailable || _appHost.CanSelfUpdate) - { - return; - } - - var type = NotificationType.ApplicationUpdateAvailable.ToString(); - - var notification = new NotificationRequest - { - Description = "Please see mediabrowser3.com for details.", - NotificationType = type - }; - - await SendNotification(notification).ConfigureAwait(false); - } - - async void _appHost_HasPendingRestartChanged(object sender, EventArgs e) - { - if (!_appHost.HasPendingRestart) - { - return; - } - - var type = NotificationType.ServerRestartRequired.ToString(); - - var notification = new NotificationRequest - { - NotificationType = type - }; - - await SendNotification(notification).ConfigureAwait(false); - } - - async void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e) - { - var user = e.Users.FirstOrDefault(); - - var item = e.MediaInfo; - - if (item == null) - { - _logger.Warn("PlaybackStart reported with null media info."); - return; - } - - if (e.Item != null && e.Item.Parent == null) - { - // Don't report theme song or local trailer playback - // TODO: This will also cause movie specials to not be reported - return; - } - - var notification = new NotificationRequest - { - NotificationType = GetPlaybackNotificationType(item.MediaType), - - ExcludeUserIds = e.Users.Select(i => i.Id.ToString("N")).ToList() - }; - - notification.Variables["ItemName"] = item.Name; - notification.Variables["UserName"] = user == null ? "Unknown user" : user.Name; - notification.Variables["AppName"] = e.ClientName; - notification.Variables["DeviceName"] = e.DeviceName; - - await SendNotification(notification).ConfigureAwait(false); - } - - private string GetPlaybackNotificationType(string mediaType) - { - if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase)) - { - return NotificationType.AudioPlayback.ToString(); - } - if (string.Equals(mediaType, MediaType.Game, StringComparison.OrdinalIgnoreCase)) - { - return NotificationType.GamePlayback.ToString(); - } - if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase)) - { - return NotificationType.VideoPlayback.ToString(); - } - - return null; - } - - private readonly List _itemsAdded = new List(); - void _libraryManager_ItemAdded(object sender, ItemChangeEventArgs e) - { - if (e.Item.LocationType == LocationType.FileSystem && !e.Item.IsFolder) - { - lock (_libraryChangedSyncLock) - { - if (LibraryUpdateTimer == null) - { - LibraryUpdateTimer = new Timer(LibraryUpdateTimerCallback, null, 5000, - Timeout.Infinite); - } - else - { - LibraryUpdateTimer.Change(5000, Timeout.Infinite); - } - - _itemsAdded.Add(e.Item); - } - } - } - - private async void LibraryUpdateTimerCallback(object state) - { - List items; - - lock (_libraryChangedSyncLock) - { - items = _itemsAdded.ToList(); - _itemsAdded.Clear(); - DisposeLibraryUpdateTimer(); - } - - var item = items.FirstOrDefault(); - - if (item != null) - { - var notification = new NotificationRequest - { - NotificationType = NotificationType.NewLibraryContent.ToString() - }; - - notification.Variables["Name"] = item.Name; - - if (items.Count > 1) - { - notification.Name = items.Count + " new library items."; - } - - await SendNotification(notification).ConfigureAwait(false); - } - } - - async void _userManager_UserCreated(object sender, GenericEventArgs e) - { - var notification = new NotificationRequest - { - UserIds = new List { e.Argument.Id.ToString("N") }, - Name = "Welcome to Media Browser!", - Description = "Check back here for more notifications." - }; - - await SendNotification(notification).ConfigureAwait(false); - } - - async void _taskManager_TaskCompleted(object sender, GenericEventArgs e) - { - var result = e.Argument; - - if (result.Status == TaskCompletionStatus.Failed) - { - var type = NotificationType.TaskFailed.ToString(); - - var notification = new NotificationRequest - { - Description = result.ErrorMessage, - Level = NotificationLevel.Error, - NotificationType = type - }; - - notification.Variables["Name"] = e.Argument.Name; - notification.Variables["ErrorMessage"] = e.Argument.ErrorMessage; - - await SendNotification(notification).ConfigureAwait(false); - } - } - - async void _installationManager_PluginUninstalled(object sender, GenericEventArgs e) - { - var type = NotificationType.PluginUninstalled.ToString(); - - var plugin = e.Argument; - - var notification = new NotificationRequest - { - NotificationType = type - }; - - notification.Variables["Name"] = plugin.Name; - notification.Variables["Version"] = plugin.Version.ToString(); - - await SendNotification(notification).ConfigureAwait(false); - } - - async void _installationManager_PackageInstallationFailed(object sender, InstallationFailedEventArgs e) - { - var installationInfo = e.InstallationInfo; - - var type = NotificationType.InstallationFailed.ToString(); - - var notification = new NotificationRequest - { - Level = NotificationLevel.Error, - Description = e.Exception.Message, - NotificationType = type - }; - - notification.Variables["Name"] = installationInfo.Name; - notification.Variables["Version"] = installationInfo.Version; - - await SendNotification(notification).ConfigureAwait(false); - } - - private async Task SendNotification(NotificationRequest notification) - { - try - { - await _notificationManager.SendNotification(notification, CancellationToken.None).ConfigureAwait(false); - } - catch (Exception ex) - { - _logger.ErrorException("Error sending notification", ex); - } - } - - public void Dispose() - { - DisposeLibraryUpdateTimer(); - - _installationManager.PluginInstalled -= _installationManager_PluginInstalled; - _installationManager.PluginUpdated -= _installationManager_PluginUpdated; - _installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed; - _installationManager.PluginUninstalled -= _installationManager_PluginUninstalled; - - _taskManager.TaskCompleted -= _taskManager_TaskCompleted; - - _userManager.UserCreated -= _userManager_UserCreated; - _libraryManager.ItemAdded -= _libraryManager_ItemAdded; - _sessionManager.PlaybackStart -= _sessionManager_PlaybackStart; - - _appHost.HasPendingRestartChanged -= _appHost_HasPendingRestartChanged; - _appHost.HasUpdateAvailableChanged -= _appHost_HasUpdateAvailableChanged; - _appHost.ApplicationUpdated -= _appHost_ApplicationUpdated; - } - - private void DisposeLibraryUpdateTimer() - { - if (LibraryUpdateTimer != null) - { - LibraryUpdateTimer.Dispose(); - LibraryUpdateTimer = null; - } - } - } -} diff --git a/MediaBrowser.Server.Implementations/HttpServer/DelReceiveWebRequest.cs b/MediaBrowser.Server.Implementations/HttpServer/DelReceiveWebRequest.cs new file mode 100644 index 000000000..235910fed --- /dev/null +++ b/MediaBrowser.Server.Implementations/HttpServer/DelReceiveWebRequest.cs @@ -0,0 +1,6 @@ +using System.Net; + +namespace MediaBrowser.Server.Implementations.HttpServer +{ + public delegate void DelReceiveWebRequest(HttpListenerContext context); +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/HttpServer/GetSwaggerResource.cs b/MediaBrowser.Server.Implementations/HttpServer/GetSwaggerResource.cs new file mode 100644 index 000000000..36a257f63 --- /dev/null +++ b/MediaBrowser.Server.Implementations/HttpServer/GetSwaggerResource.cs @@ -0,0 +1,17 @@ +using ServiceStack; + +namespace MediaBrowser.Server.Implementations.HttpServer +{ + /// + /// Class GetDashboardResource + /// + [Route("/swagger-ui/{ResourceName*}", "GET")] + public class GetSwaggerResource + { + /// + /// Gets or sets the name. + /// + /// The name. + public string ResourceName { get; set; } + } +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index cfe5ef4f0..0fc9265f6 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -25,8 +25,6 @@ using System.Threading.Tasks; namespace MediaBrowser.Server.Implementations.HttpServer { - public delegate void DelReceiveWebRequest(HttpListenerContext context); - public class HttpListenerHost : ServiceStackHost, IHttpServer { private string ServerName { get; set; } diff --git a/MediaBrowser.Server.Implementations/HttpServer/ServerLogFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/ServerLogFactory.cs new file mode 100644 index 000000000..40af3f3b0 --- /dev/null +++ b/MediaBrowser.Server.Implementations/HttpServer/ServerLogFactory.cs @@ -0,0 +1,46 @@ +using System; +using MediaBrowser.Model.Logging; +using ServiceStack.Logging; + +namespace MediaBrowser.Server.Implementations.HttpServer +{ + /// + /// Class ServerLogFactory + /// + public class ServerLogFactory : ILogFactory + { + /// + /// The _log manager + /// + private readonly ILogManager _logManager; + + /// + /// Initializes a new instance of the class. + /// + /// The log manager. + public ServerLogFactory(ILogManager logManager) + { + _logManager = logManager; + } + + /// + /// Gets the logger. + /// + /// Name of the type. + /// ILog. + public ILog GetLogger(string typeName) + { + return new ServerLogger(_logManager.GetLogger(typeName)); + } + + /// + /// Gets the logger. + /// + /// The type. + /// ILog. + public ILog GetLogger(Type type) + { + return GetLogger(type.Name); + } + } +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/HttpServer/ServerLogger.cs b/MediaBrowser.Server.Implementations/HttpServer/ServerLogger.cs index 7a4f922ed..bf7924784 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/ServerLogger.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/ServerLogger.cs @@ -4,46 +4,6 @@ using System; namespace MediaBrowser.Server.Implementations.HttpServer { - /// - /// Class ServerLogFactory - /// - public class ServerLogFactory : ILogFactory - { - /// - /// The _log manager - /// - private readonly ILogManager _logManager; - - /// - /// Initializes a new instance of the class. - /// - /// The log manager. - public ServerLogFactory(ILogManager logManager) - { - _logManager = logManager; - } - - /// - /// Gets the logger. - /// - /// Name of the type. - /// ILog. - public ILog GetLogger(string typeName) - { - return new ServerLogger(_logManager.GetLogger(typeName)); - } - - /// - /// Gets the logger. - /// - /// The type. - /// ILog. - public ILog GetLogger(Type type) - { - return GetLogger(type.Name); - } - } - /// /// Class ServerLogger /// diff --git a/MediaBrowser.Server.Implementations/HttpServer/SwaggerService.cs b/MediaBrowser.Server.Implementations/HttpServer/SwaggerService.cs index 8f8505933..3764697f1 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/SwaggerService.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/SwaggerService.cs @@ -1,24 +1,10 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Net; -using ServiceStack; using ServiceStack.Web; using System.IO; namespace MediaBrowser.Server.Implementations.HttpServer { - /// - /// Class GetDashboardResource - /// - [Route("/swagger-ui/{ResourceName*}", "GET")] - public class GetSwaggerResource - { - /// - /// Gets or sets the name. - /// - /// The name. - public string ResourceName { get; set; } - } - public class SwaggerService : IHasResultFactory, IRestfulService { private readonly IApplicationPaths _appPaths; diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseItemResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseItemResolver.cs deleted file mode 100644 index a03eda263..000000000 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseItemResolver.cs +++ /dev/null @@ -1,62 +0,0 @@ -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Resolvers; - -namespace MediaBrowser.Server.Implementations.Library.Resolvers -{ - /// - /// Class ItemResolver - /// - /// - public abstract class ItemResolver : IItemResolver - where T : BaseItem, new() - { - /// - /// Resolves the specified args. - /// - /// The args. - /// `0. - protected virtual T Resolve(ItemResolveArgs args) - { - return null; - } - - /// - /// Gets the priority. - /// - /// The priority. - public virtual ResolverPriority Priority - { - get - { - return ResolverPriority.First; - } - } - - /// - /// Sets initial values on the newly resolved item - /// - /// The item. - /// The args. - protected virtual void SetInitialItemValues(T item, ItemResolveArgs args) - { - } - - /// - /// Resolves the path. - /// - /// The args. - /// BaseItem. - BaseItem IItemResolver.ResolvePath(ItemResolveArgs args) - { - var item = Resolve(args); - - if (item != null) - { - SetInitialItemValues(item, args); - } - - return item; - } - } -} diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/ItemResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/ItemResolver.cs new file mode 100644 index 000000000..a03eda263 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/ItemResolver.cs @@ -0,0 +1,62 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Resolvers; + +namespace MediaBrowser.Server.Implementations.Library.Resolvers +{ + /// + /// Class ItemResolver + /// + /// + public abstract class ItemResolver : IItemResolver + where T : BaseItem, new() + { + /// + /// Resolves the specified args. + /// + /// The args. + /// `0. + protected virtual T Resolve(ItemResolveArgs args) + { + return null; + } + + /// + /// Gets the priority. + /// + /// The priority. + public virtual ResolverPriority Priority + { + get + { + return ResolverPriority.First; + } + } + + /// + /// Sets initial values on the newly resolved item + /// + /// The item. + /// The args. + protected virtual void SetInitialItemValues(T item, ItemResolveArgs args) + { + } + + /// + /// Resolves the path. + /// + /// The args. + /// BaseItem. + BaseItem IItemResolver.ResolvePath(ItemResolveArgs args) + { + var item = Resolve(args); + + if (item != null) + { + SetInitialItemValues(item, args); + } + + return item; + } + } +} diff --git a/MediaBrowser.Server.Implementations/Library/Validators/CountHelpers.cs b/MediaBrowser.Server.Implementations/Library/Validators/CountHelpers.cs deleted file mode 100644 index edb4e7382..000000000 --- a/MediaBrowser.Server.Implementations/Library/Validators/CountHelpers.cs +++ /dev/null @@ -1,171 +0,0 @@ -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Entities.Movies; -using MediaBrowser.Controller.Entities.TV; -using MediaBrowser.Model.Dto; -using System; -using System.Collections.Generic; - -namespace MediaBrowser.Server.Implementations.Library.Validators -{ - /// - /// Class CountHelpers - /// - internal static class CountHelpers - { - private static CountType? GetCountType(BaseItem item) - { - if (item is Movie) - { - return CountType.Movie; - } - if (item is Episode) - { - return CountType.Episode; - } - if (item is Game) - { - return CountType.Game; - } - if (item is Audio) - { - return CountType.Song; - } - if (item is Trailer) - { - return CountType.Trailer; - } - if (item is Series) - { - return CountType.Series; - } - if (item is MusicAlbum) - { - return CountType.MusicAlbum; - } - if (item is MusicVideo) - { - return CountType.MusicVideo; - } - if (item is AdultVideo) - { - return CountType.AdultVideo; - } - - return null; - } - - /// - /// Increments the count. - /// - /// The counts. - /// The key. - internal static void IncrementCount(Dictionary counts, CountType key) - { - int count; - - if (counts.TryGetValue(key, out count)) - { - count++; - counts[key] = count; - } - else - { - counts.Add(key, 1); - } - } - - /// - /// Gets the counts. - /// - /// The counts. - /// ItemByNameCounts. - internal static ItemByNameCounts GetCounts(Dictionary counts) - { - return new ItemByNameCounts - { - AdultVideoCount = GetCount(counts, CountType.AdultVideo), - AlbumCount = GetCount(counts, CountType.MusicAlbum), - EpisodeCount = GetCount(counts, CountType.Episode), - GameCount = GetCount(counts, CountType.Game), - MovieCount = GetCount(counts, CountType.Movie), - MusicVideoCount = GetCount(counts, CountType.MusicVideo), - SeriesCount = GetCount(counts, CountType.Series), - SongCount = GetCount(counts, CountType.Song), - TrailerCount = GetCount(counts, CountType.Trailer), - TotalCount = GetCount(counts, CountType.Total) - }; - } - - /// - /// Gets the count. - /// - /// The counts. - /// The key. - /// System.Int32. - internal static int GetCount(Dictionary counts, CountType key) - { - int count; - - if (counts.TryGetValue(key, out count)) - { - return count; - } - - return 0; - } - - /// - /// Sets the item counts. - /// - /// The user id. - /// The media. - /// The names. - /// The master dictionary. - internal static void SetItemCounts(Guid userId, BaseItem media, IEnumerable names, Dictionary>> masterDictionary) - { - var countType = GetCountType(media); - - foreach (var name in names) - { - Dictionary> libraryCounts; - - if (!masterDictionary.TryGetValue(name, out libraryCounts)) - { - libraryCounts = new Dictionary>(); - masterDictionary.Add(name, libraryCounts); - } - - var userLibId = userId/* ?? Guid.Empty*/; - Dictionary userDictionary; - - if (!libraryCounts.TryGetValue(userLibId, out userDictionary)) - { - userDictionary = new Dictionary(); - libraryCounts.Add(userLibId, userDictionary); - } - - if (countType.HasValue) - { - IncrementCount(userDictionary, countType.Value); - } - - IncrementCount(userDictionary, CountType.Total); - } - } - } - - internal enum CountType - { - AdultVideo, - MusicAlbum, - Episode, - Game, - Movie, - MusicVideo, - Series, - Song, - Trailer, - Total - } -} diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 74b8bf269..21fcd736f 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -104,6 +104,7 @@ + @@ -114,7 +115,7 @@ - + @@ -128,6 +129,8 @@ + + @@ -135,6 +138,7 @@ + @@ -149,7 +153,7 @@ - + @@ -163,7 +167,6 @@ - @@ -225,6 +228,7 @@ + diff --git a/MediaBrowser.Server.Implementations/Sorting/IsPlayedComparer.cs b/MediaBrowser.Server.Implementations/Sorting/IsPlayedComparer.cs new file mode 100644 index 000000000..aebfbdb1c --- /dev/null +++ b/MediaBrowser.Server.Implementations/Sorting/IsPlayedComparer.cs @@ -0,0 +1,58 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Querying; + +namespace MediaBrowser.Server.Implementations.Sorting +{ + public class IsPlayedComparer : IUserBaseItemComparer + { + /// + /// Gets or sets the user. + /// + /// The user. + public User User { get; set; } + + /// + /// Compares the specified x. + /// + /// The x. + /// The y. + /// System.Int32. + public int Compare(BaseItem x, BaseItem y) + { + return GetValue(x).CompareTo(GetValue(y)); + } + + /// + /// Gets the date. + /// + /// The x. + /// DateTime. + private int GetValue(BaseItem x) + { + return x.IsPlayed(User) ? 0 : 1; + } + + /// + /// Gets the name. + /// + /// The name. + public string Name + { + get { return ItemSortBy.IsUnplayed; } + } + + /// + /// Gets or sets the user data repository. + /// + /// The user data repository. + public IUserDataManager UserDataRepository { get; set; } + + /// + /// Gets or sets the user manager. + /// + /// The user manager. + public IUserManager UserManager { get; set; } + } +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Sorting/IsUnplayedComparer.cs b/MediaBrowser.Server.Implementations/Sorting/IsUnplayedComparer.cs index e3053155f..f1c6a5a4e 100644 --- a/MediaBrowser.Server.Implementations/Sorting/IsUnplayedComparer.cs +++ b/MediaBrowser.Server.Implementations/Sorting/IsUnplayedComparer.cs @@ -55,55 +55,4 @@ namespace MediaBrowser.Server.Implementations.Sorting /// The user manager. public IUserManager UserManager { get; set; } } - - public class IsPlayedComparer : IUserBaseItemComparer - { - /// - /// Gets or sets the user. - /// - /// The user. - public User User { get; set; } - - /// - /// Compares the specified x. - /// - /// The x. - /// The y. - /// System.Int32. - public int Compare(BaseItem x, BaseItem y) - { - return GetValue(x).CompareTo(GetValue(y)); - } - - /// - /// Gets the date. - /// - /// The x. - /// DateTime. - private int GetValue(BaseItem x) - { - return x.IsPlayed(User) ? 0 : 1; - } - - /// - /// Gets the name. - /// - /// The name. - public string Name - { - get { return ItemSortBy.IsUnplayed; } - } - - /// - /// Gets or sets the user data repository. - /// - /// The user data repository. - public IUserDataManager UserDataRepository { get; set; } - - /// - /// Gets or sets the user manager. - /// - /// The user manager. - public IUserManager UserManager { get; set; } - } } -- cgit v1.2.3