// // GET: /HowTo/DisplayArticleLink public ActionResult DisplayArticleLink() { //Request the specific article. If you intend to display the full article you must send the flag "IncludeBody" ContentArticleResponse article = _client.Content.GetContent("development-sample-articles", "link-article-1", new GetContentOptions { IncludeBody = true }); //Process all segments and convert any internal content links to real links. foreach (ContentSegmentResponse segment in article.Segments) { HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.LoadHtml(segment.Body); HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes("//a[@data-content-slug]"); if (nodes != null) { foreach (HtmlNode linkNode in nodes) { HtmlAttribute contentSlug = linkNode.Attributes["data-content-slug"]; HtmlAttribute bucketSlug = linkNode.Attributes["data-bucket-slug"]; //This line should reflect the path you use to display your content. linkNode.Attributes.Add("href", "/Content/" + bucketSlug.Value + "/" + contentSlug.Value); } } segment.Body = htmlDoc.DocumentNode.OuterHtml; } return(View(article)); }
public List <ServiceLineMappingResponse> GetMappedServices(ContentArticleResponse content) { //Get the mappings List <ServiceLineMappingResponse> mappings = new List <ServiceLineMappingResponse>(); foreach (ServiceLineResponse serviceLine in content.ServiceLines) { //There are 4 types of mappings that could be returned. We must iterate over each. foreach (MAPPING_TYPES mappingType in Enum.GetValues(typeof(MAPPING_TYPES))) { try { ServiceLineMappingResponseList mappingResponseList = _client.Mappings.GetServiceLineMappings(mappingType.ToString(), serviceLine.AudienceSlug, serviceLine.ServiceLineSlug, serviceLine.PageKeywordSlug, false); mappings.AddRange(mappingResponseList.Items); } catch (ServiceException ex) { //Not all clients purchase iMapping. If iMapping is not part of the package simply return an empty list. if (ex.StatusCode == System.Net.HttpStatusCode.Forbidden) { return(new List <ServiceLineMappingResponse>()); } throw ex; } } } return(mappings); }
// // GET: /Conversion/DisplayContentByLegacyId public ActionResult DisplayContentByLegacyId() { ContentArticleResponse article = _client.Content.GetLegacyContent("85", "P00816", new LegacyContentOptions { IncludeBody = true }); return(View(article)); }
// // GET: /HowTo/DisplayArticle public ActionResult DisplayArticle() { //Request the specific article. If you intend to display the full article you must send the flag "IncludeBody" ContentArticleResponse article = _client.Content.GetContent("diseases-and-conditions", "Prion-Diseases", new GetContentOptions { IncludeBody = true }); return(View(article)); }
[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)] //Disable cache to ensure the file uploaded is the alwasys the latest. public ActionResult VerifyLegacyIds(string ApplicationKey, string ApplicationSecret) { if (Request != null) { //If values are provided we will override the default application key and secret from configuration. ApiClient localClient = _client; if (!String.IsNullOrEmpty(ApplicationKey) && !String.IsNullOrEmpty(ApplicationSecret)) { localClient = new ApiClient(ApplicationKey, ApplicationSecret); } LegacyContentValidationReportModel report = new LegacyContentValidationReportModel(); //Process the uploaded file. HttpPostedFileBase file = Request.Files["UploadedFile"]; if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { StreamReader csvreader = new StreamReader(file.InputStream); while (!csvreader.EndOfStream) { var line = csvreader.ReadLine(); string[] values = line.Split(','); report.Items.Add(new LegacyContentModel { ContentTypeId = values[0], ContentId = values[1] }); } } //Test if content is available. foreach (LegacyContentModel item in report.Items) { try { ContentArticleResponse article = localClient.Content.GetLegacyContent(item.ContentTypeId, item.ContentId, new LegacyContentOptions()); item.IsAvailable = true; } catch (Exception ex) { item.IsAvailable = false; item.NotAvailableReason = ex.Message; } } //Prepare the report report.ItemCount = report.Items.Count; report.ErrorCount = report.Items.Count(c => c.IsAvailable == false); return(View(report)); } return(View()); }
private List <GroupedContentModel> GetRelatedServicesGrouped(ContentArticleResponse content) { //Use the helper extension to get related service lines. ApiClientExtension extension = new ApiClientExtension(_client); List <ServiceLineMappingResponse> mappings = extension.GetMappedServices(content); //Map the related services to the grouped content model MappingToGroupedContentModelMapper mapper = new MappingToGroupedContentModelMapper(); List <GroupedContentModel> groupedContent = mapper.Map(mappings); return(groupedContent); }
private List <GroupedContentModel> GetRelatedContentGrouped(ContentArticleResponse content) { //Use the helper extension to get related content. ApiClientExtension extension = new ApiClientExtension(_client); List <ContentResponse> relatedContent = extension.GetRelatedContent(content.Bucket.Slug, content.Slug, new List <string> { "En" }); //Map the related content to the grouped content model ContentToGroupedContentModelMapper mapper = new ContentToGroupedContentModelMapper(); List <GroupedContentModel> groupedContent = mapper.Map(relatedContent); return(groupedContent); }
public List <ContentResponse> GetRelatedContent(string bucketSlug, string contentSlug, List <string> Languages) { //Start with an article that you want to get the related content for ContentArticleResponse article = _client.Content.GetContent(bucketSlug, contentSlug, new GetContentOptions()); ContentTaxonomyList meshTaxonomy = article.Taxonomies.Find(c => c.Slug == "mesh"); //If there aren't any mesh terms then we'll return no related documents if (meshTaxonomy == null) { return(new List <ContentResponse>()); } //Mesh terms exist, let's build a mesh basd query to get related articles. string query = "mesh: "; if (meshTaxonomy.Items.Count > 0) { query = "mesh: " + meshTaxonomy.Items[0].Value; } for (int i = 1; i < meshTaxonomy.Items.Count; i++) { query += " or mesh: " + meshTaxonomy.Items[i].Value; } //Search for content with an overlapping mesh code. ContentList relatedContent = _client.Content.SearchContent(new ContentSearchRequest { Query = query, Count = DEFAULT_COUNT, Languages = Languages }); //Fiter out the item that we started the related to search from. List <ContentResponse> contentResponses = new List <ContentResponse>(); foreach (ContentResponse response in relatedContent.Items) { if (response.Bucket.Slug != bucketSlug || response.Slug != contentSlug) { contentResponses.Add(response); } } return(contentResponses); }