protected override List <ID> GetReference(PlayList entity, Item accountItem)
        {
            if (entity.PlayListSearch == null || entity.PlayListSearch.FilterTags == null || entity.PlayListSearch.FilterTags.Count == 0)
            {
                return(new List <ID>(0));
            }
            Expression <Func <TagSearchResult, bool> > ancestorFilter = ContentSearchUtil.GetAncestorFilter <TagSearchResult>(accountItem, TemplateIDs.Tag);
            Expression <Func <TagSearchResult, bool> > second         = Enumerable.Aggregate <string, Expression <Func <TagSearchResult, bool> > >((IEnumerable <string>)entity.PlayListSearch.FilterTags, PredicateBuilder.False <TagSearchResult>(), (Func <Expression <Func <TagSearchResult, bool> >, string, Expression <Func <TagSearchResult, bool> > >)((current, tmp) => PredicateBuilder.Or <TagSearchResult>(current, (Expression <Func <TagSearchResult, bool> >)(i => i.TagName == tmp))));
            List <TagSearchResult> all = ContentSearchUtil.FindAll <TagSearchResult>(Configuration.Settings.IndexName, PredicateBuilder.And <TagSearchResult>(ancestorFilter, second));

            if (all.Count < entity.PlayListSearch.FilterTags.Count)
            {
                IItemSynchronizer itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(typeof(Entities.Tag));
                if (itemSynchronizer != null)
                {
                    foreach (string str in entity.PlayListSearch.FilterTags)
                    {
                        string tagName = str;
                        if (!Enumerable.Any <TagSearchResult>((IEnumerable <TagSearchResult>)all, (Func <TagSearchResult, bool>)(i => i.Name == tagName)))
                        {
                            TagSearchResult tagSearchResult = itemSynchronizer.Fallback((object)new Entities.Tag()
                            {
                                Name = tagName
                            }, accountItem) as TagSearchResult;
                            if (tagSearchResult != null)
                            {
                                all.Add(tagSearchResult);
                            }
                        }
                    }
                }
            }
            return(Enumerable.ToList <ID>(Enumerable.Select <TagSearchResult, ID>((IEnumerable <TagSearchResult>)all, (Func <TagSearchResult, ID>)(i => i.ItemId))));
        }
        protected override List <ID> GetReference(Channel entity, Item accountItem)
        {
            var parameters = new List <Parameter> {
                new Parameter()
                {
                    Name = "embedcode", Type = ParameterType.UrlSegment, Value = entity.EmbedCode
                }
            };

            var           context    = new RestContext(Constants.SitecoreRestSharpService, new OoyalaAthenticator(accountItem));
            List <string> embedCodes = context.Read <List <string> >("read_channel_lineup", parameters).Data;

            if (embedCodes == null)
            {
                return(null);
            }

            Expression <Func <VideoSearchResult, bool> > expression = ContentSearchUtil.GetAncestorFilter <VideoSearchResult>(accountItem, TemplateIDs.Video);

            var embedCodesExp = embedCodes.Aggregate(PredicateBuilder.False <VideoSearchResult>(), (current, tmp) => current.Or(i => i.EmbedCode == tmp.Replace('-', ' ')));

            List <VideoSearchResult> searchResults = ContentSearchUtil.FindAll(Constants.IndexName, expression.And(embedCodesExp));

            //fallback
            if (searchResults.Count < embedCodes.Count)
            {
                IItemSynchronizer synchronizer = MediaFrameworkContext.GetItemSynchronizer(typeof(Video));
                if (synchronizer != null)
                {
                    foreach (string embedCode in embedCodes)
                    {
                        if (searchResults.Any(i => i.EmbedCode == embedCode))
                        {
                            continue;
                        }

                        Video video = new Video {
                            EmbedCode = embedCode
                        };
                        var videoIndex = synchronizer.Fallback(video, accountItem) as VideoSearchResult;

                        if (videoIndex != null)
                        {
                            searchResults.Add(videoIndex);
                        }
                    }
                }
            }

            return(searchResults.Select(i => i.ItemId).ToList());
        }
