public virtual IEnumerable <object> GetData(Item accountItem)
        {
            var authenticator = new YouTubeAuthenticator(accountItem);
            var context       = new Sitecore.RestSharp.RestContext(Constants.SitecoreRestSharpService, authenticator);
            var parameters    = new List <Parameter>();

            if (!string.IsNullOrEmpty(this.IdParameterValue))
            {
                var idParameter = new Parameter
                {
                    Type  = ParameterType.UrlSegment,
                    Name  = "id",
                    Value = this.IdParameterValue
                };

                parameters.Add(idParameter);
            }

            if (this.MineParameterValue)
            {
                var mineParameter = new Parameter
                {
                    Type  = ParameterType.UrlSegment,
                    Name  = "mine",
                    Value = this.MineParameterValue
                };

                parameters.Add(mineParameter);
            }

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

            parameters.Add(pageTokenParameter);

            if (!string.IsNullOrEmpty(this.IdParameterValue) || this.MineParameterValue || this.NoParametersNeeded)
            {
                do
                {
                    pageTokenParameter.Value = nextPageToken;

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

                    nextPageToken = (pagedEntities.Data.NextPageToken != null && pagedEntities.Data.NextPageToken != nextPageToken) ? pagedEntities.Data.NextPageToken : string.Empty;
                    foreach (TEntity entity in pagedEntities.Data.Items)
                    {
                        yield return(entity);
                    }
                } while (!string.IsNullOrEmpty(nextPageToken));
            }
        }
        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());
        }
        public IEnumerable <object> GetData(Item accountItem)
        {
            string[] idList = { };

            if (accountItem.TemplateID == Templates.AccountPublic.TemplateID)
            {
                string ids = accountItem[Templates.AccountPublic.PlaylistIDs];
                if (!string.IsNullOrEmpty(ids))
                {
                    idList = ids.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                }
            }
            else
            {
                var data = ImportManager.ImportList <Playlist>("import_youtube_playlists", accountItem);
                if (data != null)
                {
                    idList = data.Select(d => d.UniqueId).ToArray();
                }
            }

            var authenticator = new YouTubeAuthenticator(accountItem);
            var context       = new RestSharp.RestContext(Constants.SitecoreRestSharpService, authenticator);
            var parameters    = new List <Parameter>();

            var playlistIdParameter = new Parameter
            {
                Type = ParameterType.UrlSegment,
                Name = "playlistId"
            };

            parameters.Add(playlistIdParameter);

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

            parameters.Add(pageTokenParameter);

            foreach (string id in idList)
            {
                {
                    playlistIdParameter.Value = id;

                    do
                    {
                        pageTokenParameter.Value = nextPageToken;

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

                        nextPageToken = (pagedEntities.Data.NextPageToken != null && pagedEntities.Data.NextPageToken != nextPageToken) ? pagedEntities.Data.NextPageToken : string.Empty;
                        foreach (PlaylistItem entity in pagedEntities.Data.Items)
                        {
                            yield return(entity);
                        }
                    }while (!string.IsNullOrEmpty(nextPageToken));
                }
            }
        }