/// <summary> /// This method intialize the state of the base object or peform tasks that are /// applicable to all derived class object. /// </summary> public virtual void Initialize() { IPageAssemblyInstruction pgInst = ((IPageAssemblyInstruction)this); // field filters pgInst.AddFieldFilter("invokedFrom", (name, field) => { field.Value = String.Empty; }); pgInst.AddFieldFilter("language", (name, field) => { string languageValue = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; field.Value = languageValue; }); // URL filters pgInst.AddUrlFilter("RootPrettyURL", (name, url) => { url.SetUrl(pgInst.GetUrl("CurrentURL").ToString()); // This is hack to fix the RootPrettyURL. If this content type is // rx:pdqCancerInfoSummary then remove the 'patient' or 'healthprofessional' from // the pretty url string prettyUrl = pgInst.GetUrl("PrettyURL").ToString().ToLower(); if (ContentItemInfo != null && ContentItemInfo.ContentItemType == "rx:pdqCancerInfoSummary") { int verIndex = prettyUrl.LastIndexOf("/patient"); if (verIndex == -1) { verIndex = prettyUrl.LastIndexOf("/healthprofessional"); } if (verIndex != -1) { prettyUrl = prettyUrl.Substring(0, verIndex); } } url.SetUrl(prettyUrl); }); pgInst.AddUrlFilter("BookMarkShareUrl", (name, url) => { url.SetUrl(pgInst.GetUrl("CurrentURL").ToString()); }); pgInst.AddUrlFilter("EmailUrl", (name, url) => { url.SetUrl(pgInst.GetUrl("CurrentURL").ToString()); }); pgInst.AddUrlFilter("PostBackURL", (name, url) => { url.SetUrl(pgInst.GetUrl("CurrentURL") + "?" + HttpContext.Current.Request.QueryString); }); }
/// <summary> /// Adds an appropriate FieldFilter to the given PageAssemblyInstruction object, based on the Tag's /// current settings. /// </summary> /// <param name="pai">The IPageAssemblyInstruction object to receive the new FieldFilter.</param> private void RegisterSocialMetaTagFieldFilter(IPageAssemblyInstruction pai, SocialMetaTagData socialMetaTag) { // add a field filter for each tag pai.AddFieldFilter(socialMetaTag.Id, (name, data) => { string content = String.Empty; switch (socialMetaTag.Source) { case SocialMetaTagSources.field: content = pai.GetField(socialMetaTag.Content); break; case SocialMetaTagSources.url: content = pai.GetUrl(socialMetaTag.Content).ToString(); break; // both literal types just use the content directly default: content = socialMetaTag.Content; break; } data.Value = content; }); }
/// <summary> /// Creates field filters for the given SocialMetadata object. /// </summary> /// <param name="pai">An available PageAssemblyInstruction object to receive the field filters.</param> /// <param name="socialMetadata">The SocialMetadata object to provide the fields.</param> protected virtual void RegisterSocialMetadataFieldFilters(IPageAssemblyInstruction pai, SocialMetadata socialMetadata) { try { // check provided PageAssemblyInstruction if (pai == null) { log.Warn("RegisterSocialMetadataFieldFilters(): null PageAssemblyInstruction provided."); return; } // add commenting available field filter pai.AddFieldFilter("is_commenting_available", (name, data) => { data.Value = socialMetadata.IsCommentingAvailable.ToString(); }); // add field filters for any tags if (socialMetadata.Tags != null) { foreach (SocialMetaTagData tag in socialMetadata.Tags) { RegisterSocialMetaTagFieldFilter(pai, tag); } } } catch (Exception e) { log.Error("InitializeFieldFilters(): Exception encountered while initializing field filters.", e); } }
/// <summary> /// Sets the Meta Tag Description to a given term /// </summary> /// <param name="PageInstruction"></param> /// <param name="termName"></param> /// <param name="DictionaryLanguage"></param> private void SetMetaTagDescriptionToTerm(IPageAssemblyInstruction PageInstruction, string termName, string DictionaryLanguage) { switch (DictionaryLanguage.ToLower().Trim()) { case "es": PageInstruction.AddFieldFilter("meta_description", (name, data) => { data.Value = "Definición de " + termName; }); break; default: PageInstruction.AddFieldFilter("meta_description", (name, data) => { data.Value = "Definition of " + termName; }); break; } }
public void GetField_MultipleFieldFilters_Test() { IPageAssemblyInstruction pageAssemblyInfo = null; pageAssemblyInfo = InitializeTestPageAssemblyInfo(); pageAssemblyInfo.AddFieldFilter("Foo12345", (name, data) => { data.Value = "Dictionary of cancer terms"; }); //Add another one, but make sure we chain from the previous pageAssemblyInfo.AddFieldFilter("Foo12345", (name, data) => { data.Value += "--Modified"; }); Assert.AreEqual("Dictionary of cancer terms--Modified", pageAssemblyInfo.GetField("Foo12345")); }
public void AddField_EmptyFieldName_Test() { IPageAssemblyInstruction pageAssemblyInfo = null; pageAssemblyInfo = InitializeTestPageAssemblyInfo(); pageAssemblyInfo.AddFieldFilter(string.Empty, (name, data) => { data.Value = "Dictionary of cancer terms"; }); }
public void GetField_Test() { IPageAssemblyInstruction pageAssemblyInfo = null; pageAssemblyInfo = InitializeTestPageAssemblyInfo(); pageAssemblyInfo.AddFieldFilter("Foo12345", (name, data) => { data.Value = "Foo12345"; }); Assert.AreEqual("Foo12345", pageAssemblyInfo.GetField("Foo12345")); }
/// <summary> /// Sets the meta tag description. The function checks if the Dictionary Term has a valid (not null and length greater than 0) definition. /// If it is the case the function attempts to extract the first two sentences of the Definition and set them as the meta tag description. /// If not, we revert to using the term itself has the meta tag description. /// /// AUTHOR: CHRISTIAN RIKONG /// LAST PUBLISHED DATE: 12/08/2017 11:47 AM /// </summary> /// <param name="dataItem">Stores the Dictionary Term that is used to create the description meta tag</param> public static void SetMetaTagDescription(DictionaryTerm dataItem, string DictionaryLanguage, IPageAssemblyInstruction PageInstruction) { string termName = dataItem.Term; if (dataItem.Definition != null && dataItem.Definition.Text != null && dataItem.Definition.Text.Length > 0) { string sentences = ""; string[] definitionsSentences = System.Text.RegularExpressions.Regex.Split(dataItem.Definition.Text, @"(?<=[\.!\?])\s+"); if (definitionsSentences != null && definitionsSentences.Length > 0) { int sentencesCount = 0; foreach (string existingSentence in definitionsSentences) { sentencesCount = sentencesCount + 1; if (sentencesCount <= 2) { sentences = sentences + existingSentence.Replace(".", "") + ". "; } else { break; } } PageInstruction.AddFieldFilter("meta_description", (name, data) => { data.Value = sentences; }); } else { SetMetaTagDescriptionToTerm(PageInstruction, termName, DictionaryLanguage); } } else { SetMetaTagDescriptionToTerm(PageInstruction, termName, DictionaryLanguage); } }