示例#3
0
        protected override List <ID> GetReference(Asset entity, Item accountItem)
        {
            List <Label> labels = this.GetLabels(entity, accountItem);

            if (labels == null)
            {
                return(null);
            }

            if (labels.Count == 0)
            {
                return(new List <ID>(0));
            }

            string[] labelIds = labels.Select(i => i.Id).ToArray();

            var expression = ContentSearchUtil.GetAncestorFilter <LabelSearchResult>(accountItem, TemplateIDs.Label);
            var idExp      = labelIds.Aggregate(PredicateBuilder.False <LabelSearchResult>(), (current, tmp) => current.Or(i => i.Id == tmp));

            List <LabelSearchResult> searchResults = ContentSearchUtil.FindAll(Constants.IndexName, expression.And(idExp));

            //fallback
            if (searchResults.Count < labelIds.Length)
            {
                IItemSynchronizer synchronizer = MediaFrameworkContext.GetItemSynchronizer(typeof(Label));
                if (synchronizer != null)
                {
                    foreach (Label label in labels)
                    {
                        if (searchResults.Any(i => i.Id == label.Id))
                        {
                            continue;
                        }

                        var labelIndex = synchronizer.Fallback(label, accountItem) as LabelSearchResult;
                        if (labelIndex != null)
                        {
                            searchResults.Add(labelIndex);
                        }
                    }
                }
            }

            return(searchResults.Select(i => i.ItemId).ToList());
        }
        protected override List <ID> GetReference(Video entity, Item accountItem)
        {
            if (entity.Tags == null || entity.Tags.Count == 0)
            {
                return(new List <ID>(0));
            }

            var expression = ContentSearchUtil.GetAncestorFilter <TagSearchResult>(accountItem, TemplateIDs.Tag);
            var nameExp    = entity.Tags.Aggregate(PredicateBuilder.False <TagSearchResult>(), (current, tmp) => current.Or(i => i.TagName == tmp));

            List <TagSearchResult> searchResults = ContentSearchUtil.FindAll(Constants.IndexName, expression.And(nameExp));

            //fallback
            if (searchResults.Count < entity.Tags.Count)
            {
                IItemSynchronizer synchronizer = MediaFrameworkContext.GetItemSynchronizer(typeof(Tag));
                if (synchronizer != null)
                {
                    foreach (string tagName in entity.Tags)
                    {
                        if (searchResults.Any(i => i.Name == tagName))
                        {
                            continue;
                        }

                        var tagIndex = synchronizer.Fallback(new Tag {
                            Name = tagName
                        }, accountItem) as TagSearchResult;
                        if (tagIndex != null)
                        {
                            searchResults.Add(tagIndex);
                        }
                    }
                }
            }

            return(searchResults.Select(i => i.ItemId).ToList());
        }
