protected override void Delete(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

            if (synchronizer == null)
            {
                return;
            }

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

            var parameters = new Dictionary <string, object>
            {
                { "playlist_id", playlist.Id },
                { "cascade", "true" },
            };

            var authenticator = new BrightcoveAthenticator(operation.AccountItem);

            var updateData = new PostData("delete_playlist", authenticator, parameters);

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

            context.Delete <PostData, ResultData <PlayList> >("update_data", updateData);
        }
Exemple #2
0
        /// <summary>
        /// Deletes a label.
        /// </summary>
        /// <param name="operation">
        /// The operation.
        /// </param>
        protected override void Delete(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

            if (synchronizer == null)
            {
                return;
            }

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

            var label = (Label)synchronizer.CreateEntity(operation.Item);

            context.Delete <Label, RestEmptyType>(
                "delete_label",
                parameters:
                new List <Parameter>
            {
                new Parameter
                {
                    Type  = ParameterType.UrlSegment,
                    Name  = "id",
                    Value = label.Id
                }
            });
        }
Exemple #3
0
        protected override void Delete(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

            if (synchronizer == null)
            {
                return;
            }

            var video = (Video)synchronizer.CreateEntity(operation.Item);

            var inactivatedVideo = new Video
            {
                Id        = video.Id,
                ItemState = ItemState.INACTIVE
            };

            var authenticator = new BrightcoveAthenticator(operation.AccountItem);

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

            var updateData = new PostData("update_video", authenticator, "video", inactivatedVideo);

            var data = context.Update <PostData, ResultData <Video> >("update_data", updateData).Data;
        }
Exemple #4
0
        /// <summary>
        /// Update a label.
        /// </summary>
        /// <param name="operation">
        /// The operation.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        protected override object Update(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

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

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

            var lab = (Label)synchronizer.CreateEntity(operation.Item);

            return(context.Update <Label, Label>(
                       "update_label",
                       new Label {
                Name = lab.Name, ParentId = !string.IsNullOrEmpty(lab.ParentId) ? lab.ParentId : "root"
            },
                       new List <Parameter>
            {
                new Parameter
                {
                    Type = ParameterType.UrlSegment,
                    Name = "id",
                    Value = lab.Id
                }
            }).Data);
        }
        /// <summary>
        /// Updates a player.
        /// </summary>
        /// <param name="operation">
        /// The operation.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        protected override object Update(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

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

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

            var player = (Player)synchronizer.CreateEntity(operation.Item);

            string playerId = player.Id;

            player.Id = null;

            return(context.Update <Player, Player>(
                       "update_player",
                       player,
                       new List <Parameter>
            {
                new Parameter
                {
                    Type = ParameterType.UrlSegment,
                    Name = "id",
                    Value = playerId
                }
            }).Data);
        }
Exemple #6
0
        protected override object Update(ExportOperation operation)
        {
            var itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

            if (itemSynchronizer == null)
            {
                return(null);
            }
            var playList = (PlayList)itemSynchronizer.CreateEntity(operation.Item);

            playList.ReferenceId = null;
            //Video ids used only for EXPLICIT playlist.
            //In other case will be used playlistsearch
            if (playList.PlaylistType == PlaylistType.EXPLICIT.ToString())
            {
                playList.PlayListSearch = null;
            }
            else
            {
                playList.VideoIds = null;
            }
            var authenticator = new BrightcoveAuthenticator(operation.AccountItem);
            var data          = new PlaylistProxy(authenticator).Patch(playList);

            if (data == null)
            {
                return(null);
            }
            return(data);
        }
