update admin session filter

This commit is contained in:
Luke Pulverenti 2016-08-20 14:43:13 -04:00
parent 234dcaf458
commit acd60f1d85
5 changed files with 18 additions and 35 deletions

View File

@ -185,12 +185,8 @@ namespace MediaBrowser.Controller.Session
/// Sends the message to user sessions.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="userId">The user identifier.</param>
/// <param name="name">The name.</param>
/// <param name="data">The data.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
Task SendMessageToUserSessions<T>(string userId, string name, T data, CancellationToken cancellationToken);
Task SendMessageToUserSessions<T>(List<string> userIds, string name, T data, CancellationToken cancellationToken);
/// <summary>
/// Sends the message to user device sessions.

View File

@ -54,18 +54,15 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private async void SendMessage(string name, TimerEventInfo info)
{
var users = _userManager.Users.Where(i => i.Policy.EnableLiveTvAccess).ToList();
var users = _userManager.Users.Where(i => i.Policy.EnableLiveTvAccess).Select(i => i.Id.ToString("N")).ToList();
foreach (var user in users)
try
{
try
{
await _sessionManager.SendMessageToUserSessions<TimerEventInfo>(user.Id.ToString("N"), name, info, CancellationToken.None);
}
catch (Exception ex)
{
_logger.ErrorException("Error sending message", ex);
}
await _sessionManager.SendMessageToUserSessions<TimerEventInfo>(users, name, info, CancellationToken.None);
}
catch (Exception ex)
{
_logger.ErrorException("Error sending message", ex);
}
}

View File

@ -11,6 +11,7 @@ using MediaBrowser.Controller.Sync;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Sync;
using System;
using System.Collections.Generic;
using System.Threading;
namespace MediaBrowser.Server.Implementations.EntryPoints
@ -164,7 +165,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private async void SendMessageToUserSession<T>(User user, string name, T data)
{
await _sessionManager.SendMessageToUserSessions(user.Id.ToString("N"), name, data, CancellationToken.None);
await _sessionManager.SendMessageToUserSessions(new List<string> { user.Id.ToString("N") }, name, data, CancellationToken.None);
}
/// <summary>

View File

@ -1871,29 +1871,15 @@ namespace MediaBrowser.Server.Implementations.Session
public Task SendMessageToAdminSessions<T>(string name, T data, CancellationToken cancellationToken)
{
// TODO: How to identify admin sessions?
var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null).ToList();
var adminUserIds = _userManager.Users.Where(i => i.Policy.IsAdministrator).Select(i => i.Id.ToString("N")).ToList();
var tasks = sessions.Select(session => Task.Run(async () =>
{
try
{
await session.SessionController.SendMessage(name, data, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.ErrorException("Error sending message", ex);
}
}, cancellationToken));
return Task.WhenAll(tasks);
return SendMessageToUserSessions(adminUserIds, name, data, cancellationToken);
}
public Task SendMessageToUserSessions<T>(string userId, string name, T data,
public Task SendMessageToUserSessions<T>(List<string> userIds, string name, T data,
CancellationToken cancellationToken)
{
var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null && i.ContainsUser(userId)).ToList();
var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null && userIds.Any(i.ContainsUser)).ToList();
var tasks = sessions.Select(session => Task.Run(async () =>
{

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F0E0E64C-2A6F-4E35-9533-D53AC07C2CD1}"
EndProject
@ -65,6 +65,9 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emby.Drawing", "Emby.Drawing\Emby.Drawing.csproj", "{08FFF49B-F175-4807-A2B5-73B0EBD9F716}"
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms