예제 #1
0
        protected override IList <GetChildrenReferenceResult> LoadChildrenReferencesAndTypes(ContentReference contentLink, string languageID, out bool languageSpecific)
        {
            languageSpecific = false;
            var childrenList = new List <GetChildrenReferenceResult>();

            // Add Playlists, Subscriptions and Search as default nodes
            if (EntryPoint.CompareToIgnoreWorkID(contentLink))
            {
                childrenList.Add(new GetChildrenReferenceResult {
                    ContentLink = _identityMappingService.Get(MappedIdentity.ConstructExternalIdentifier(ProviderKey, "Playlists"), true).ContentLink, IsLeafNode = false, ModelType = typeof(YouTubeFolder)
                });
                childrenList.Add(new GetChildrenReferenceResult {
                    ContentLink = _identityMappingService.Get(MappedIdentity.ConstructExternalIdentifier(ProviderKey, "Subscriptions"), true).ContentLink, IsLeafNode = false, ModelType = typeof(YouTubeFolder)
                });

                SearchResultNode = _identityMappingService.Get(MappedIdentity.ConstructExternalIdentifier(ProviderKey, "Search"), true).ContentLink;
                childrenList.Add(new GetChildrenReferenceResult {
                    ContentLink = SearchResultNode, IsLeafNode = false, ModelType = typeof(YouTubeFolder)
                });

                return(childrenList);
            }

            var     mappedItem = _identityMappingService.Get(contentLink);
            dynamic items;

            switch (GetYouTubeResourceType(mappedItem.ExternalIdentifier))
            {
            case YouTubeResourceType.PlaylistRoot:

                items = _youTubeRepository.ListPlaylists();
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey,
                                                                             string.Format("{0}/{1}/{2}", YouTubeResourceType.Playlist.ToString().ToLower(), contentLink.ID, item.id));
                        var mappedChild = _identityMappingService.Get(uri, true);
                        childrenList.Add(new GetChildrenReferenceResult
                        {
                            ContentLink = mappedChild.ContentLink,
                            IsLeafNode  = false,
                            ModelType   = typeof(YouTubePlaylist)
                        });

                        // We have all the data about the YouTube resource and creates the content instance and adds it to the cache.
                        AddContentToCache(CreateYouTubeData(mappedChild, typeof(YouTubePlaylist), item));
                    }
                }
                break;

            case YouTubeResourceType.Playlist:

                items = _youTubeRepository.ListPlaylistItems(mappedItem.ExternalIdentifier.Segments[3]);
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey,
                                                                             string.Format("{0}/{1}/{2}/{3}", YouTubeResourceType.Playlist.ToString().ToLower(), contentLink.ID,
                                                                                           mappedItem.ExternalIdentifier.Segments[3], item.id));
                        var mappedChild = _identityMappingService.Get(uri, true);
                        childrenList.Add(new GetChildrenReferenceResult
                        {
                            ContentLink = mappedChild.ContentLink,
                            IsLeafNode  = true,
                            ModelType   = typeof(YouTubePlaylistItem)
                        });

                        // We have all the data about the YouTube resource and creates the content instance and adds it to the cache.
                        AddContentToCache(CreatePlaylistItem(mappedChild, item));
                    }
                }
                break;

            case YouTubeResourceType.SubscriptionRoot:

                items = _youTubeRepository.ListSubscriptions();
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey,
                                                                             string.Format("{0}/{1}/{2}/{3}", YouTubeResourceType.Subscription.ToString().ToLower(), contentLink.ID, item.id,
                                                                                           item.snippet.resourceId.channelId));
                        var mappedChild = _identityMappingService.Get(uri, true);
                        childrenList.Add(new GetChildrenReferenceResult
                        {
                            ContentLink = mappedChild.ContentLink,
                            IsLeafNode  = false,
                            ModelType   = typeof(YouTubeSubscription)
                        });

                        // We have all the data about the YouTube resource and creates the content instance and adds it to the cache.
                        AddContentToCache(CreateYouTubeData(mappedChild, typeof(YouTubeSubscription), item));
                    }
                }
                break;

            case YouTubeResourceType.Subscription:

                items = _youTubeRepository.ListPlaylists(mappedItem.ExternalIdentifier.Segments[4]);
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey,
                                                                             string.Format("{0}/{1}/{2}", YouTubeResourceType.Playlist.ToString().ToLower(), contentLink.ID, item.id));
                        var mappedChild = _identityMappingService.Get(uri, true);
                        childrenList.Add(new GetChildrenReferenceResult
                        {
                            ContentLink = mappedChild.ContentLink,
                            IsLeafNode  = false,
                            ModelType   = typeof(YouTubePlaylist)
                        });

                        // We have all the data about the YouTube resource and creates the content instance and adds it to the cache.
                        AddContentToCache(CreateYouTubeData(mappedChild, typeof(YouTubePlaylist), item));
                    }
                }
                break;

            case YouTubeResourceType.Search:

                childrenList.AddRange(SearchResult.Select(item => new GetChildrenReferenceResult()
                {
                    ContentLink = item.ContentLink, IsLeafNode = true, ModelType = typeof(YouTubeVideo)
                }));

                break;
            }

            return(childrenList);
        }