Example #1
0
        public override IEnumerable <object> GetData(Item accountItem)
        {
            base.IdParameterValue   = string.Empty;
            base.MineParameterValue = false;
            base.NoParametersNeeded = false;

            if (accountItem.TemplateID == Templates.AccountPublic.TemplateID)
            {
                string ids = accountItem[Templates.AccountPublic.VideoIDs];
                if (!string.IsNullOrEmpty(ids))
                {
                    string[] idList = ids.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                    base.IdParameterValue = string.Join(",", idList);
                }
            }
            else
            {
                var data = ImportManager.ImportList <SearchResult>("import_youtube_channel_videos", accountItem);
                if (data != null)
                {
                    base.IdParameterValue = string.Join(",", data.Where(d => d.Id != null).Select(d => d.Id.VideoId));
                }
            }

            return(base.GetData(accountItem));
        }
Example #2
0
        public override IEnumerable <object> GetData(Item accountItem)
        {
            this.IdParameterValue   = null;
            base.MineParameterValue = false;
            base.NoParametersNeeded = false;

            if (accountItem.TemplateID == Templates.Account.TemplateID)
            {
                var data = ImportManager.ImportList <SearchResult>("import_youtube_channel_videos", accountItem);
                if (data != null)
                {
                    IdParameterValue = string.Join(",", data.Where(d => d.Id != null).Select(d => d.Id.VideoId));
                }
            }

            return(this.ReadAllTags(base.GetData(accountItem).OfType <Video>()));
        }
        protected override List <TEntity> GetServiceData(Item accountItem)
        {
            if (this.ImportNames.Any())
            {
                var serviceData = new List <TEntity>();

                // revisit and convert to linq
                foreach (var importName in this.ImportNames)
                {
                    var data = ImportManager.ImportList <TEntity>(importName, accountItem);

                    if (data != null)
                    {
                        serviceData.AddRange(data);
                    }
                }

                return(serviceData);
            }

            return(base.GetServiceData(accountItem));
        }
 protected virtual List <TEntity> GetServiceData(Item accountItem)
 {
     return(ImportManager.ImportList <TEntity>(this.ImportName, accountItem));
 }
        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));
                }
            }
        }