|
|
@ -21,40 +21,11 @@ namespace MediaBrowser.Server.Implementations.Library
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class UserManager : IUserManager
|
|
|
|
public class UserManager : IUserManager
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The _users
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private IEnumerable<User> _users;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The _user lock
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private object _usersSyncLock = new object();
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The _users initialized
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private bool _usersInitialized;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the users.
|
|
|
|
/// Gets the users.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The users.</value>
|
|
|
|
/// <value>The users.</value>
|
|
|
|
public IEnumerable<User> Users
|
|
|
|
public IEnumerable<User> Users { get; private set; }
|
|
|
|
{
|
|
|
|
|
|
|
|
get
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Call ToList to exhaust the stream because we'll be iterating over this multiple times
|
|
|
|
|
|
|
|
LazyInitializer.EnsureInitialized(ref _users, ref _usersInitialized, ref _usersSyncLock, LoadUsers);
|
|
|
|
|
|
|
|
return _users;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
internal set
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_users = value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (value == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_usersInitialized = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// The _logger
|
|
|
|
/// The _logger
|
|
|
@ -78,11 +49,13 @@ namespace MediaBrowser.Server.Implementations.Library
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
|
|
|
|
|
|
|
/// <param name="userRepository">The user repository.</param>
|
|
|
|
public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository)
|
|
|
|
public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
UserRepository = userRepository;
|
|
|
|
UserRepository = userRepository;
|
|
|
|
ConfigurationManager = configurationManager;
|
|
|
|
ConfigurationManager = configurationManager;
|
|
|
|
|
|
|
|
Users = new List<User>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region UserUpdated Event
|
|
|
|
#region UserUpdated Event
|
|
|
@ -132,6 +105,11 @@ namespace MediaBrowser.Server.Implementations.Library
|
|
|
|
return Users.FirstOrDefault(u => u.Id == id);
|
|
|
|
return Users.FirstOrDefault(u => u.Id == id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task Initialize()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Users = await LoadUsers().ConfigureAwait(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Authenticates a User and returns a result indicating whether or not it succeeded
|
|
|
|
/// Authenticates a User and returns a result indicating whether or not it succeeded
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -185,7 +163,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|
|
|
/// Loads the users from the repository
|
|
|
|
/// Loads the users from the repository
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>IEnumerable{User}.</returns>
|
|
|
|
/// <returns>IEnumerable{User}.</returns>
|
|
|
|
private IEnumerable<User> LoadUsers()
|
|
|
|
private async Task<IEnumerable<User>> LoadUsers()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var users = UserRepository.RetrieveAllUsers().ToList();
|
|
|
|
var users = UserRepository.RetrieveAllUsers().ToList();
|
|
|
|
|
|
|
|
|
|
|
@ -198,10 +176,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|
|
|
|
|
|
|
|
|
|
|
user.DateLastSaved = DateTime.UtcNow;
|
|
|
|
user.DateLastSaved = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
|
|
var task = UserRepository.SaveUser(user, CancellationToken.None);
|
|
|
|
await UserRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
// Hate having to block threads
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
users.Add(user);
|
|
|
|
users.Add(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|