public static void Load(TextIndexer indexer, IEnumerable <Book> books, string version) { foreach (var book in books) { foreach (var chapter in book.Chapters) { foreach (var verse in chapter.Verses) { var text = verse.Text.FirstOrDefault(v => v.VersionId.Equals(version)); if (text != null) { indexer.Index(book, chapter, verse, text); } } } } var profile = indexer.Profiler.Present(); }
/// <summary> /// Writes the RSS feed. /// </summary> protected virtual void WriteRss() { XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8); string url; PageData page; writer.WriteStartDocument(); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/"); writer.WriteStartElement("channel"); writer.WriteElementString("language", CurrentPage.LanguageID); writer.WriteElementString("title", CurrentPage.PageName); writer.WriteElementString("link", Settings.Instance.SiteUrl.ToString()); writer.WriteElementString("description", CurrentPage["Description"] as string); writer.WriteElementString("ttl", "60"); writer.WriteElementString("generator", "EPiServer CMS 6 R2"); for (int i = 0; i < FeedSource.Count && i < FeedCount; i++) { page = FeedSource[i]; url = CreateExternalLink(page); writer.WriteStartElement("item"); writer.WriteElementString("title", page.PageName); writer.WriteElementString("link", url); writer.WriteElementString("description", TextIndexer.StripHtml((String)page["MainBody"], 250)); writer.WriteElementString("guid", url); writer.WriteElementString("author", page.CreatedBy); writer.WriteElementString("pubDate", page.Changed.ToString("r")); foreach (int category in page.Category) { writer.WriteElementString("category", page.Category.GetCategoryName(category)); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); }
/// <summary> /// Process XHTMLString to the contained string value - Handles the loading of blockvalues within the XhtmlString, replacing it with the "rendered" string from the block. /// </summary> /// <param name="language"></param> /// <param name="content"></param> /// <returns></returns> public string ParseToString(CultureInfo language, params XhtmlString[] content) { var sb = new StringBuilder(); foreach (var xhtmlString in content) { if (xhtmlString == null) { continue; } foreach (var fragment in xhtmlString.Fragments.GetFilteredFragments(PrincipalInfo.AnonymousPrincipal)) { if (fragment is ContentFragment) { var contentFragment = fragment as ContentFragment; var block = ServiceLocator.Current.GetInstance <IContentLoader>().Get <IContent>(contentFragment.ContentGuid, language) as BlockData; if (block != null) { var parsed = ServiceLocator.Current.GetInstance <IEpiBlockParser>().Parse(language, block); if (!string.IsNullOrWhiteSpace(parsed)) { sb.Append(parsed); sb.Append(" "); } else { _logger.Debug($"{block.GetType().BaseType?.Name} has no block parsing strategy"); } } } else if (fragment is StaticFragment) { sb.Append((fragment as StaticFragment).InternalFormat); } } } return(TextIndexer.StripHtml(sb.ToString().Trim(), 0)); }
private string GetPreviewText(FoundationPageData page) { var previewText = string.Empty; if (page.MainBody != null) { previewText = page.MainBody.ToHtmlString(); } if (string.IsNullOrEmpty(previewText)) { return(string.Empty); } var regexPattern = new StringBuilder(@"<span[\s\W\w]*?classid="""); //regexPattern.Append(DynamicContentFactory.Instance.DynamicContentId.ToString()); regexPattern.Append(@"""[\s\W\w]*?</span>"); previewText = Regex.Replace(previewText, regexPattern.ToString(), string.Empty, RegexOptions.IgnoreCase | RegexOptions.Multiline); return(TextIndexer.StripHtml(previewText, 200)); }
/// <summary> /// Generates the TXT. /// </summary> /// <param name="page">The page.</param> /// <returns> /// The <see cref="string" />. /// </returns> public static string GenerateTxt(IContent page) { if (page == null) { return(string.Empty); } StringBuilder contentString = new StringBuilder(); contentString.AppendLine(page.Name); contentString.AppendLine(); List <KeyValuePair <string, string> > propertyValues = page.GetPropertyValues(); foreach (KeyValuePair <string, string> content in propertyValues) { contentString.AppendLine(TextIndexer.StripHtml(content.Value, content.Value.Length)); contentString.AppendLine(); } return(contentString.ToString()); }
/// <returns>Returns the preview text for the specified PageData</returns> /// <remarks>The preview text is primarily created from the MainIntro property if it exists, /// otherwise parts of the MainBody property are being used. /// If neither a MainIntro nor a MainBody property exists, the preview will not be shown. protected string GetPreviewText(object dataItem) { PageData page = dataItem as PageData; if (page == null) { return(string.Empty); } string previewText = String.Empty; if (page.Property["MainIntro"] != null && page.Property["MainIntro"].ToString().Length > 0) { previewText = page.Property["MainIntro"].ToWebString(); } else if (page.Property["MainBody"] != null) { previewText = page.Property["MainBody"].ToWebString(); } return(TextIndexer.StripHtml(previewText, _previewTextLength)); }
static IEnumerable <string> GetTextAnalysisRequireentPropertyValues(ITageablePage productPage) { var textAnalysisContentProperties = productPage .GetType() .BaseType .GetProperties(); foreach (var textAnalysisContentProperty in textAnalysisContentProperties) { if (textAnalysisContentProperty.GetCustomAttributes(typeof(TextAnalysisRequireAttribute), true).Any()) { var propertyVale = textAnalysisContentProperty.GetValue(productPage); if (propertyVale != null) { var strPropertyValue = propertyVale.ToString(); if (!string.IsNullOrWhiteSpace(strPropertyValue)) { var noHtmlString = HttpUtility.HtmlDecode(TextIndexer.StripHtml(strPropertyValue, 0)); yield return(Regex.Replace(noHtmlString, @"[^\u0000-\u007F]+", string.Empty)); } } } } }
/// <summary> /// Generate the json output for the page. /// </summary> /// <param name="page"> /// The page. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string GenerateJson(IContent page) { string json; List <KeyValuePair <string, string> > propertyValues = page.GetPropertyValues(); StringBuilder stringBuilder = new StringBuilder(); using (StringWriter sw = new StringWriter(stringBuilder, CultureInfo.InvariantCulture)) { JsonWriter jsonWriter = new JsonTextWriter(sw) { Formatting = Formatting.Indented }; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName(page.Name); jsonWriter.WriteStartObject(); foreach (KeyValuePair <string, string> content in propertyValues) { jsonWriter.WritePropertyName(content.Key); jsonWriter.WriteValue(TextIndexer.StripHtml(content.Value, content.Value.Length)); } jsonWriter.WriteEndObject(); jsonWriter.WriteEndObject(); json = sw.ToString(); } return(json); }
/// <summary> /// Strip all HTML elements from a HTML string and return text. /// </summary> /// <param name="htmlText">A HTML string.</param> /// <param name="maxLength">Max string length to return. 0 returns all text in the HTML string.</param> /// <returns>A string with text.</returns> public static string StripHtml(this string htmlText, int maxLength = 0) { return(string.IsNullOrWhiteSpace(htmlText) ? htmlText : TextIndexer.StripHtml(htmlText, maxLength)); }
public PsudoEmailInjector(LayerManager db, DbgGUI gui) { this.db = db; this.gui = gui; this.indexer = new TextIndexer(db); }
private void MainWindow_Load(object sender, EventArgs e) { Debug.WriteLine("MainWindow_Load: {0}", Thread.CurrentThread.ManagedThreadId); _uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); _indexer = new TextIndexer<Tokenizer>(TimeSpan.FromSeconds(60)); _indexer.Changed += _indexer_Changed; _detailsWindow = new DetailsWindow(); _detailsWindow.Hide(); }
/// <summary> /// Creates the metadata tags for the website /// </summary> private void CreateMetaData() { // Description - use MetaDescription property if it exists, otherwise use contents // from MainIntro property. Do not display the meta tag if none of these options return // values. string metaDescription = GetPropertyString("MetaDescription", CurrentPage); if (metaDescription.Equals(string.Empty)) { metaDescription = GetPropertyString("MainIntro", CurrentPage); if (!metaDescription.Equals(string.Empty)) { metaDescription = TextIndexer.StripHtml(metaDescription, 0); if (metaDescription.Length > 255) { metaDescription = metaDescription.Substring(0, 252) + "..."; } } } if (!metaDescription.Equals(string.Empty)) { CreateMetaTag("description", metaDescription, false); } // Keywords CreateMetaTag("keywords", "MetaKeywords", CurrentPage, false); // Author CreateMetaTag("author", "MetaAuthor", CurrentPage, false); // Rating CreateMetaTag("rating", "General", false); // Revisit each month CreateMetaTag("revisit-after", "4 weeks", false); // Generator CreateMetaTag("generator", "EPiServer", false); // Robots CreateMetaTag("robots", "all", false); // Charset CreateMetaTag("Content-Type", string.Format("text/html; charset={0}", "UTF-8"), true); // Created - GMT format if (CurrentPage.Created != DateTime.MinValue) { CreateMetaTag("creation_date", CurrentPage.Created.ToString("R"), false); } // Last modified data, in GMT format - Note, same as revised if (CurrentPage.Changed != DateTime.MinValue) { CreateMetaTag("last-modified", CurrentPage.Changed.ToString("R"), false); } // Revised - GMT format if (CurrentPage.Changed != DateTime.MinValue) { CreateMetaTag("revised", CurrentPage.Changed.ToString("R"), false); } CreateMetaTag("Content-Language", CurrentPage.LanguageBranch, true); }
private static string StripHtml(string html) { const string moreTextMarker = "..."; return(TextIndexer.StripHtml(html, int.MaxValue, int.MaxValue, moreTextMarker).Trim()); }
/// <summary> /// Raises the page event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="contentEventArgs">Event information to send to registered event handlers.</param> public void OnPublishingContent(object sender, ContentEventArgs contentEventArgs) { if (contentEventArgs == null) { return; } PageData page = contentEventArgs.Content as PageData; if (page == null) { return; } PropertyInfo addtionalSearchContentProperty = GetAddtionalSearchContentProperty(page); if (addtionalSearchContentProperty == null) { return; } if (addtionalSearchContentProperty.PropertyType != typeof(string)) { return; } StringBuilder stringBuilder = new StringBuilder(); ContentType contentType = this.ContentTypeRepository.Service.Load(page.ContentTypeID); foreach (PropertyDefinition current in from d in contentType.PropertyDefinitions where typeof(PropertyContentArea).IsAssignableFrom(d.Type.DefinitionType) select d) { PropertyData propertyData = page.Property[current.Name]; ContentArea contentArea = propertyData.Value as ContentArea; if (contentArea == null) { continue; } foreach (ContentAreaItem contentAreaItem in contentArea.Items) { IContent content; if (!this.ContentRepository.Service.TryGet(contentAreaItem.ContentLink, out content)) { continue; } // content area item can be null when duplicating a page if (content == null) { continue; } // Check if the content is indeed a block, and not a page used in a content area BlockData blockData = content as BlockData; // Content area is not a block, but probably a page used as a teaser. if (blockData == null) { Logger.Information( "[Blocksearch] Contentarea item is not block data. Skipping update.", content.Name); continue; } IEnumerable <string> props = this.GetSearchablePropertyValues(content, content.ContentTypeID); stringBuilder.AppendFormat(" {0}", string.Join(" ", props)); } } if (addtionalSearchContentProperty.PropertyType != typeof(string)) { return; } try { string additionalSearchContent = TextIndexer.StripHtml(stringBuilder.ToString(), 0); // When being "delayed published" the pagedata is readonly. Create a writable clone to be safe. PageData editablePage = page.CreateWritableClone(); editablePage[addtionalSearchContentProperty.Name] = additionalSearchContent; // Save the writable pagedata, do not create a new version this.ContentRepository.Service.Save( editablePage, SaveAction.Save | SaveAction.ForceCurrentVersion, AccessLevel.NoAccess); } catch (EPiServerException ePiServerException) { Logger.Error( string.Format( CultureInfo.InvariantCulture, "[Blocksearch] Property {0} dose not exist on {1} .", addtionalSearchContentProperty.Name, page.Name), ePiServerException); } }