private static IList <ContentReference> GenerateRelatedPages() { IList <ContentReference> references = new List <ContentReference>(); var serviceLandingPage = ContentShortcuts.GetServiceLandingPageReference(); var services = serviceLandingPage.GetChildren().Select(x => x as ServicePage).ToList(); if (!serviceLandingPage.IsNullOrEmpty()) { while (_xmlReader.ReadAndCount() && !_xmlReader.IsEndOfElementSection("services")) { var title = _xmlReader.GetAttribute("title"); if (_xmlReader.Name == "service" && title != null) { var service = services.Find(x => x.Name.ToLower().Contains(title.ToLower())); if (service != null) { ContentReference reference = service.ContentLink; if (reference != null) { references.Add(reference); } } } } } return(references); }
/// <summary> /// Creates or updates an existing with page with data from a hardcoded XML-file. /// </summary> /// <returns></returns> public static string JobHandler() { var pagesChangedCount = 0; while (_xmlReader.ReadAndCount()) { if (_xmlReader.IsStartElement("case")) { pagesChangedCount++; var id = _xmlReader.GetAttribute("id"); var title = _xmlReader.GetAttribute("title"); var longTitle = _xmlReader.GetAttribute("longtitle"); var imageUrl = _xmlReader.GetAttribute("image"); var workLanding = ContentShortcuts.GetWorkLandingPageReference() ?? ContentReference.StartPage; var currPage = workLanding.ToPageReference().GetOrCreatePageWithName <WorkPage>(title); if (currPage != null) { _repo.SaveAndPublish(currPage); } _rootReference = currPage.ContentLink; if (!longTitle.IsNullOrEmpty()) { currPage.IntroSection.Header = longTitle; } if (imageUrl != null) { var imgBlock = BlockHelper.CreateImageBlock(_rootReference, imageUrl, $"{id}-header-image"); if (imgBlock != null) { currPage.Image = imgBlock; } } currPage.MainContentArea = new ContentArea(); while (_xmlReader.ReadAndCount() && !_xmlReader.IsEndOfElementSection("case")) { switch (_xmlReader.Name) { case "tagline": var tagLine = _xmlReader.ReadShallowElementAndCount("tagline"); if (!tagLine.IsNullOrEmpty()) { currPage.TeaserDescription = new XhtmlString(tagLine); } break; case "description": var description = _xmlReader.ReadShallowElementAndCount("description"); if (!description.IsNullOrEmpty()) { currPage.IntroSection.Preamble = new XhtmlString(description); } break; case "sections": currPage = AddSections(currPage); break; case "services": currPage = AddServices(currPage); break; } } _repo.SaveAndPublish(currPage); } } return($"Creatd or updated ${pagesChangedCount} pages"); }