protected override object Create(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

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

            var playlist = (PlayList)synchronizer.CreateEntity(operation.Item);

            playlist.Id           = null;
            playlist.ReferenceId  = null;
            playlist.ThumbnailUrl = null;

            //Video ids used only for EXPLICIT playlist.
            //In other case will be used filter tags & tag inclusion
            if (playlist.PlaylistType == PlaylistType.EXPLICIT.ToString())
            {
                playlist.FilterTags   = null;
                playlist.TagInclusion = null;
            }
            else
            {
                playlist.VideoIds = null;
            }

            var authenticator = new BrightcoveAthenticator(operation.AccountItem);

            var updateData = new PostData("create_playlist", authenticator, "playlist", playlist);

            var context = new RestContext(Constants.SitecoreRestSharpService, authenticator);

            var data = context.Create <PostData, ResultData <string> >("update_data", updateData).Data;


            if (data != null && !string.IsNullOrEmpty(data.Result))
            {
                //we could not to use existing playlist object because it does not contain all data
                var playlistData = context.Read <PlayList>("read_playlist_by_id",
                                                           new List <Parameter>
                {
                    new Parameter {
                        Type = ParameterType.UrlSegment, Name = "playlist_id", Value = data.Result
                    }
                }).Data;

                if (playlistData == null)
                {
                    playlist.Id = data.Result;
                    return(playlist);
                }

                return(playlistData);
            }

            return(null);
        }
        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());
        }
Beispiel #3
0
        protected virtual List <string> GetUploadingUrls(Item accountItem, Video video)
        {
            var authenticator = new OoyalaAthenticator(accountItem);
            var context       = new RestContext(Constants.SitecoreRestSharpService, authenticator);

            return(context.Read <List <string> >(
                       "get_uploading_URLs",
                       new List <Parameter>
            {
                new Parameter
                {
                    Type = ParameterType.UrlSegment,
                    Name = "embedcode",
                    Value = video.EmbedCode
                }
            }).Data);
        }
Beispiel #4
0
        protected virtual IEnumerable <object> GetWithPaging(IAuthenticator authenticator)
        {
            var context = new RestContext(Constants.SitecoreRestSharpService, authenticator);

            string nextPage = null;

            var parameters = new List <Parameter>();

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

            parameters.Add(pageToken);

            string requestName = this.RequestName;

            do
            {
                if (!string.IsNullOrEmpty(nextPage))
                {
                    NameValueCollection qscoll = HttpUtility.ParseQueryString(nextPage.Split('?')[1]);
                    pageToken.Value = string.Format(qscoll["page_token"].UrlDecode().UrlEncode());
                }
                else
                {
                    pageToken.Value = string.Empty;
                }

                var temp = context.Read <PagedCollection <TEntity> >(requestName, parameters);

                if (temp == null || temp.Data == null || temp.Data.Items == null)
                {
                    LogHelper.Warn("Null Result during importing", this);

                    throw new HttpException("Http null result");
                }

                nextPage = temp.Data.NextPage != nextPage ? temp.Data.NextPage : null;

                foreach (TEntity entity in temp.Data.Items)
                {
                    yield return(entity);
                }
            }while (!string.IsNullOrEmpty(nextPage));
        }
Beispiel #5
0
        protected virtual IEnumerable <object> GetWithPaging(IAuthenticator authenticator)
        {
            var context = new RestContext(Constants.SitecoreRestSharpService, authenticator);

            var parameters = new List <Parameter>();

            var pageNumber = new Parameter {
                Type = ParameterType.UrlSegment, Name = "page_number", Value = -1
            };

            parameters.Add(pageNumber);

            int totalCount;
            int count = 0;

            do
            {
                pageNumber.Value = (int)pageNumber.Value + 1;

                var temp = context.Read <PagedCollection <TEntity> >(this.RequestName, parameters);

                if (temp == null || temp.Data == null || temp.Data.Items == null)
                {
                    LogHelper.Warn("Null Result during importing", this);

                    throw new HttpException("Http null result");
                }

                totalCount = temp.Data.TotalCount;

                if (temp.Data.Items.Count == 0)
                {
                    yield break;
                }

                foreach (TEntity entity in temp.Data.Items)
                {
                    yield return(entity);
                }

                count += temp.Data.Items.Count;
            }while (count < totalCount);
        }
Beispiel #6
0
        protected virtual List <Label> GetLabels(Asset asset, Item accountItem)
        {
            if (asset.Labels != null)
            {
                return(asset.Labels);
            }

            var parameters = new List <Parameter> {
                new Parameter()
                {
                    Name = "embedcode", Type = ParameterType.UrlSegment, Value = asset.EmbedCode
                }
            };

            var context = new RestContext(Constants.SitecoreRestSharpService, new OoyalaAthenticator(accountItem));
            PagedCollection <Label> collection = context.Read <PagedCollection <Label> >("read_asset_labels", parameters).Data;

            return(collection != null ? collection.Items : null);
        }
Beispiel #7
0
        protected override List <ID> GetReference(Asset 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));

            var referencedPlayer = context.Read <ReferencedPlayer>("read_asset_player", parameters).Data;

            if (referencedPlayer == null)
            {
                return(new List <ID>(0));
            }

            var playerIndex = ContentSearchUtil.FindOne <PlayerSearchResult>(Constants.IndexName,
                                                                             i => i.Paths.Contains(accountItem.ID) && i.TemplateId == TemplateIDs.Player && i.Id == referencedPlayer.ID);

            if (playerIndex == null)
            {
                IItemSynchronizer synchronizer = MediaFrameworkContext.GetItemSynchronizer(typeof(Player));
                if (synchronizer != null)
                {
                    Player player = new Player {
                        Id = referencedPlayer.ID
                    };

                    playerIndex = synchronizer.Fallback(player, accountItem) as PlayerSearchResult;
                }
            }

            return(playerIndex != null ? new List <ID> {
                playerIndex.ItemId
            } : new List <ID>(0));
        }
        protected override string GetReference(Asset entity, Item accountItem)
        {
            Dictionary <string, string> medatadata;

            if (entity.Metadata != null)
            {
                medatadata = entity.Metadata;
            }
            else
            {
                var parameters = new List <Parameter> {
                    new Parameter {
                        Name = "embedcode", Type = ParameterType.UrlSegment, Value = entity.EmbedCode
                    }
                };

                var context = new RestContext(Constants.SitecoreRestSharpService, new OoyalaAthenticator(accountItem));

                medatadata = context.Read <Dictionary <string, string> >("read_asset_metadata", parameters).Data;
            }

            return(medatadata != null?StringUtil.DictionaryToString(entity.Metadata, '=', '&') : null);
        }