From 33a3e215d03d2e8dad3e653e7c75258dc7eb4989 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 2 Oct 2013 15:08:58 -0400 Subject: [PATCH] added user data save event --- .../AuthorizationRequestFilterAttribute.cs | 2 +- .../BaseApplicationHost.cs | 5 +++ .../Library/IUserDataManager.cs | 5 +++ .../Library/UserDataSaveEventArgs.cs | 36 +++++++++++++++++++ .../MediaBrowser.Controller.csproj | 3 +- ...oteController.cs => ISessionController.cs} | 2 +- .../Session/ISessionManager.cs | 4 +-- .../Session/SessionInfo.cs | 6 ++-- .../Library/UserDataManager.cs | 14 +++++++- .../Session/SessionManager.cs | 8 ++--- .../Session/WebSocketController.cs | 2 +- .../ApplicationHost.cs | 2 +- 12 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 MediaBrowser.Controller/Library/UserDataSaveEventArgs.cs rename MediaBrowser.Controller/Session/{ISessionRemoteController.cs => ISessionController.cs} (98%) diff --git a/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs b/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs index d225bdd994..9cc62a6dc1 100644 --- a/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs +++ b/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs @@ -64,7 +64,7 @@ namespace MediaBrowser.Api if (!string.IsNullOrEmpty(client) && !string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(device) && !string.IsNullOrEmpty(version)) { - SessionManager.LogConnectionActivity(client, version, deviceId, device, user); + SessionManager.LogSessionActivity(client, version, deviceId, device, user); } } } diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 4a614f42d5..8b8e81e8a9 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -413,6 +413,11 @@ namespace MediaBrowser.Common.Implementations { Logger.Error("Error creating {0}", ex, type.Name); +#if DEBUG + throw; +#endif + + // Don't blow up in release mode return null; } } diff --git a/MediaBrowser.Controller/Library/IUserDataManager.cs b/MediaBrowser.Controller/Library/IUserDataManager.cs index 95eadbd64e..5a4dcd55d2 100644 --- a/MediaBrowser.Controller/Library/IUserDataManager.cs +++ b/MediaBrowser.Controller/Library/IUserDataManager.cs @@ -11,6 +11,11 @@ namespace MediaBrowser.Controller.Library /// public interface IUserDataManager { + /// + /// Occurs when [user data saved]. + /// + event EventHandler UserDataSaved; + /// /// Saves the user data. /// diff --git a/MediaBrowser.Controller/Library/UserDataSaveEventArgs.cs b/MediaBrowser.Controller/Library/UserDataSaveEventArgs.cs new file mode 100644 index 0000000000..752bed6185 --- /dev/null +++ b/MediaBrowser.Controller/Library/UserDataSaveEventArgs.cs @@ -0,0 +1,36 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Entities; +using System; + +namespace MediaBrowser.Controller.Library +{ + /// + /// Class UserDataSaveEventArgs + /// + public class UserDataSaveEventArgs : EventArgs + { + /// + /// Gets or sets the user id. + /// + /// The user id. + public Guid UserId { get; set; } + + /// + /// Gets or sets the key. + /// + /// The key. + public string Key { get; set; } + + /// + /// Gets or sets the save reason. + /// + /// The save reason. + public UserDataSaveReason SaveReason { get; set; } + + /// + /// Gets or sets the user data. + /// + /// The user data. + public UserItemData UserData { get; set; } + } +} diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 760ff382ca..b032da8264 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -98,6 +98,7 @@ + @@ -174,7 +175,7 @@ - + diff --git a/MediaBrowser.Controller/Session/ISessionRemoteController.cs b/MediaBrowser.Controller/Session/ISessionController.cs similarity index 98% rename from MediaBrowser.Controller/Session/ISessionRemoteController.cs rename to MediaBrowser.Controller/Session/ISessionController.cs index 9ba5c983d1..f37d63b727 100644 --- a/MediaBrowser.Controller/Session/ISessionRemoteController.cs +++ b/MediaBrowser.Controller/Session/ISessionController.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; namespace MediaBrowser.Controller.Session { - public interface ISessionRemoteController + public interface ISessionController { /// /// Supportses the specified session. diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index 138aa1fc36..6ee57eb466 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -17,7 +17,7 @@ namespace MediaBrowser.Controller.Session /// Adds the parts. /// /// The remote controllers. - void AddParts(IEnumerable remoteControllers); + void AddParts(IEnumerable remoteControllers); /// /// Occurs when [playback start]. @@ -50,7 +50,7 @@ namespace MediaBrowser.Controller.Session /// The user. /// Task. /// user - Task LogConnectionActivity(string clientType, string appVersion, string deviceId, string deviceName, User user); + Task LogSessionActivity(string clientType, string appVersion, string deviceId, string deviceName, User user); /// /// Used to report that playback has started for an item diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs index dc934b70a3..d50f19c1f0 100644 --- a/MediaBrowser.Controller/Session/SessionInfo.cs +++ b/MediaBrowser.Controller/Session/SessionInfo.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using System.Linq; -using MediaBrowser.Common.Net; +using MediaBrowser.Common.Net; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Net; using System; +using System.Collections.Generic; +using System.Linq; namespace MediaBrowser.Controller.Session { diff --git a/MediaBrowser.Server.Implementations/Library/UserDataManager.cs b/MediaBrowser.Server.Implementations/Library/UserDataManager.cs index 5dcfe0eddc..34ad7f235d 100644 --- a/MediaBrowser.Server.Implementations/Library/UserDataManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserDataManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Common.Events; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; @@ -15,6 +16,8 @@ namespace MediaBrowser.Server.Implementations.Library /// public class UserDataManager : IUserDataManager { + public event EventHandler UserDataSaved; + private readonly ConcurrentDictionary _userData = new ConcurrentDictionary(); private readonly ILogger _logger; @@ -84,6 +87,15 @@ namespace MediaBrowser.Server.Implementations.Library throw; } + + EventHelper.FireEventIfNotNull(UserDataSaved, this, new UserDataSaveEventArgs + { + Key = key, + UserData = userData, + SaveReason = reason, + UserId = userId + + }, _logger); } /// diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index d91f0ee0c9..efb8dbe10e 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -78,8 +78,8 @@ namespace MediaBrowser.Server.Implementations.Session _userRepository = userRepository; } - private List _remoteControllers; - public void AddParts(IEnumerable remoteControllers) + private List _remoteControllers; + public void AddParts(IEnumerable remoteControllers) { _remoteControllers = remoteControllers.ToList(); } @@ -104,7 +104,7 @@ namespace MediaBrowser.Server.Implementations.Session /// Task. /// /// user - public async Task LogConnectionActivity(string clientType, string appVersion, string deviceId, string deviceName, User user) + public async Task LogSessionActivity(string clientType, string appVersion, string deviceId, string deviceName, User user) { if (string.IsNullOrEmpty(clientType)) { @@ -442,7 +442,7 @@ namespace MediaBrowser.Server.Implementations.Session /// /// The session. /// IEnumerable{ISessionRemoteController}. - private IEnumerable GetControllers(SessionInfo session) + private IEnumerable GetControllers(SessionInfo session) { return _remoteControllers.Where(i => i.Supports(session)); } diff --git a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs index 6915cfc64f..fb0bc9b7c1 100644 --- a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs +++ b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace MediaBrowser.Server.Implementations.Session { - public class WebSocketController : ISessionRemoteController + public class WebSocketController : ISessionController { public bool Supports(SessionInfo session) { diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 2d9f22eadf..c9d079fc71 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -427,7 +427,7 @@ namespace MediaBrowser.ServerApplication ProviderManager.AddParts(GetExports()); - SessionManager.AddParts(GetExports()); + SessionManager.AddParts(GetExports()); ImageProcessor.AddParts(GetExports());