public void Map(NewsItemPage newsItemPage, NewsItem item, DateTime publishDate) { newsItemPage.PageName = item.Title; newsItemPage.ListHeading = item.LinkTitle; newsItemPage.Headline = item.Title; newsItemPage.Preamble = item.Introduction; if (item.MetaData.CreatedDateMilliseconds > 0) { newsItemPage.Created = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) .AddMilliseconds(item.MetaData.CreatedDateMilliseconds); } if (item.MetaData.ModifiedDateMilliseconds > 0) { newsItemPage.Saved = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) .AddMilliseconds(item.MetaData.ModifiedDateMilliseconds); } /* DATES */ newsItemPage.StartPublish = publishDate; if (item.ClosingDate != DateTime.MinValue) { newsItemPage.StopPublish = item.ClosingDate; } /* END DATES */ // Need to save before setting MainBody (ContentFolder needs to be created) ContentRepository.Save(newsItemPage, SaveAction.Save, AccessLevel.NoAccess); // Prepend domain to relative urls var mainBody = item.Text.Replace("href=\"/", "href=\"//www.ericsson.com/"); // Download, upload, save media to page, and replace markup in MainBody newsItemPage.MainBody = new XhtmlString(GetMainBodyWithMediaAndLinks(mainBody, newsItemPage)); /* Media items */ foreach (var media in item.MediaItems) { var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(media.Html); /* Images */ var imageNodes = htmlDoc.DocumentNode.Descendants().Where(n => n.Name.StartsWith("macro:image")); if (imageNodes.Any()) { newsItemPage.Image3 = ImportExternalImage(imageNodes.First(), newsItemPage); } /* Videos */ var videoNodes = htmlDoc.DocumentNode.Descendants() .Where(n => n.Name.StartsWith("macro:video") || n.Name.StartsWith("macro:kaltura-video")); if (videoNodes.Any()) { var videoId = "not found"; if (videoNodes.First().Attributes["entry-id"] != null) { videoId = videoNodes.First().Attributes["entry-id"].Value; } else if (videoNodes.First().Attributes["video-path"] != null) { videoId = videoNodes.First().Attributes["video-path"].Value; } var missingText = "<h3 style=\"color: red;\">MISSING VIDEO. Id/path: " + videoId + "</h3>"; var currentMainBody = newsItemPage.MainBody != null?newsItemPage.MainBody.ToHtmlString() : string.Empty; newsItemPage.MainBody = new XhtmlString(missingText + currentMainBody); } } newsItemPage.ImportedTagList = item.TagListString; newsItemPage.ImportedCategories = item.Categories != null && item.Categories.Count > 0 ? string.Join(CategoriesSeparator, item.Categories.Select(s => s.Reference)) : string.Empty; //newsItemPage.DirectLink = item.DirectLink; newsItemPage.ImportedReferences = EipaReferenceMapper.ReferencesToString(item.References); //newsItemPage.Targeting = item.Targeting; /* Meta data */ if (item.MetaData != null) { newsItemPage.MetaTitle = item.MetaData.Title; newsItemPage.MetaDescription = item.MetaData.Description; newsItemPage.MetaKeywords = item.MetaData.KeyWordsString; } if (item.ShareOptions != null) { newsItemPage.ShareDescription = item.ShareOptions.Description; } //newsPage.ShareImage = item.ShareOptions.Image.Reference; // images urls from XML does not resolve // Publish page ContentRepository.Save(newsItemPage, SaveAction.Publish, AccessLevel.NoAccess); }
public NewsItem Map(NewsItemPage newsItemPage) { var newsItem = new NewsItem { Title = newsItemPage.Headline, Introduction = newsItemPage.Preamble, LinkTitle = newsItemPage.ListHeading, PublishDate = newsItemPage.StartPublish, Translation = new Translation { LanguageId = newsItemPage.LanguageID } }; /* DATES */ if (newsItemPage.StopPublish != DateTime.MaxValue) { newsItem.ClosingDate = newsItemPage.StopPublish; } if (newsItemPage.MainBody != null) { newsItem.Text = newsItemPage.MainBody.ToString();//.Replace("href=\"/", "href=\"//www.ericsson.com/"); } string imageUrl; if (TryGetImageUrl(newsItemPage.Image1, "image-wide-100", out imageUrl)) { newsItem.Images = new Images { AlternativeText = newsItemPage.AltText1, DesktopImageUrl = imageUrl }; } var unixStartTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); var createdTimeDiff = newsItemPage.Created - unixStartTime; var savedTimeDiff = newsItemPage.Saved - unixStartTime; /* Meta data */ newsItem.MetaData = new Meta { Title = newsItemPage.MetaTitle, Description = newsItemPage.MetaDescription, KeyWordsString = newsItemPage.MetaKeywords, CreatedDateMilliseconds = createdTimeDiff.TotalMilliseconds, ModifiedDateMilliseconds = savedTimeDiff.TotalMilliseconds }; newsItem.ShareOptions = new ShareOptions { Description = newsItemPage.ShareDescription }; string shareImageUrl; if (TryGetImageUrl(newsItemPage.ShareImage, "image-normal-100", out shareImageUrl)) { newsItem.ShareOptions.Image = new Link { Reference = shareImageUrl }; } newsItem.TagListString = newsItemPage.ImportedTagList; /* Categories */ if (!string.IsNullOrWhiteSpace(newsItemPage.ImportedCategories)) { var categoriesList = newsItemPage.ImportedCategories .Split(new[] { CategoriesSeparator }, StringSplitOptions.RemoveEmptyEntries) .ToList(); if (categoriesList.Count > 0) { newsItem.Categories = new List <Link>(); foreach (var category in categoriesList) { newsItem.Categories.Add(new Link { Reference = category }); } } } newsItem.References = EipaReferenceMapper.ReferencesFromString(newsItemPage.ImportedReferences); return(newsItem); }