public async Task InitializeUserAsync() { IUserProfileDataManagement userManager = ServiceRegistration.Get <IUserProfileDataManagement>(); if (UserId.HasValue) { await userManager.LoginProfileAsync(UserId.Value); var audioList = await userManager.GetUserAdditionalDataListAsync(UserId.Value, UserDataKeysKnown.KEY_PREFERRED_AUDIO_LANGUAGE); PreferredAudioLanguages = audioList.Result?.Select(l => l.Item2); if (!(PreferredAudioLanguages?.Any() ?? false)) { PreferredAudioLanguages = new List <string>() { "EN" } } ; var subtitleList = await userManager.GetUserAdditionalDataListAsync(UserId.Value, UserDataKeysKnown.KEY_PREFERRED_SUBTITLE_LANGUAGE); PreferredSubtitleLanguages = subtitleList.Result?.Select(l => l.Item2); if (!(PreferredSubtitleLanguages?.Any() ?? false)) { PreferredSubtitleLanguages = new List <string>() { "EN" } } ; } } }
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 async Task InitializeAsync(string id) { if (RootContainer == null) { IUserProfileDataManagement userManager = ServiceRegistration.Get <IUserProfileDataManagement>(); ClientName = $"DLNA ({id})"; var profile = await userManager.GetProfileByNameAsync(ClientName); if (profile.Success) { ClientId = profile.Result.ProfileId; } else { ClientId = await userManager.CreateProfileAsync(ClientName, UserProfileType.ClientProfile, ""); } await userManager.LoginProfileAsync(ClientId); if (UserId.HasValue) { await InitializeUserAsync(); } InitialiseContainerTree(); } }
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(); } }
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); }
public UserProfile GetOrCreateDefaultUser() { UserProfile user = null; string profileName = SystemInformation.ComputerName; IUserProfileDataManagement updm = UserProfileDataManagement; if (updm != null && !updm.GetProfileByName(profileName, out user)) { Guid profileId = updm.CreateProfile(profileName); if (!updm.GetProfile(profileId, out user)) { return(null); } } return(user); }
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); }
public static Task LoadProfileLinksAsync() { try { IUserProfileDataManagement userManager = ServiceRegistration.Get <IUserProfileDataManagement>(); ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>(); ProfileLinkSettings profileLinks = settingsManager.Load <ProfileLinkSettings>(); //Remove deleted profiles var deletedProfiles = ProfileLinks.Where(p => !profileLinks.Links.Any(lp => lp.ClientName == p.Key)).Select(p => p.Key).ToList(); foreach (var profile in deletedProfiles) { ProfileLinks.TryRemove(profile, out _); } //Add and update profiles foreach (ProfileLink link in profileLinks.Links) { EndPointSettings settings = null; if (!ProfileLinks.TryGetValue(link.ClientName, out settings)) { settings = new EndPointSettings(); ProfileLinks.TryAdd(link.ClientName, settings); } settings.AutoProfile = false; if (Profiles.ContainsKey(link.Profile) == true) { settings.Profile = Profiles[link.Profile]; } else if (link.Profile == NO_PROFILE) { settings.Profile = null; } else if (link.Profile == AUTO_PROFILE) { //settings.Profile = null; settings.AutoProfile = true; } else if (Profiles.ContainsKey(DLNA_DEFAULT_PROFILE_ID) == true) { settings.Profile = Profiles[DLNA_DEFAULT_PROFILE_ID]; } //settings.ClientId = await userManager.CreateProfileAsync($"DLNA ({ip.ToString()})", UserProfileType.ClientProfile, ""); settings.UserId = Guid.TryParse(link.DefaultUserProfile, out Guid g) ? g : (Guid?)null; if (settings.Profile == null) { Logger.Info("DlnaMediaServer: Client: {0}, using profile: {1}", link.ClientName, NO_PROFILE); } else { Logger.Info("DlnaMediaServer: Client: {0}, using profile: {1}", link.ClientName, settings.Profile.ID); } } } catch (Exception e) { Logger.Info("DlnaMediaServer: Exception reading profile links (Text: '{0}')", e.Message); } return(Task.CompletedTask); }
private void InitialiseContainerTree() { if (Profile == null) { return; } ILocalization language = ServiceRegistration.Get <ILocalization>(); List <BasicContainer> mediaRoots = new List <BasicContainer>(); RootContainer = new BasicContainer(MediaLibraryHelper.CONTAINER_ROOT_KEY, this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_ROOT)) ?? "MediaPortal Media Library" }; if (MediaServerPlugin.Settings.ShowUserLogin) { IUserProfileDataManagement userManager = ServiceRegistration.Get <IUserProfileDataManagement>(); var users = userManager.GetProfilesAsync().Result?.Where(u => u.ProfileType == UserProfileType.UserProfile); if (users?.Count() > 0) { foreach (var user in users.Where(u => u.ProfileType == UserProfileType.UserProfile)) { var userContainer = new BasicContainer($"{MediaLibraryHelper.CONTAINER_USERS_KEY}>{user.ProfileId}", this) { Title = user.Name }; RootContainer.Add(userContainer); mediaRoots.Add(userContainer); } } } if (mediaRoots.Count == 0) { mediaRoots.Add(RootContainer); } foreach (var mediaRoot in mediaRoots) { var audioContainer = new BasicContainer(MediaLibraryHelper.CONTAINER_AUDIO_KEY, this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_AUDIO)) ?? "Audio" }; audioContainer.Add(new MediaLibraryAlbumContainer(MediaLibraryHelper.CONTAINER_AUDIO_KEY + "AL", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_ALBUM)) ?? "Albums" }); audioContainer.Add(new MediaLibraryMusicRecentContainer(MediaLibraryHelper.CONTAINER_AUDIO_KEY + "RA", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_RECENT)) ?? "Recently Added" }); audioContainer.Add(new MediaLibraryAlbumArtistContainer(MediaLibraryHelper.CONTAINER_AUDIO_KEY + "AR", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_ALBUM_ARTIST)) ?? "Album Artists" }); audioContainer.Add(new MediaLibraryMusicArtistContainer(MediaLibraryHelper.CONTAINER_AUDIO_KEY + "AAR", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_ARTIST)) ?? "Artists" }); audioContainer.Add(new MediaLibraryMusicGenreContainer(MediaLibraryHelper.CONTAINER_AUDIO_KEY + "G", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_GENRE)) ?? "Genres" }); audioContainer.Add(new MediaLibraryMusicYearContainer(MediaLibraryHelper.CONTAINER_AUDIO_KEY + "AY", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_YEAR)) ?? "Year" }); audioContainer.Add(new MediaLibraryShareContainer(MediaLibraryHelper.CONTAINER_AUDIO_KEY + "AS", this, "Audio") { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_SHARE)) ?? "Shares" }); mediaRoot.Add(audioContainer); var pictureContainer = new BasicContainer(MediaLibraryHelper.CONTAINER_IMAGES_KEY, this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_IMAGE)) ?? "Images" }; pictureContainer.Add(new MediaLibraryImageAlbumContainer(MediaLibraryHelper.CONTAINER_IMAGES_KEY + "IA", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_ALBUM)) ?? "Albums" }); pictureContainer.Add(new MediaLibraryImageRecentContainer(MediaLibraryHelper.CONTAINER_IMAGES_KEY + "RA", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_RECENT)) ?? "Recently Added" }); pictureContainer.Add(new MediaLibraryImageYearContainer(MediaLibraryHelper.CONTAINER_IMAGES_KEY + "IY", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_YEAR)) ?? "Year" }); pictureContainer.Add(new MediaLibraryShareContainer(MediaLibraryHelper.CONTAINER_IMAGES_KEY + "IS", this, "Image") { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_SHARE)) ?? "Shares" }); mediaRoot.Add(pictureContainer); var videoContainer = new BasicContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY, this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_VIDEO)) ?? "Video" }; var movieContainer = new BasicContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "M", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_MOVIE)) ?? "Movies" }; movieContainer.Add(new MediaLibraryMovieContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "MT", null, this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_TITLE)) ?? "Titles" }); movieContainer.Add(new MediaLibraryMovieRecentContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "MRA", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_RECENT)) ?? "Recently Added" }); movieContainer.Add(new MediaLibraryMovieUnwatchedContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "MU", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_UNWATCHED)) ?? "Unwatched" }); movieContainer.Add(new MediaLibraryMovieActorsContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "MAR", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_ACTOR)) ?? "Actors" }); movieContainer.Add(new MediaLibraryMovieGenreContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "MG", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_GENRE)) ?? "Genres" }); movieContainer.Add(new MediaLibraryMovieYearContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "MY", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_YEAR)) ?? "Year" }); videoContainer.Add(movieContainer); var seriesContainer = new BasicContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "S", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_SERIES)) ?? "Series" }; seriesContainer.Add(new MediaLibrarySeriesContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "ST", null, this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_TITLE)) ?? "Titles" }); seriesContainer.Add(new MediaLibrarySeriesActorsContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "SAR", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_ACTOR)) ?? "Actors" }); seriesContainer.Add(new MediaLibrarySeriesGenresContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "SG", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_GENRE)) ?? "Genres" }); seriesContainer.Add(new MediaLibrarySeriesYearContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "SY", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_YEAR)) ?? "Year" }); seriesContainer.Add(new MediaLibrarySeriesRecentContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "SRA", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_RECENT)) ?? "Recently Added" }); seriesContainer.Add(new MediaLibrarySeriesUnwatchedContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "SU", this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_UNWATCHED)) ?? "Unwatched" }); videoContainer.Add(seriesContainer); videoContainer.Add(new MediaLibraryShareContainer(MediaLibraryHelper.CONTAINER_VIDEO_KEY + "VS", this, "Video") { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_SHARE)) ?? "Shares" }); mediaRoot.Add(videoContainer); if (ServiceRegistration.IsRegistered <ITvProvider>()) { mediaRoot.Add(new MediaLibraryBroadcastGroupContainer(MediaLibraryHelper.CONTAINER_BROADCAST_KEY, this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_BROADCAST)) ?? "Broadcasts" }); } mediaRoot.Add(new MediaLibraryShareContainer(MediaLibraryHelper.CONTAINER_MEDIA_SHARES_KEY, this) { Title = StringUtils.TrimToNull(language.ToString(Consts.RES_SHARE)) ?? "Shares" }); } }