Exemple #7
0
        /// <summary>
        /// Deletes a video.
        /// </summary>
        /// <param name="operation">
        /// The operation.
        /// </param>
        protected override void Delete(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

            if (synchronizer == null)
            {
                return;
            }

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

            var video = (Video)synchronizer.CreateEntity(operation.Item);

            context.Delete <Video, RestEmptyType>(
                "delete_video",
                parameters:
                new List <Parameter>
            {
                new Parameter
                {
                    Name  = "embedcode",
                    Type  = ParameterType.UrlSegment,
                    Value = video.EmbedCode
                }
            });
        }
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="operation"></param>
        /// <returns></returns>
        protected override object Update(ExportOperation operation)
        {
            IItemSynchronizer itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

            if (itemSynchronizer == null)
            {
                return(null);
            }
            var video = (Video)itemSynchronizer.CreateEntity(operation.Item);

            if (video.CustomFields != null && video.CustomFields.Count == 0)
            {
                video.CustomFields = null;
            }
            var authenticator = new BrightcoveAuthenticator(operation.AccountItem);
            var result        = new VideoProxy(authenticator).Patch(video);

            if (result == null || result.Id == null)
            {
                return(null);
            }
            if (result.CustomFields == null)
            {
                result.CustomFields = video.CustomFields;
            }
            return(result);
        }
        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))));
        }
Exemple #10
0
        /// <summary>
        /// Creates a channel.
        /// </summary>
        /// <param name="operation">
        /// The operation.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        protected override object Create(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

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

            var authenticator = new OoyalaAthenticator(operation.AccountItem);

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

            var channel = (Channel)synchronizer.CreateEntity(operation.Item);

            channel.EmbedCode            = null;
            channel.CreatedAt            = null;
            channel.UpdatedAt            = null;
            channel.Duration             = null;
            channel.PostProcessingStatus = null;
            channel.Metadata             = null;
            channel.PreviewImageUrl      = null;
            channel.Status = null;

            var createdChannel = context.Create <Channel, Channel>("create_channel", channel).Data;

            this.UpdateLineup(operation, createdChannel.EmbedCode);
            this.UpdateLabels(operation, createdChannel.EmbedCode);
            this.UpdatePlayer(operation, createdChannel.EmbedCode);
            this.UpdateMetadata(operation, createdChannel.EmbedCode);

            return(createdChannel);
        }
        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);
        }
        public void MigrateItem(Item item)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(item);

            if (synchronizer != null)
            {
                this.Helper.RecreateItem(item, true);
            }
        }
        public virtual IItemSynchronizer GetItemSynchronizer(Item mediaItem)
        {
            Assert.ArgumentNotNull(mediaItem, "mediaItem");

            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(mediaItem);

            if (synchronizer == null)
            {
                LogHelper.Warn("Item synchronizer could not be resolved. MediaItem:" + mediaItem.Uri, this);
            }
            return(synchronizer);
        }
Exemple #14
0
        protected override void Delete(ExportOperation operation)
        {
            var itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

            if (itemSynchronizer == null)
            {
                return;
            }
            var authenticator = new BrightcoveAuthenticator(operation.AccountItem);

            new PlaylistProxy(authenticator).Delete(((Asset)itemSynchronizer.CreateEntity(operation.Item)).Id);
        }
        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());
        }
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="operation"></param>
        /// <returns></returns>
        protected override object Update(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

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

            var video = (Video)synchronizer.CreateEntity(operation.Item);

            video.ThumbnailUrl      = null;
            video.CreationDate      = null;
            video.VideoStillURL     = null;
            video.PublishedDate     = null;
            video.PlaysTrailingWeek = null;
            video.PlaysTotal        = null;
            video.LastModifiedDate  = null;
            video.Length            = null;

            if (video.CustomFields != null && video.CustomFields.Count == 0)
            {
                video.CustomFields = null;
            }

            var authenticator = new BrightcoveAthenticator(operation.AccountItem);

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

            var updateData = new PostData("update_video", authenticator, "video", video);

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

            if (data != null && data.Result != null)
            {
                if (data.Result.CustomFields == null)
                {
                    data.Result.CustomFields = video.CustomFields;
                }

                return(data.Result);
            }

            return(null);
        }
Exemple #17
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());
        }
