public async Task <UserProfile> GetOrCreateDefaultUser() { await _lock.WaitAsync(); try { Guid systemId = Guid.Parse(ServiceRegistration.Get <ISystemResolver>().LocalSystemId); IUserProfileDataManagement updm = UserProfileDataManagement; if (updm == null) { return(null); } var result = await updm.GetProfileAsync(systemId); if (result.Success) { return(result.Result); } // First check if there is an "old" client profile with same name but different ID. This happens only for older versions. // This needs to be done to avoid unique constraint violations when creating the new profile by name. // If client profile exists rename it and convert it to a user profile so it can be deleted or used otherwise. string profileName = SystemInformation.ComputerName; var existingProfile = await updm.GetProfileByNameAsync(profileName); if (existingProfile.Success && existingProfile.Result.ProfileId != systemId) { if (await updm.ChangeProfileIdAsync(existingProfile.Result.ProfileId, systemId)) { result = await updm.GetProfileAsync(systemId); if (result.Success) { return(result.Result); } } } // Create a login profile which uses the LocalSystemId and the associated ComputerName Guid profileId = await updm.CreateClientProfileAsync(systemId, profileName); result = await updm.GetProfileAsync(profileId); if (result.Success) { return(result.Result); } return(null); } finally { _lock.Release(); } }
protected IList <IChannelGroup> FilterGroups(IList <IChannelGroup> channelGroups) { UserProfile userProfile = null; IUserProfileDataManagement userProfileDataManagement = ServiceRegistration.Get <IUserProfileDataManagement>(); if (userProfileDataManagement != null) { userProfile = (userProfileDataManagement.GetProfileAsync(UserId).Result)?.Result; if (userProfile != null) { IList <IChannelGroup> filteredGroups = new List <IChannelGroup>(); foreach (IChannelGroup channelGroup in channelGroups) { IUserRestriction restriction = channelGroup as IUserRestriction; if (restriction != null && !userProfile.CheckUserAccess(restriction)) { continue; } filteredGroups.Add(channelGroup); } return(filteredGroups); } } return(channelGroups); }
public IFilter AppendUserFilter(IFilter filter, ICollection <Guid> necessaryMias) { IFilter userFilter = null; IUserProfileDataManagement userProfileDataManagement = ServiceRegistration.Get <IUserProfileDataManagement>(); var res = userProfileDataManagement.GetProfileAsync(UserId).Result; if (res.Success) { userFilter = res.Result.GetUserFilter(necessaryMias); } return(filter == null ? userFilter : userFilter != null?BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filter, userFilter) : filter); }
internal static IFilter AppendUserFilter(Guid?userId, IFilter filter, ICollection <Guid> filterMias) { IFilter userFilter = null; if (userId.HasValue) { IUserProfileDataManagement userProfileDataManagement = ServiceRegistration.Get <IUserProfileDataManagement>(); var res = userProfileDataManagement.GetProfileAsync(userId.Value).Result; if (res.Success) { userFilter = res.Result.GetUserFilter(filterMias); } } return(filter == null ? userFilter : userFilter != null?BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filter, userFilter) : filter); }
protected ICollection <Share> GetAllowedShares() { IMediaLibrary library = ServiceRegistration.Get <IMediaLibrary>(); ICollection <Share> shares = library.GetShares(null)?.Values; IUserProfileDataManagement userProfileDataManagement = ServiceRegistration.Get <IUserProfileDataManagement>(); var res = userProfileDataManagement.GetProfileAsync(UserId).Result; if (!res.Success || !res.Result.RestrictShares) { return(shares); } var allowedShareIds = res.Result.GetAllowedShares(); return(shares.Where(s => allowedShareIds.Contains(s.ShareId)).ToList()); }
public static async Task <bool> AddPreferredLanguagesAsync(Guid?userId, IList <string> preferredAudioLanguuages, IList <string> preferredSubtitleLanguuages) { IUserProfileDataManagement userProfileDataManagement = ServiceRegistration.Get <IUserProfileDataManagement>(); if (userId.HasValue) { var res = userProfileDataManagement.GetProfileAsync(userId.Value).Result; if (res.Success) { await userProfileDataManagement.LoginProfileAsync(userId.Value); foreach (var lang in res.Result.GetPreferredAudioLanguages()) { preferredAudioLanguuages.Add(lang); } foreach (var lang in res.Result.GetPreferredSubtitleLanguages()) { preferredSubtitleLanguuages.Add(lang); } } } if (preferredAudioLanguuages.Count == 0) { preferredAudioLanguuages = new List <string>() { "EN" } } ; if (preferredSubtitleLanguuages.Count == 0) { preferredSubtitleLanguuages = new List <string>() { "EN" } } ; return(true); }