Exemplo n.º 1
0
        protected VideoDriveHandler(DriveInfo driveInfo, IEnumerable <Guid> extractedMIATypeIds) : base(driveInfo)
        {
            IMediaAccessor    mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();
            ResourcePath      rp            = LocalFsResourceProviderBase.ToResourcePath(driveInfo.Name);
            IResourceAccessor ra;

            if (!rp.TryCreateLocalResourceAccessor(out ra))
            {
                throw new ArgumentException(string.Format("Unable to access drive '{0}'", driveInfo.Name));
            }
            using (ra)
                _mediaItem = mediaAccessor.CreateLocalMediaItem(ra, mediaAccessor.GetMetadataExtractorsForMIATypes(extractedMIATypeIds));
            if (_mediaItem == null)
            {
                throw new Exception(string.Format("Could not create media item for drive '{0}'", driveInfo.Name));
            }

            MatchWithStubs(driveInfo, new MediaItem[] { _mediaItem });
            IEnumerable <MediaItem> processedItems = CertificationHelper.ProcessMediaItems(new MediaItem[] { _mediaItem });

            if (processedItems.Count() == 0)
            {
                _mediaItem = null;
                return;
            }
            _mediaItem = processedItems.First();
            SingleMediaItemAspect mia = null;

            MediaItemAspect.TryGetAspect(_mediaItem.Aspects, MediaAspect.Metadata, out mia);
            mia.SetAttribute(MediaAspect.ATTR_TITLE, mia.GetAttributeValue(MediaAspect.ATTR_TITLE) +
                             " (" + DriveUtils.GetDriveNameWithoutRootDirectory(driveInfo) + ")");
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        public void TestMediaItemLoader_SingleMIAs_LikeFilter()
        {
            MockDBUtils.Reset();
            SingleTestMIA mia1 = TestBackendUtils.CreateSingleMIA("SINGLE1", Cardinality.Inline, true, false);
            SingleTestMIA mia2 = TestBackendUtils.CreateSingleMIA("SINGLE2", Cardinality.Inline, false, true);
            SingleTestMIA mia3 = TestBackendUtils.CreateSingleMIA("SINGLE3", Cardinality.Inline, true, true);

            Guid itemId = new Guid("aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa");

            IFilter filter = new LikeFilter(mia1.ATTR_STRING, "%", null);

            MockReader reader = MockDBUtils.AddReader(
                "SELECT T0.MEDIA_ITEM_ID A4, T0.MEDIA_ITEM_ID A5, T1.MEDIA_ITEM_ID A6, T2.MEDIA_ITEM_ID A7, T0.ATTR_STRING A0, T1.ATTR_INTEGER A1, T2.ATTR_STRING A2, T2.ATTR_INTEGER A3 " +
                "FROM M_SINGLE1 T0 INNER JOIN M_SINGLE2 T1 ON T1.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID LEFT OUTER JOIN M_SINGLE3 T2 ON T2.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID " +
                " WHERE T0.ATTR_STRING LIKE @V0", "A4", "A5", "A6", "A7", "A0", "A1", "A2", "A3");

            reader.AddResult(itemId, itemId, itemId, itemId, "zerozero", 11, "twotwo", 33);

            Guid[]                 requiredAspects = new Guid[] { mia1.ASPECT_ID, mia2.ASPECT_ID };
            Guid[]                 optionalAspects = new Guid[] { mia3.ASPECT_ID };
            MediaItemQuery         query           = new MediaItemQuery(requiredAspects, optionalAspects, filter);
            CompiledMediaItemQuery compiledQuery   = CompiledMediaItemQuery.Compile(MockCore.Management, query);
            MediaItem              result          = compiledQuery.QueryMediaItem();

            //Console.WriteLine("Query result " + result.MediaItemId + ": " + string.Join(",", result.Aspects) + ": " + result);

            Assert.AreEqual(itemId, result.MediaItemId, "MediaItem ID");
            SingleMediaItemAspect value = null;

            Assert.IsTrue(MediaItemAspect.TryGetAspect(result.Aspects, mia1.Metadata, out value), "MIA1");
            Assert.AreEqual("zerozero", value.GetAttributeValue(mia1.ATTR_STRING), "MIA1 string attibute");
            Assert.IsTrue(MediaItemAspect.TryGetAspect(result.Aspects, mia2.Metadata, out value), "MIA2");
            Assert.AreEqual(11, value.GetAttributeValue(mia2.ATTR_INTEGER), "MIA2 integer attibute");
            Assert.IsTrue(MediaItemAspect.TryGetAspect(result.Aspects, mia3.Metadata, out value), "MIA3");
            Assert.AreEqual("twotwo", value.GetAttributeValue(mia3.ATTR_STRING), "MIA3 string attibute");
            Assert.AreEqual(33, value.GetAttributeValue(mia3.ATTR_INTEGER), "MIA3 integer attibute");
        }