示例#5
0
        protected override List <ID> GetReference(Video entity, Item accountItem)
        {
            if (entity.Snippet == null || entity.Snippet.Tags == null || entity.Snippet.Tags.Count == 0)
            {
                return(new List <ID>());
            }

            var ancestorFilter = ContentSearchUtil.GetAncestorFilter <TagSearchResult>(accountItem, Templates.Tag.TemplateID);
            var expression     = entity.Snippet.Tags.Aggregate(PredicateBuilder.False <TagSearchResult>(), (current, tmp) => current.Or(i => i.TagName == tmp));

            List <TagSearchResult> all = ContentSearchUtil.FindAll(Constants.IndexName, ancestorFilter.And(expression));

            if (all.Count < entity.Snippet.Tags.Count)
            {
                IItemSynchronizer itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(typeof(Tag));
                if (itemSynchronizer != null)
                {
                    foreach (string tag in entity.Snippet.Tags)
                    {
                        string tagName = tag;
                        if (all.All(i => i.Name != tagName))
                        {
                            var tagSearchResult = itemSynchronizer.Fallback(new Tag {
                                Name = tagName
                            }, accountItem) as TagSearchResult;

                            if (tagSearchResult != null)
                            {
                                all.Add(tagSearchResult);
                            }
                        }
                    }
                }
            }

            return(all.Select(i => i.ItemId).ToList());
        }
        protected override List <ID> GetReference(PlayList entity, Item accountItem)
        {
            if (entity.VideoIds == null || entity.VideoIds.Count == 0)
            {
                return(new List <ID>(0));
            }
            Expression <Func <VideoSearchResult, bool> > ancestorFilter = ContentSearchUtil.GetAncestorFilter <VideoSearchResult>(accountItem, TemplateIDs.Video);
            Expression <Func <VideoSearchResult, bool> > second         = Enumerable.Aggregate <string, Expression <Func <VideoSearchResult, bool> > >((IEnumerable <string>)entity.VideoIds, PredicateBuilder.False <VideoSearchResult>(), (Func <Expression <Func <VideoSearchResult, bool> >, string, Expression <Func <VideoSearchResult, bool> > >)((current, tmp) => PredicateBuilder.Or <VideoSearchResult>(current, (Expression <Func <VideoSearchResult, bool> >)(i => i.Id == tmp))));
            List <VideoSearchResult> all = ContentSearchUtil.FindAll <VideoSearchResult>(Configuration.Settings.IndexName, PredicateBuilder.And <VideoSearchResult>(ancestorFilter, second));

            if (all.Count < entity.VideoIds.Count)
            {
                IItemSynchronizer itemSynchronizer1 = MediaFrameworkContext.GetItemSynchronizer(typeof(Video));
                if (itemSynchronizer1 != null)
                {
                    foreach (string str in entity.VideoIds)
                    {
                        string videoId = str;
                        if (!Enumerable.Any <VideoSearchResult>((IEnumerable <VideoSearchResult>)all, (Func <VideoSearchResult, bool>)(i => i.Id == videoId)))
                        {
                            IItemSynchronizer itemSynchronizer2 = itemSynchronizer1;
                            Video             video1            = new Video();
                            video1.Id = videoId;
                            Video             video2            = video1;
                            Item              accountItem1      = accountItem;
                            VideoSearchResult videoSearchResult = itemSynchronizer2.Fallback((object)video2, accountItem1) as VideoSearchResult;
                            if (videoSearchResult != null)
                            {
                                all.Add(videoSearchResult);
                            }
                        }
                    }
                }
            }
            return(Enumerable.ToList <ID>(Enumerable.Select <VideoSearchResult, ID>((IEnumerable <VideoSearchResult>)all, (Func <VideoSearchResult, ID>)(i => i.ItemId))));
        }
