/// <summary> /// Not currently used. Hopefully Media service doesn't need to know anything /// about the member/device (maybe account/user retention time for media object?) /// </summary> /// <param name="accountId"></param> /// <param name="id"></param> /// <returns></returns> private async Task <User> LoadAsync(Guid accountId, Guid id) { Logger.LogMessage("Requesting user: {0}", id); lock (LockObject) { if (UsersById.ContainsKey(id)) { return(UsersById[id]); } } try { Logger.LogMessage("User not found in cache, getting from membership."); var request = new GetAccountUserByIdRequest { User = new UserSummaryDto { AccountId = accountId, UserId = id }, RequestSource = Source.Media }; var response = await _bus.RequestAsync <GetAccountUserByIdRequest, GetAccountUserByIdResponse>(request); Logger.LogMessage("Got user {0}", response.User); var user = AutoMapper.Mapper.Map <User>(response.User); return(Cache(user)); } catch (Exception ex) { Logger.LogException(ex, "****** Failed to load user by id:" + id); throw; } }
/// <summary> /// User is not in the local cache, get them from the Membership Service. /// </summary> /// <param name="accountId"></param> /// <param name="userId"></param> /// <returns></returns> private async Task <User> GetUserFromMembership(Guid accountId, Guid userId) { Stopwatch stopwatch = Stopwatch.StartNew(); try { _logger.LogInformation("Cache miss, requesting user from membership service. Id: {0}", userId); var request = new GetAccountUserByIdRequest { User = new UserSummaryDto { AccountId = accountId, UserId = userId }, RequestSource = Source.Measurements }; var response = await _bus.RequestAsync <GetAccountUserByIdRequest, GetAccountUserByIdResponse>(request); if (response.User == null) { _logger.LogWarning("User not found: {0} (AccountId: {1})", userId, accountId); return(null); } User user = Cache(_mapper.Map <User>(response.User)); // Clean up the user location. if (user.Location != null) { if (!user.Location.IsValidLocation()) { user.Location = null; } } // User wasn't stored in the local DB so get them from the Membership service. await UpdateUserPropertiesAsync(user); return(user); } catch (TimeoutException ex) { _logger.LogError(ex, "Membership service timeout exception. Failed to load user: "******"Failed to load user: "******"Load user from membership service took {stopwatch.ElapsedMilliseconds}"); } }