public static void HandleDelete(object sender, DeleteContentEventArgs e) { var beingDeleted = new List <ContentReference>(); if (e.ContentLink != null) { beingDeleted.Add(e.ContentLink); } beingDeleted.AddRange(e.DeletedDescendents); foreach (var item in beingDeleted) { var contentMapping = DivvyContentMapping.FindFromEpiserverContent(item.ID); if (contentMapping != null) { DivvyContentMapping.Archive(contentMapping); DivvyLogManager.Log("Deleted Event Raised", new { EpiserverId = item.ID, DivvyId = DivvyContentMapping.FindFromEpiserverContent(item.ID).DivvyId }); var content = repo.Get <IContent>(new ContentReference(item.ID)); NotifyDivvy(content, Settings.DeletedStatusLabel); } } }
public static void Archive(DivvyContentMapping mapping) { mapping.ArchivedOn = DateTime.Now; mapping.Status = ArchivedStatusLabel; var store = GetStore(); store.Save(mapping); }
public static void HandlePublish(object sender, ContentEventArgs e) { var contentMapping = DivvyContentMapping.FindFromEpiserverContent(e.Content.ContentLink.ID); if (contentMapping != null) { DivvyLogManager.Log("Published Event Raised", new { contentMapping.EpiserverContentId, contentMapping.DivvyId }); NotifyDivvy(e.Content, Settings.PublishedStatusLabel); } }
private static void NotifyDivvy(IContent content, string status) { DivvyWebhookManager.Instance.Add(new DivvyWebhook() { Uri = new Uri(Settings.DivvyNotificationEndpoint), Data = new { id = DivvyContentMapping.FindFromEpiserverContent(content.ContentLink.ID).DivvyId, state = status } }); }
private static DivvyContentMapping FindContentMapping(int divvyId) { var divvyContentMapping = DivvyContentMapping.FindFromDivvyContent(divvyId); if (divvyContentMapping == null) { DivvyLogManager.LogRequest("No Existing Content Found"); return(null); } return(divvyContentMapping); }
// Static methods to maintain the mappings public static void Create(int episerverContentId, int divvyId) { var existingMapping = FindFromEpiserverContent(episerverContentId) ?? FindFromDivvyContent(divvyId); if (existingMapping != null) { // There is already a mapping for this return; } var contentMapping = new DivvyContentMapping(episerverContentId, divvyId); GetStore().Save(contentMapping); }
private static IContent CreateContent(ContentRequest contentRequest, DivvyTypeMapping mapping) { // Run the event. The target node might change in here var e = new DivvyEventArgs() { ContentRequest = contentRequest, IntendedParent = mapping.ParentNode, IntendedTypeName = mapping.EpiserverPageTypeName }; OnBeforeContentCreation(null, e); if (e.CancelAction) { return(null); } var parent = repo.Get <PageData>(e.IntendedParent); DivvyLogManager.LogRequest($"Creating New Content", new { Type = e.IntendedTypeName, ParentId = parent.ContentGuid, ParentName = parent.Name }); try { // Get the type ID. For whatever reason, we can't create content with a type name, we have to have the ID... var type = typeRepo.Load(e.IntendedTypeName); // Create the content var content = repo.GetDefault <IContent>(e.IntendedParent, type.ID); content.Name = contentRequest.Title; repo.Save(content, AccessLevel.NoAccess); // There's an edge case where we have a mappng already because the Episerver content got deleted if (!DivvyContentMapping.HasDivvyMapping(content.ContentLink.ID)) { DivvyContentMapping.Create(content.ContentLink.ID, contentRequest.Id); } DivvyLogManager.LogRequest("Created New Content", new { Id = content.ContentGuid }); return(content); } catch (Exception ex) { DivvyLogManager.LogRequest($"Error Creating New Content", ex); return(null); } }
// This is the main method of the class. // This processes the inbound Divvy information. public static ContentResponse ProcessDivvyInput(string input) { // Filter the raw string input = FilterInput(input); if (input == null) { // Explicit abandon return(null); } // Parse the string into an object var contentRequest = ParseContentRequest(input); if (contentRequest == null) { // Explicit abandon return(null); } // Attempt to find the content mapping var contentMapping = FindContentMapping(contentRequest.Id); // Do we have an archived mapping? // This ensures the same content isn't created twice if (contentMapping != null && contentMapping.Status == DivvyContentMapping.ArchivedStatusLabel) { DivvyLogManager.LogRequest("Found Archived Content Mapping", new { contentMapping.EpiserverContentId, contentMapping.ArchivedOn }); return(null); } IContent content; if (contentMapping == null) { // No existing content; attempt to find a mapping var typeMapping = FindTypeMapping(contentRequest.ContentType); if (typeMapping == null) { // No existing content and no mapping for new content // We're done here... return(null); } // We found a mapping, create new content content = CreateContent(contentRequest, typeMapping); if (content == null) { // Content was short-circuited in an event handler return(null); } } else { // We found a mapping. Retrieve the content var repo = ServiceLocator.Current.GetInstance <IContentRepository>(); content = repo.Get <IContent>(new ContentReference(contentMapping.EpiserverContentId)); if (content == null) { // For some reason, this content doesn't exist // Archive the mapping DivvyLogManager.LogRequest("Unable to Find Mapped Content", new { EpiserverID = contentMapping.EpiserverContentId }); DivvyContentMapping.Archive(contentMapping); return(null); } DivvyLogManager.LogRequest($"Found Episerver Content", new { Id = content.ContentGuid }); } // If we get to this point, we should have content, one way or the other -- either found or created // Get and filter the HTML we're sending back for a preview var previewHtml = Settings.PreviewProvider(content); previewHtml = FilterPreviewHtml(previewHtml); // Get the URL for the content in Edit Mode var editUrl = GetEditUrl(content); // Get the calculated last modified date var lastModified = GetLastModifiedDate(content); return(new ContentResponse() { Id = content.ContentGuid, PreviewHtml = previewHtml, EditUrl = editUrl, LastModified = lastModified, Media = GetMedia(content).Select(m => new Media() { Name = m.Name, Url = resolver.GetUrl(m) }).ToList() }); }
public static void Save(DivvyContentMapping mapping) { GetStore().Save(mapping); }