/// <summary> /// Tries to find the resource path corresponding to the given media library <paramref name="viewSpecification"/>. /// </summary> /// <param name="viewSpecification">View specification to be examined.</param> /// <param name="path">Path corresponding to the given <paramref name="viewSpecification"/>, if it is a media library view specification (i.e. one of the /// view specifications which are created in any of the sub views of this view specification). Else, this parameter will return <c>null</c>.</param> /// <returns><c>true</c>, if the given <paramref name="viewSpecification"/> is one of the direct or indirect view specifications which are created as sub view specifications /// of this view specification.</returns> public static bool TryGetLocalBrowseViewPath(ViewSpecification viewSpecification, out ResourcePath path) { MediaLibraryBrowseViewSpecification mlbvs = viewSpecification as MediaLibraryBrowseViewSpecification; if (mlbvs != null) { // We're in some MediaLibrary browsing state IServerConnectionManager serverConnectionManager = ServiceRegistration.Get <IServerConnectionManager>(); string localSystemId = ServiceRegistration.Get <ISystemResolver>().LocalSystemId; if (mlbvs.SystemId != localSystemId && mlbvs.SystemId != serverConnectionManager.HomeServerSystemId) { // If the currently browsed system is a different one, the path must be set to null path = null; return(true); } // In a browsing state for the local system, we can return the base path from the view specification path = mlbvs.BasePath; return(true); } BrowseMediaRootProxyViewSpecification bmrvs = viewSpecification as BrowseMediaRootProxyViewSpecification; SystemSharesViewSpecification ssvs = viewSpecification as SystemSharesViewSpecification; AllSystemsViewSpecification asvs = viewSpecification as AllSystemsViewSpecification; if (ssvs != null || asvs != null || bmrvs != null) { // If the current browsing state shows one of the root browse states, we can just set the path to null path = null; return(true); } path = null; return(false); }
protected internal override void ReLoadItemsAndSubViewSpecifications(out IList <MediaItem> mediaItems, out IList <ViewSpecification> subViewSpecifications) { mediaItems = null; subViewSpecifications = null; IContentDirectory cd = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory; if (cd == null) { return; } try { mediaItems = new List <MediaItem>(cd.Browse(_directoryId, _necessaryMIATypeIds, _optionalMIATypeIds)); ICollection <MediaItem> childDirectories = cd.Browse(_directoryId, DIRECTORY_MIA_ID_ENUMERATION, EMPTY_ID_ENUMERATION); subViewSpecifications = new List <ViewSpecification>(childDirectories.Count); foreach (MediaItem childDirectory in childDirectories) { MediaItemAspect ma = childDirectory.Aspects[MediaAspect.ASPECT_ID]; MediaItemAspect pra = childDirectory.Aspects[ProviderResourceAspect.ASPECT_ID]; MediaLibraryBrowseViewSpecification subViewSpecification = new MediaLibraryBrowseViewSpecification( (string)ma.GetAttributeValue(MediaAspect.ATTR_TITLE), childDirectory.MediaItemId, (string)pra.GetAttributeValue(ProviderResourceAspect.ATTR_SYSTEM_ID), ResourcePath.Deserialize((string)pra.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH)), _necessaryMIATypeIds, _optionalMIATypeIds); subViewSpecifications.Add(subViewSpecification); } } catch (UPnPRemoteException e) { ServiceRegistration.Get <ILogger>().Error("SimpleTextSearchViewSpecification.ReLoadItemsAndSubViewSpecifications: Error requesting server", e); mediaItems = null; subViewSpecifications = null; } }
protected internal override void ReLoadItemsAndSubViewSpecifications(out IList <MediaItem> mediaItems, out IList <ViewSpecification> subViewSpecifications) { mediaItems = null; subViewSpecifications = null; IContentDirectory cd = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory; if (cd == null) { return; } Guid? userProfile = null; IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>(); if (userProfileDataManagement != null && userProfileDataManagement.IsValidUser) { userProfile = userProfileDataManagement.CurrentUser.ProfileId; } try { bool showVirtual = VirtualMediaHelper.ShowVirtualMedia(_necessaryMIATypeIds); mediaItems = new List <MediaItem>(cd.BrowseAsync(_directoryId, _necessaryMIATypeIds, _optionalMIATypeIds, userProfile, showVirtual).Result); ICollection <MediaItem> childDirectories = cd.BrowseAsync(_directoryId, DIRECTORY_MIA_ID_ENUMERATION, EMPTY_ID_ENUMERATION, userProfile, showVirtual).Result; subViewSpecifications = new List <ViewSpecification>(childDirectories.Count); foreach (MediaItem childDirectory in childDirectories) { SingleMediaItemAspect ma = null; MediaItemAspect.TryGetAspect(childDirectory.Aspects, MediaAspect.Metadata, out ma); IList <MultipleMediaItemAspect> pras = null; MediaItemAspect.TryGetAspects(childDirectory.Aspects, ProviderResourceAspect.Metadata, out pras); foreach (MultipleMediaItemAspect pra in pras) { MediaLibraryBrowseViewSpecification subViewSpecification = new MediaLibraryBrowseViewSpecification( (string)ma.GetAttributeValue(MediaAspect.ATTR_TITLE), childDirectory.MediaItemId, (string)pra.GetAttributeValue(ProviderResourceAspect.ATTR_SYSTEM_ID), ResourcePath.Deserialize((string)pra.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH)), _necessaryMIATypeIds, _optionalMIATypeIds); subViewSpecifications.Add(subViewSpecification); } } } catch (UPnPRemoteException e) { ServiceRegistration.Get <ILogger>().Error("SimpleTextSearchViewSpecification.ReLoadItemsAndSubViewSpecifications: Error requesting server", e); mediaItems = null; subViewSpecifications = null; } }
protected internal override void ReLoadItemsAndSubViewSpecifications(out IList<MediaItem> mediaItems, out IList<ViewSpecification> subViewSpecifications) { mediaItems = null; subViewSpecifications = null; IContentDirectory cd = ServiceRegistration.Get<IServerConnectionManager>().ContentDirectory; if (cd == null) return; try { mediaItems = new List<MediaItem>(cd.Browse(_directoryId, _necessaryMIATypeIds, _optionalMIATypeIds)); ICollection<MediaItem> childDirectories = cd.Browse(_directoryId, DIRECTORY_MIA_ID_ENUMERATION, EMPTY_ID_ENUMERATION); subViewSpecifications = new List<ViewSpecification>(childDirectories.Count); foreach (MediaItem childDirectory in childDirectories) { MediaItemAspect ma = childDirectory.Aspects[MediaAspect.ASPECT_ID]; MediaItemAspect pra = childDirectory.Aspects[ProviderResourceAspect.ASPECT_ID]; MediaLibraryBrowseViewSpecification subViewSpecification = new MediaLibraryBrowseViewSpecification( (string) ma.GetAttributeValue(MediaAspect.ATTR_TITLE), childDirectory.MediaItemId, (string) pra.GetAttributeValue(ProviderResourceAspect.ATTR_SYSTEM_ID), ResourcePath.Deserialize((string) pra.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH)), _necessaryMIATypeIds, _optionalMIATypeIds); subViewSpecifications.Add(subViewSpecification); } } catch (UPnPRemoteException e) { ServiceRegistration.Get<ILogger>().Error("SimpleTextSearchViewSpecification.ReLoadItemsAndSubViewSpecifications: Error requesting server", e); mediaItems = null; subViewSpecifications = null; } }