示例#7
0
        protected virtual Item GetParentItem(Label label, Item accountItem)
        {
            if (string.IsNullOrEmpty(label.ParentId))
            {
                return(accountItem.Children["Labels"]);
            }

            var expression = ContentSearchUtil.GetAncestorFilter <LabelSearchResult>(accountItem, TemplateIDs.Label);

            expression.And(i => i.Id == label.ParentId);

            LabelSearchResult searchResults = ContentSearchUtil.FindOne(Constants.IndexName, expression.And(i => i.Id == label.ParentId));

            if (searchResults != null)
            {
                Item item = searchResults.GetItem();
                if (item != null)
                {
                    return(item);
                }
            }

            return(accountItem.Axes.SelectSingleItem(string.Format("./Labels//*[@@templateid='{0}' and @Id='{1}']", TemplateIDs.Label, label.ParentId)));
        }
        protected override List <ID> GetReference(Channel entity, Item accountItem)
        {
            var authenticator = new YouTubeAuthenticator(accountItem);
            var context       = new RestSharp.RestContext(Constants.SitecoreRestSharpService, authenticator);
            var parameters    = new List <Parameter>();

            string nextPageToken      = string.Empty;
            var    pageTokenParameter = new Parameter
            {
                Type  = ParameterType.UrlSegment,
                Name  = "pageToken",
                Value = nextPageToken
            };

            parameters.Add(pageTokenParameter);

            var playlistIds = new List <string>();

            do
            {
                pageTokenParameter.Value = nextPageToken;

                IRestResponse <PagedCollection <Playlist> > pagedEntities = context.Read <PagedCollection <Playlist> >(this.RequestName, parameters);
                if (pagedEntities == null || pagedEntities.Data == null || pagedEntities.Data.Items == null)
                {
                    LogHelper.Warn("Null Result during synchronization", this);
                    throw new HttpException("Http null result");
                }

                nextPageToken = (pagedEntities.Data.NextPageToken != null && pagedEntities.Data.NextPageToken != nextPageToken) ? pagedEntities.Data.NextPageToken : string.Empty;
                playlistIds.AddRange(pagedEntities.Data.Items.Select(p => p.UniqueId));
            }while (!string.IsNullOrEmpty(nextPageToken));

            if (!playlistIds.Any())
            {
                return(new List <ID>());
            }

            var ancestorFilter = ContentSearchUtil.GetAncestorFilter <PlaylistSearchResult>(accountItem, Templates.Playlist.TemplateID);
            var expression     = playlistIds.Aggregate(PredicateBuilder.False <PlaylistSearchResult>(), (current, playlistId) => current.Or(i => i.UniqueID == playlistId));

            var all = ContentSearchUtil.FindAll(Constants.IndexName, PredicateBuilder.And(ancestorFilter, expression));

            if (all.Count < playlistIds.Count)
            {
                var itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(typeof(Playlist));
                if (itemSynchronizer != null)
                {
                    foreach (var id in playlistIds)
                    {
                        string playlistId = id;
                        if (all.All(i => i.UniqueID != playlistId))
                        {
                            var playlist = new Playlist
                            {
                                UniqueId = playlistId,
                                Snippet  = new Snippet {
                                    PlaylistId = playlistId
                                }
                            };

                            var playlistSearchResult = itemSynchronizer.Fallback(playlist, accountItem) as PlaylistSearchResult;

                            if (playlistSearchResult != null)
                            {
                                all.Add(playlistSearchResult);
                            }
                        }
                    }
                }
            }

            return(all.Select(i => i.ItemId).ToList());
        }
        protected virtual TSearchResult GetSearchResult <TSearchResult>(string indexName, Item accountItem, Expression <Func <TSearchResult, bool> > selector) where TSearchResult : MediaServiceSearchResult, new()
        {
            Expression <Func <TSearchResult, bool> > predicate = ContentSearchUtil.GetAncestorFilter <TSearchResult>(accountItem);

            return(ContentSearchUtil.FindOne <TSearchResult>(indexName, predicate.And(selector)));
        }
示例#10
0
        public static TSearchResult GetSearchResultForAncesterFilter <TSearchResult>(string indexName, Item ancesterItem, Expression <Func <TSearchResult, bool> > selector) where TSearchResult : MediaServiceSearchResult, new()
        {
            Expression <Func <TSearchResult, bool> > ancestorFilter = ContentSearchUtil.GetAncestorFilter <TSearchResult>(ancesterItem, (List <ID>)null);

            return(ContentSearchUtil.FindOne <TSearchResult>(indexName, PredicateBuilder.And <TSearchResult>(ancestorFilter, selector)));
        }
        protected virtual List <TSearchResult> GetSitecoreData(string indexName, Item accountItem)
        {
            var expression = ContentSearchUtil.GetAncestorFilter <TSearchResult>(accountItem, this.Templates);

            return(ContentSearchUtil.FindAll(indexName, expression));
        }