From 5b3bde4d9a21066b3b62f52b95a4a88b9e0d3a7e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 16 Mar 2014 12:15:10 -0400 Subject: [PATCH] fixed dlna user reporting --- MediaBrowser.Api/SessionsService.cs | 19 +++-- .../Session/ISessionManager.cs | 15 ++-- .../Manager/MetadataService.cs | 13 +++- .../Session/SessionManager.cs | 78 ++++++++----------- 4 files changed, 67 insertions(+), 58 deletions(-) diff --git a/MediaBrowser.Api/SessionsService.cs b/MediaBrowser.Api/SessionsService.cs index b8ca70ba5..df35c93a0 100644 --- a/MediaBrowser.Api/SessionsService.cs +++ b/MediaBrowser.Api/SessionsService.cs @@ -277,7 +277,7 @@ namespace MediaBrowser.Api SeekPositionTicks = request.SeekPositionTicks }; - var task = _sessionManager.SendPlaystateCommand(request.Id, command, CancellationToken.None); + var task = _sessionManager.SendPlaystateCommand(GetSession().Id, request.Id, command, CancellationToken.None); Task.WaitAll(task); } @@ -296,7 +296,7 @@ namespace MediaBrowser.Api ItemType = request.ItemType }; - var task = _sessionManager.SendBrowseCommand(request.Id, command, CancellationToken.None); + var task = _sessionManager.SendBrowseCommand(GetSession().Id, request.Id, command, CancellationToken.None); Task.WaitAll(task); } @@ -307,7 +307,7 @@ namespace MediaBrowser.Api /// The request. public void Post(SendSystemCommand request) { - var task = _sessionManager.SendSystemCommand(request.Id, request.Command, CancellationToken.None); + var task = _sessionManager.SendSystemCommand(GetSession().Id, request.Id, request.Command, CancellationToken.None); Task.WaitAll(task); } @@ -325,7 +325,7 @@ namespace MediaBrowser.Api Text = request.Text }; - var task = _sessionManager.SendMessageCommand(request.Id, command, CancellationToken.None); + var task = _sessionManager.SendMessageCommand(GetSession().Id, request.Id, command, CancellationToken.None); Task.WaitAll(task); } @@ -344,7 +344,7 @@ namespace MediaBrowser.Api StartPositionTicks = request.StartPositionTicks }; - var task = _sessionManager.SendPlayCommand(request.Id, command, CancellationToken.None); + var task = _sessionManager.SendPlayCommand(GetSession().Id, request.Id, command, CancellationToken.None); Task.WaitAll(task); } @@ -367,5 +367,14 @@ namespace MediaBrowser.Api .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } + + private SessionInfo GetSession() + { + var auth = AuthorizationRequestFilterAttribute.GetAuthorization(Request); + + return _sessionManager.Sessions.First(i => string.Equals(i.DeviceId, auth.DeviceId) && + string.Equals(i.Client, auth.Client) && + string.Equals(i.ApplicationVersion, auth.Version)); + } } } \ No newline at end of file diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index ee29671c0..6ca15585a 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -86,47 +86,52 @@ namespace MediaBrowser.Controller.Session /// /// Sends the system command. /// + /// The controlling session identifier. /// The session id. /// The command. /// The cancellation token. /// Task. - Task SendSystemCommand(Guid sessionId, SystemCommand command, CancellationToken cancellationToken); + Task SendSystemCommand(Guid controllingSessionId, Guid sessionId, SystemCommand command, CancellationToken cancellationToken); /// /// Sends the message command. /// + /// The controlling session identifier. /// The session id. /// The command. /// The cancellation token. /// Task. - Task SendMessageCommand(Guid sessionId, MessageCommand command, CancellationToken cancellationToken); + Task SendMessageCommand(Guid controllingSessionId, Guid sessionId, MessageCommand command, CancellationToken cancellationToken); /// /// Sends the play command. /// + /// The controlling session identifier. /// The session id. /// The command. /// The cancellation token. /// Task. - Task SendPlayCommand(Guid sessionId, PlayRequest command, CancellationToken cancellationToken); + Task SendPlayCommand(Guid controllingSessionId, Guid sessionId, PlayRequest command, CancellationToken cancellationToken); /// /// Sends the browse command. /// + /// The controlling session identifier. /// The session id. /// The command. /// The cancellation token. /// Task. - Task SendBrowseCommand(Guid sessionId, BrowseRequest command, CancellationToken cancellationToken); + Task SendBrowseCommand(Guid controllingSessionId, Guid sessionId, BrowseRequest command, CancellationToken cancellationToken); /// /// Sends the playstate command. /// + /// The controlling session identifier. /// The session id. /// The command. /// The cancellation token. /// Task. - Task SendPlaystateCommand(Guid sessionId, PlaystateRequest command, CancellationToken cancellationToken); + Task SendPlaystateCommand(Guid controllingSessionId, Guid sessionId, PlaystateRequest command, CancellationToken cancellationToken); /// /// Sends the restart required message. diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs index 74b54fe2c..dfd13d8c3 100644 --- a/MediaBrowser.Providers/Manager/MetadataService.cs +++ b/MediaBrowser.Providers/Manager/MetadataService.cs @@ -56,11 +56,16 @@ namespace MediaBrowser.Providers.Manager /// /// Gets the last result. /// - /// The item identifier. + /// The item. /// ProviderResult. - protected MetadataStatus GetLastResult(Guid itemId) + protected MetadataStatus GetLastResult(IHasMetadata item) { - return ProviderRepo.GetMetadataStatus(itemId) ?? new MetadataStatus { ItemId = itemId }; + if (item.DateLastSaved == default(DateTime)) + { + return new MetadataStatus { ItemId = item.Id }; + } + + return ProviderRepo.GetMetadataStatus(item.Id) ?? new MetadataStatus { ItemId = item.Id }; } public async Task RefreshMetadata(IHasMetadata item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken) @@ -74,7 +79,7 @@ namespace MediaBrowser.Providers.Manager var config = ProviderManager.GetMetadataOptions(item); var updateType = ItemUpdateType.None; - var refreshResult = GetLastResult(item.Id); + var refreshResult = GetLastResult(item); refreshResult.LastErrorMessage = string.Empty; refreshResult.LastStatus = ProviderRefreshStatus.Success; diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index cea70a8b4..3acc5e892 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -622,42 +622,27 @@ namespace MediaBrowser.Server.Implementations.Session return session; } - /// - /// Sends the system command. - /// - /// The session id. - /// The command. - /// The cancellation token. - /// Task. - public Task SendSystemCommand(Guid sessionId, SystemCommand command, CancellationToken cancellationToken) + public Task SendSystemCommand(Guid controllingSessionId, Guid sessionId, SystemCommand command, CancellationToken cancellationToken) { var session = GetSessionForRemoteControl(sessionId); + var controllingSession = GetSession(controllingSessionId); + AssertCanControl(session, controllingSession); + return session.SessionController.SendSystemCommand(command, cancellationToken); } - /// - /// Sends the message command. - /// - /// The session id. - /// The command. - /// The cancellation token. - /// Task. - public Task SendMessageCommand(Guid sessionId, MessageCommand command, CancellationToken cancellationToken) + public Task SendMessageCommand(Guid controllingSessionId, Guid sessionId, MessageCommand command, CancellationToken cancellationToken) { var session = GetSessionForRemoteControl(sessionId); + var controllingSession = GetSession(controllingSessionId); + AssertCanControl(session, controllingSession); + return session.SessionController.SendMessageCommand(command, cancellationToken); } - /// - /// Sends the play command. - /// - /// The session id. - /// The command. - /// The cancellation token. - /// Task. - public Task SendPlayCommand(Guid sessionId, PlayRequest command, CancellationToken cancellationToken) + public Task SendPlayCommand(Guid controllingSessionId, Guid sessionId, PlayRequest command, CancellationToken cancellationToken) { var session = GetSessionForRemoteControl(sessionId); @@ -690,36 +675,27 @@ namespace MediaBrowser.Server.Implementations.Session } } - if (session.UserId.HasValue) + var controllingSession = GetSession(controllingSessionId); + AssertCanControl(session, controllingSession); + if (controllingSession.UserId.HasValue) { - command.ControllingUserId = session.UserId.Value.ToString("N"); + command.ControllingUserId = controllingSession.UserId.Value.ToString("N"); } return session.SessionController.SendPlayCommand(command, cancellationToken); } - /// - /// Sends the browse command. - /// - /// The session id. - /// The command. - /// The cancellation token. - /// Task. - public Task SendBrowseCommand(Guid sessionId, BrowseRequest command, CancellationToken cancellationToken) + public Task SendBrowseCommand(Guid controllingSessionId, Guid sessionId, BrowseRequest command, CancellationToken cancellationToken) { var session = GetSessionForRemoteControl(sessionId); + var controllingSession = GetSession(controllingSessionId); + AssertCanControl(session, controllingSession); + return session.SessionController.SendBrowseCommand(command, cancellationToken); } - /// - /// Sends the playstate command. - /// - /// The session id. - /// The command. - /// The cancellation token. - /// Task. - public Task SendPlaystateCommand(Guid sessionId, PlaystateRequest command, CancellationToken cancellationToken) + public Task SendPlaystateCommand(Guid controllingSessionId, Guid sessionId, PlaystateRequest command, CancellationToken cancellationToken) { var session = GetSessionForRemoteControl(sessionId); @@ -728,14 +704,28 @@ namespace MediaBrowser.Server.Implementations.Session throw new ArgumentException(string.Format("Session {0} is unable to seek.", session.Id)); } - if (session.UserId.HasValue) + var controllingSession = GetSession(controllingSessionId); + AssertCanControl(session, controllingSession); + if (controllingSession.UserId.HasValue) { - command.ControllingUserId = session.UserId.Value.ToString("N"); + command.ControllingUserId = controllingSession.UserId.Value.ToString("N"); } return session.SessionController.SendPlaystateCommand(command, cancellationToken); } + private void AssertCanControl(SessionInfo session, SessionInfo controllingSession) + { + if (session == null) + { + throw new ArgumentNullException("session"); + } + if (controllingSession == null) + { + throw new ArgumentNullException("controllingSession"); + } + } + /// /// Sends the restart required message. ///