From 33a3e215d03d2e8dad3e653e7c75258dc7eb4989 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 2 Oct 2013 15:08:58 -0400 Subject: added user data save event --- .../AuthorizationRequestFilterAttribute.cs | 2 +- .../BaseApplicationHost.cs | 5 ++ .../Library/IUserDataManager.cs | 5 ++ .../Library/UserDataSaveEventArgs.cs | 36 +++++++++++++ .../MediaBrowser.Controller.csproj | 3 +- .../Session/ISessionController.cs | 61 ++++++++++++++++++++++ MediaBrowser.Controller/Session/ISessionManager.cs | 4 +- .../Session/ISessionRemoteController.cs | 61 ---------------------- MediaBrowser.Controller/Session/SessionInfo.cs | 6 +-- .../Library/UserDataManager.cs | 14 ++++- .../Session/SessionManager.cs | 8 +-- .../Session/WebSocketController.cs | 2 +- MediaBrowser.ServerApplication/ApplicationHost.cs | 2 +- 13 files changed, 134 insertions(+), 75 deletions(-) create mode 100644 MediaBrowser.Controller/Library/UserDataSaveEventArgs.cs create mode 100644 MediaBrowser.Controller/Session/ISessionController.cs delete mode 100644 MediaBrowser.Controller/Session/ISessionRemoteController.cs diff --git a/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs b/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs index d225bdd99..9cc62a6dc 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 4a614f42d..8b8e81e8a 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 95eadbd64..5a4dcd55d 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 000000000..752bed618 --- /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 760ff382c..b032da826 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/ISessionController.cs b/MediaBrowser.Controller/Session/ISessionController.cs new file mode 100644 index 000000000..f37d63b72 --- /dev/null +++ b/MediaBrowser.Controller/Session/ISessionController.cs @@ -0,0 +1,61 @@ +using MediaBrowser.Model.Session; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Session +{ + public interface ISessionController + { + /// + /// Supportses the specified session. + /// + /// The session. + /// true if XXXX, false otherwise + bool Supports(SessionInfo session); + + /// + /// Sends the system command. + /// + /// The session. + /// The command. + /// The cancellation token. + /// Task. + Task SendSystemCommand(SessionInfo session, SystemCommand command, CancellationToken cancellationToken); + + /// + /// Sends the message command. + /// + /// The session. + /// The command. + /// The cancellation token. + /// Task. + Task SendMessageCommand(SessionInfo session, MessageCommand command, CancellationToken cancellationToken); + + /// + /// Sends the play command. + /// + /// The session. + /// The command. + /// The cancellation token. + /// Task. + Task SendPlayCommand(SessionInfo session, PlayRequest command, CancellationToken cancellationToken); + + /// + /// Sends the browse command. + /// + /// The session. + /// The command. + /// The cancellation token. + /// Task. + Task SendBrowseCommand(SessionInfo session, BrowseRequest command, CancellationToken cancellationToken); + + /// + /// Sends the playstate command. + /// + /// The session. + /// The command. + /// The cancellation token. + /// Task. + Task SendPlaystateCommand(SessionInfo session, PlaystateRequest command, CancellationToken cancellationToken); + } +} diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index 138aa1fc3..6ee57eb46 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/ISessionRemoteController.cs b/MediaBrowser.Controller/Session/ISessionRemoteController.cs deleted file mode 100644 index 9ba5c983d..000000000 --- a/MediaBrowser.Controller/Session/ISessionRemoteController.cs +++ /dev/null @@ -1,61 +0,0 @@ -using MediaBrowser.Model.Session; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Controller.Session -{ - public interface ISessionRemoteController - { - /// - /// Supportses the specified session. - /// - /// The session. - /// true if XXXX, false otherwise - bool Supports(SessionInfo session); - - /// - /// Sends the system command. - /// - /// The session. - /// The command. - /// The cancellation token. - /// Task. - Task SendSystemCommand(SessionInfo session, SystemCommand command, CancellationToken cancellationToken); - - /// - /// Sends the message command. - /// - /// The session. - /// The command. - /// The cancellation token. - /// Task. - Task SendMessageCommand(SessionInfo session, MessageCommand command, CancellationToken cancellationToken); - - /// - /// Sends the play command. - /// - /// The session. - /// The command. - /// The cancellation token. - /// Task. - Task SendPlayCommand(SessionInfo session, PlayRequest command, CancellationToken cancellationToken); - - /// - /// Sends the browse command. - /// - /// The session. - /// The command. - /// The cancellation token. - /// Task. - Task SendBrowseCommand(SessionInfo session, BrowseRequest command, CancellationToken cancellationToken); - - /// - /// Sends the playstate command. - /// - /// The session. - /// The command. - /// The cancellation token. - /// Task. - Task SendPlaystateCommand(SessionInfo session, PlaystateRequest command, CancellationToken cancellationToken); - } -} diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs index dc934b70a..d50f19c1f 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 5dcfe0edd..34ad7f235 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 d91f0ee0c..efb8dbe10 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 6915cfc64..fb0bc9b7c 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 2d9f22ead..c9d079fc7 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()); -- cgit v1.2.3