/// <summary> /// Event handler for content service saved event /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void ContentServiceOnSaved(IContentService sender, ContentSavedEventArgs e) { foreach (var contentItem in e.SavedEntities) { this.entityParsingService.ParseContent(contentItem); } }
private void ContentService_Saved(IContentService sender, ContentSavedEventArgs e) { foreach (var content in e.SavedEntities // Check if the content item type has a specific alias .Where(c => c.ContentType.Alias.InvariantEquals("Product"))) { // Do something if the content is using the MyContentType doctype this._logger.Info <MyPublishEventComponent>("{content} has been saved and event fired!", content.Name); // message template stored with the value of content.Name as a part of message template, not useful this._logger.Info <MyPublishEventComponent>($"{content.Name} has been saved and event fired"); } }
private void ContentService_Saved(IContentService sender, ContentSavedEventArgs e) { foreach (var node in e.SavedEntities) { if (NodeHasPcFolder(node.Id)) { continue; } if (IsValidContentTypeAlias(node.ContentType.Alias)) { var pageComponentsFolder = _services.ContentService.CreateContent("Page Components", node.GetUdi(), "pcFolder"); _services.ContentService.Save(pageComponentsFolder); } } }
private void ContentServiceOnSaved(IContentService sender, ContentSavedEventArgs e) { var playlistEntities = e.SavedEntities.Where(ent => ent.ContentType.Alias.InvariantEquals(YoutubePlaylistConstants.ContentTypeAlias)); foreach (var youtubePlaylist in playlistEntities) { var youtubePlaylistId = youtubePlaylist.GetValue <string>(YoutubePlaylistConstants.YoutubePlaylistIdNodeName); if (string.IsNullOrEmpty(youtubePlaylistId)) { return; } _youtubePlaylistContentImporter.Import(youtubePlaylist.Id, youtubePlaylistId); } }
private void ContentService_Saved(IContentService sender, ContentSavedEventArgs e) { foreach (var node in e.SavedEntities) { if (node.ContentType.Alias == USNConstants.HomePageAlias || node.ContentType.Alias == USNConstants.PageAlias || node.ContentType.Alias == USNConstants.BlogPostAlias) { IContent pageComponentsNode = CreatePageComponentsFolder(node, false); if (pageComponentsNode != null) { _contentService.Save(pageComponentsNode); } } if (node.ContentType.Alias == USNConstants.BlogPostAlias) { MoveBlogPostToCorrectFolder(node, e); } } }
private static void OnContentChanged(object sender, ContentSavedEventArgs <TChangeInfo> e) { if (e.ChangeInfo.ScheduleInfoChanged || e.ChangeInfo.WholeScheduleChanged) { ScheduleInfoChanged?.Invoke(null, EventArgs.Empty); } if (e.SavingReason != ContentSavingReason.ScheduleChanged) { ScheduleSaving?.Invoke(null, new ScheduleSavingEventArgs()); } if (e.SavingReason == ContentSavingReason.TabChanged || e.SavingReason == ContentSavingReason.ScheduleChanged || e.SavingReason == ContentSavingReason.ScheduleSaved) { foreach (var destinationEditorId in _controller.EditorRelations.Where(l => e.Source.Contains(l.Target)).SelectMany(l => l.Destrination)) { var destinationEditor = _controller.ContentControls.OfType <IContentEditControl <TChangeInfo> >().FirstOrDefault(editor => editor.Identifier == destinationEditorId); destinationEditor?.OnRelatedContentChanged(e.ChangeInfo); } } }
private void MoveBlogPostToCorrectFolder(IContent node, ContentSavedEventArgs e) { int monthID = -1; IContent parentNode = _contentService.GetById(node.ParentId); DateTime postDate = DateTime.Parse(node.GetValue(USNConstants.BlogPostDateFieldAlias).ToString()); //Check if post already in month folder if (parentNode.ContentType.Alias == USNConstants.BlogMonthFolderAlias) { IContent yearNode = _contentService.GetById(parentNode.ParentId); if (parentNode.GetValue <int>(USNConstants.BlogMonthFieldAlias) != postDate.Month || yearNode.GetValue <int>(USNConstants.BlogYearFieldAlias) != postDate.Year) { IContent blogPostFolder = _contentService.GetById(yearNode.ParentId); monthID = GetMonthNodeForBlogItem(blogPostFolder, postDate); } } else if (parentNode.ContentType.Alias == USNConstants.BlogPostsFolderAlias) { monthID = GetMonthNodeForBlogItem(parentNode, postDate); } else if (parentNode.ContentType.Alias == USNConstants.BlogLandingPageAlias) { var filter = _sqlContent.Query <IContent>().Where(x => x.Name == "Posts"); long totalChildren; var blogPostsFolder = _contentService.GetPagedChildren(parentNode.Id, 0, 1, out totalChildren, filter: filter).FirstOrDefault(); if (blogPostsFolder != null) { monthID = GetMonthNodeForBlogItem(blogPostsFolder, postDate); } } if (monthID != -1) { _contentService.Move(node, monthID); } }
private static void ContentService_Saved(IContentService contentService, ContentSavedEventArgs e) { foreach (IContent content in e.SavedEntities) { List <string> editors = new List <string> { Umbraco.Core.Constants.PropertyEditors.Aliases.Grid, BentoItemDataEditor.EditorAlias, BentoStackDataEditor.EditorAlias }; foreach (Property contentProperty in content.Properties.Where(x => editors.Contains(x.PropertyType.PropertyEditorAlias))) { IDataType editor = DataTypeService.GetDataType(contentProperty.PropertyType.DataTypeId); IRelationType bentoBlocksRelationType = RelationService.GetRelationTypeByAlias(RelationTypes.BentoItemsAlias); if (bentoBlocksRelationType == null) { RelationType relationType = new RelationType( RelationTypes.BentoItemsAlias, RelationTypes.BentoItemsName, true, UmbracoObjectTypes.Document.GetGuid(), UmbracoObjectTypes.Document.GetGuid()); RelationService.Save(relationType); bentoBlocksRelationType = RelationService.GetRelationTypeByAlias(RelationTypes.BentoItemsAlias); } //todo: this does work but it's a bit brute force... //i guess we could store the current relationships and then store the ones we're creating and compare them and then //delete the ones from the old list that arent in the new list? but that's a lot of db hits... IEnumerable <IRelation> rels = RelationService.GetByParentId(content.Id); foreach (IRelation currentRelation in rels.Where(x => x.RelationType.Id == bentoBlocksRelationType.Id)) { RelationService.Delete(currentRelation); } if (contentProperty.PropertyType.PropertyEditorAlias == BentoItemDataEditor.EditorAlias) { foreach (Property.PropertyValue value in contentProperty.Values) { if (value.PublishedValue == null) { break; } var area = JsonConvert.DeserializeObject <Area>(value.PublishedValue.ToString()); if (area.Id <= 0) { continue; } var bentoContent = contentService.GetById(area.Id); if (bentoContent == null) { continue; } BentoItemConfiguration config = (BentoItemConfiguration)editor.Configuration; ProcessRelationship(contentService, bentoContent, content, bentoBlocksRelationType, config.ItemDoctypeCompositionAlias); } } else { foreach (Property.PropertyValue value in contentProperty.Values) { if (value.PublishedValue == null) { break; } string valueString = value.PublishedValue?.ToString(); if (string.IsNullOrWhiteSpace(valueString)) { continue; } IEnumerable <StackItem> items = JsonConvert.DeserializeObject <IEnumerable <StackItem> >(valueString, new StackItemConverter()); var itemList = items.Where(x => x.Areas != null && x.Areas.Any()) .SelectMany(stackItem => stackItem.Areas.Where(x => x.Id > 0), (stackItem, x) => contentService.GetById(x.Id)) .Where(bentoContent => bentoContent != null) .Distinct(); BentoStackConfiguration config = (BentoStackConfiguration)editor.Configuration; foreach (IContent item in itemList) { ProcessRelationship(contentService, item, content, bentoBlocksRelationType, config.ItemDoctypeCompositionAlias); } } } } } }
protected virtual void OnContentChanged(ContentSavedEventArgs <TChangeInfo> e) { var handler = ContentChanged; handler?.Invoke(this, e); }