Exemple #18
0
        protected virtual Item SyncEntity(object entity, Item accountItem)
        {
            try
            {
                IItemSynchronizer synchronizer = MediaFrameworkContext.GetItemSynchronizer(entity);
                if (synchronizer != null)
                {
                    return(synchronizer.SyncItem(entity, accountItem));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("Sync failed. Entity:" + entity, this, ex);
                return(null);
            }

            return(null);
        }
Exemple #19
0
        protected override void Delete(ExportOperation operation)
        {
            IItemSynchronizer itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

            if (itemSynchronizer == null)
            {
                return;
            }
            var video1 = (Video)itemSynchronizer.CreateEntity(operation.Item);
            var video2 = new Video();

            video2.Id        = video1.Id;
            video2.ItemState = ItemState.INACTIVE;
            Video video3        = video2;
            var   authenticator = new BrightcoveAuthenticator(operation.AccountItem);

            new VideoProxy(authenticator).Patch(video3);
        }
Exemple #20
0
        /// <summary>
        /// Updates a video.
        /// </summary>
        /// <param name="operation">
        /// The operation.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        protected override object Update(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

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

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

            var video = (Video)synchronizer.CreateEntity(operation.Item);

            string embedCode = video.EmbedCode;

            video.EmbedCode            = null;
            video.CreatedAt            = null;
            video.UpdatedAt            = null;
            video.Duration             = null;
            video.PostProcessingStatus = null;
            video.PreviewImageUrl      = null;
            video.Status           = null;
            video.AssetType        = null;
            video.Metadata         = null;
            video.OriginalFileName = null;

            this.UpdateLabels(operation, embedCode);
            this.UpdatePlayer(operation, embedCode);
            this.UpdateMetadata(operation, embedCode);

            return(context.Update <Video, Video>(
                       "update_video",
                       video,
                       new List <Parameter>
            {
                new Parameter
                {
                    Type = ParameterType.UrlSegment,
                    Name = "embedcode",
                    Value = embedCode
                }
            }).Data);
        }
        /// <summary>
        /// Updates media item on the Sitecore after update on service side.
        /// </summary>
        protected virtual void UpdateOnSitecore(ExportOperation operation, object entity)
        {
            IItemSynchronizer sync = MediaFrameworkContext.GetItemSynchronizer(entity);

            if (sync != null)
            {
                var args = new MediaSyncItemImportArgs
                {
                    Entity            = entity,
                    Item              = operation.Item,
                    AccountItem       = operation.AccountItem,
                    Synchronizer      = sync,
                    SyncAllowActivity = SyncAllowActivity.UpdateItem | SyncAllowActivity.SyncReferences
                };
                MediaSyncItemImportPipeline.Run(args);

                //sync.UpdateItem(entity, operation.AccountItem, operation.Item);
                //sync.SyncReferences(entity, operation.AccountItem, operation.Item);
            }
        }
        /// <summary>
        /// Creates a player.
        /// </summary>
        /// <param name="operation">
        /// The operation.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        protected override object Create(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

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

            var authenticator = new OoyalaAthenticator(operation.AccountItem);

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

            var player = (Player)synchronizer.CreateEntity(operation.Item);

            player.Id        = null;
            player.IsDefault = false;

            return(context.Create <Player, Player>("create_player", player).Data);
        }
        protected virtual IEnumerable <Item> GetFoldersContent(IEnumerable <Item> folders)
        {
            Assert.ArgumentNotNull(folders, "folders");

            foreach (Item folder in folders)
            {
                if (folder == null)
                {
                    continue;
                }

                foreach (Item item in folder.GetDescendants())
                {
                    var synchronizer = MediaFrameworkContext.GetItemSynchronizer(item);

                    if (synchronizer != null)
                    {
                        yield return(item);
                    }
                }
            }
        }
Exemple #24
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 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());
        }
Exemple #26
0
        /// <summary>
        /// Creates a label.
        /// </summary>
        /// <param name="operation">
        /// The operation.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        protected override object Create(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

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

            var authenticator = new OoyalaAthenticator(operation.AccountItem);

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

            var label = (Label)synchronizer.CreateEntity(operation.Item);

            return(context.Create <Label, Label>(
                       "create_label",
                       new Label
            {
                Name = label.Name,
                ParentId = !string.IsNullOrEmpty(label.ParentId) ? label.ParentId : "root"
            }).Data);
        }
Exemple #27
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 object Update(ExportOperation operation)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item);

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

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

            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("update_playlist", authenticator, "playlist", playlist);

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

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

            return(data != null ? data.Result : null);
        }
        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))));
        }
        protected virtual Item SyncItem(object entity, Item accountItem)
        {
            var synchronizer = MediaFrameworkContext.GetItemSynchronizer(entity);

            return(synchronizer != null?synchronizer.SyncItem(entity, accountItem) : null);
        }