diff --git a/MediaBrowser.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs b/MediaBrowser.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs index 0f35a766a..a0b7ff515 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs @@ -28,18 +28,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// public async void Run() { - #if __MonoCS__ - try - { - await _userManager.RefreshUsersMetadata(CancellationToken.None).ConfigureAwait(false); - } - catch - { - System.Console.WriteLine("RefreshUsersMetadata task error: No users? First time running?"); - } - #else await _userManager.RefreshUsersMetadata(CancellationToken.None).ConfigureAwait(false); - #endif } /// diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 4243aecfe..a6d670483 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -21,40 +21,11 @@ namespace MediaBrowser.Server.Implementations.Library /// public class UserManager : IUserManager { - /// - /// The _users - /// - private IEnumerable _users; - /// - /// The _user lock - /// - private object _usersSyncLock = new object(); - /// - /// The _users initialized - /// - private bool _usersInitialized; /// /// Gets the users. /// /// The users. - public IEnumerable Users - { - 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; - } - } - } + public IEnumerable Users { get; private set; } /// /// The _logger @@ -78,11 +49,13 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The logger. /// The configuration manager. + /// The user repository. public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository) { _logger = logger; UserRepository = userRepository; ConfigurationManager = configurationManager; + Users = new List(); } #region UserUpdated Event @@ -132,6 +105,11 @@ namespace MediaBrowser.Server.Implementations.Library return Users.FirstOrDefault(u => u.Id == id); } + public async Task Initialize() + { + Users = await LoadUsers().ConfigureAwait(false); + } + /// /// Authenticates a User and returns a result indicating whether or not it succeeded /// @@ -185,7 +163,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Loads the users from the repository /// /// IEnumerable{User}. - private IEnumerable LoadUsers() + private async Task> LoadUsers() { var users = UserRepository.RetrieveAllUsers().ToList(); @@ -198,10 +176,7 @@ namespace MediaBrowser.Server.Implementations.Library user.DateLastSaved = DateTime.UtcNow; - var task = UserRepository.SaveUser(user, CancellationToken.None); - - // Hate having to block threads - Task.WaitAll(task); + await UserRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false); users.Add(user); } @@ -284,7 +259,7 @@ namespace MediaBrowser.Server.Implementations.Library } public event EventHandler> UserCreated; - + /// /// Creates the user. /// @@ -311,11 +286,11 @@ namespace MediaBrowser.Server.Implementations.Library Users = list; user.DateLastSaved = DateTime.UtcNow; - + await UserRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false); EventHelper.QueueEventIfNotNull(UserCreated, this, new GenericEventArgs { Argument = user }, _logger); - + return user; } diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 5e6a156bb..00db91f41 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -292,6 +292,8 @@ namespace MediaBrowser.ServerApplication await Task.WhenAll(itemsTask, displayPreferencesTask, userdataTask).ConfigureAwait(false); progress.Report(100); + await ((UserManager) UserManager).Initialize().ConfigureAwait(false); + SetKernelProperties(); }