/// <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)))); }
/// <summary> /// Delete /// </summary> /// <param name="operation"></param> protected override void Delete(ExportOperation operation) { IItemSynchronizer itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (itemSynchronizer == null) { return; } var authenticator = new BrightcoveAuthenticator(operation.AccountItem); new VideoProxy(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()); }
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 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); }
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); }
public virtual object CreateEntity(Item mediaItem, IItemSynchronizer synchronizer = null) { Assert.ArgumentNotNull(mediaItem, "mediaItem"); synchronizer = synchronizer ?? this.GetItemSynchronizer(mediaItem); if (synchronizer == null) { return(null); } object entity = synchronizer.CreateEntity(mediaItem); if (entity == null) { LogHelper.Warn("Entity could not be resolved. MediaItem:" + mediaItem.Uri, this); } return(entity); }
/// <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); } }
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()); }
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.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)))); }