public void Generate(List <string> additionalFiles) { UI.Log("Generating web site", ChmLogLevel.INFO); // Create directory, and additional files CreateDestinationDirectory(Project.WebDirectory, additionalFiles); try { if (Project.FullTextSearch) { // Prepare the search index Indexer = new WebIndex(); string dbFile = Path.Combine(Project.WebDirectory, "fullsearchdb.db3"); string dirTextFiles = Path.Combine(Project.WebDirectory, "textFiles"); Indexer.Connect(dbFile); Indexer.CreateDatabase(System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "searchdb.sql", dirTextFiles); Indexer.StoreConfiguration(Project.WebLanguage); } // Create content help files, and index them if it was needed CreateHelpContentFiles(Project.WebDirectory); } finally { if (Indexer != null) { Indexer.Disconnect(); } } // Create text replacements Replacements replacements = CreateTextReplacements(); // Copy template web files replacing text replacements.CopyDirectoryReplaced(Project.TemplateDirectory, Project.WebDirectory, MSWord.HTMLEXTENSIONS, AppSettings.UseTidyOverOutput, UI, Decorator.OutputEncoding); // Copy full text search files replacing text: if (Project.FullTextSearch) { // Copy full text serch files: string dirSearchFiles = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "searchFiles"; replacements.CopyDirectoryReplaced(dirSearchFiles, Project.WebDirectory, MSWord.ASPXEXTENSIONS, false, UI, Decorator.OutputEncoding); } if (Project.GenerateSitemap) { // Generate site map for web indexers (google). GeneateSitemap(); } }
/// <summary> /// Saves the splitted content files of the document to HTML files into a directory. /// </summary> /// <param name="directoryDstPath">Directory path where the content files will be stored</param> /// <param name="decorator">Tool to generate and decorate the HTML content files</param> /// <param name="indexer">Tool to index the saved content files. It can be null, if the content /// does not need to be indexed.</param> /// <returns>The content file names saved</returns> public List <string> SaveContentFiles(string directoryDstPath, HtmlPageDecorator decorator, WebIndex indexer) { // Search nodes with body on the document tree List <string> savedFiles = new List <string>(); foreach (ChmDocumentNode node in RootNode.Children) { SaveContentFiles(node, savedFiles, directoryDstPath, decorator, indexer); } // Save the CSS file: if (!string.IsNullOrEmpty(EmbeddedStylesTagContent)) { string cssFilePath = Path.Combine(directoryDstPath, EMBEDDEDCSSFILENAME); StreamWriter writer = new StreamWriter(cssFilePath); writer.Write(EmbeddedStylesTagContent); writer.Close(); savedFiles.Add(EMBEDDEDCSSFILENAME); } return(savedFiles); }
protected void Page_Load(object sender, EventArgs e) { DateTime start = DateTime.Now; txtResult.Text = ""; string queryText = Request["q"]; int startPage = 0; if (Request["s"] != null) { try { startPage = Int32.Parse(Request["s"]); } catch { } } ; if (queryText != null) { char[] tokens = { ' ' }; string[] words = queryText.Split(tokens); string webDirectory = Path.GetDirectoryName(Request.PhysicalPath); string pathDB = webDirectory + Path.DirectorySeparatorChar + "fullsearchdb.db3"; WebIndex idx = null; ArrayList results = null; SearchWords searchWords = null; try { idx = new WebIndex(); idx.Connect(pathDB); //results = idx.Search(words); searchWords = idx.PrepareRealWords(words); if (searchWords == null) { // Some word not found: results = new ArrayList(0); } else { results = idx.Search(searchWords); } } finally { if (idx != null) { idx.Disconnect(); } } //ArrayList normalizedWords = WebIndex.NormalizeWordsSet(words); string textFilesDir = webDirectory + Path.DirectorySeparatorChar + "textFiles"; int startResult = startPage * NRESULTSBYPAGE; int lastResult = (startPage + 1) * NRESULTSBYPAGE; if (lastResult > results.Count) { lastResult = results.Count; } txtSearchText.Text = ""; foreach (string word in words) { txtSearchText.Text += word + " "; } txtShowResults.Text = (startResult + 1) + " - " + lastResult; txtTotalResults.Text = results.Count.ToString(); txtResult.Text += "<p>"; for (int i = startResult; i < lastResult; i++) { Result result = (Result)results[i]; txtResult.Text += result.GoogleTextFormat(textFilesDir, searchWords) + "\n"; } txtResult.Text += "</p>"; if (results.Count > NRESULTSBYPAGE) { int nPages = results.Count / NRESULTSBYPAGE; if ((results.Count % NRESULTSBYPAGE) > 0) { nPages++; } if (startPage != 0) { lnkPrevious.NavigateUrl = HRef(queryText, startPage - 1); } else { lnkPrevious.Visible = false; } for (int i = 0; i < nPages; i++) { if (startPage != i) { int number = i + 1; txtResultLinks.Text += " " + Link(queryText, i, number.ToString()); } else { txtResultLinks.Text += " <font color=\"red\">" + (i + 1) + "</font>"; } } if (startPage != (nPages - 1)) { lnkNext.NavigateUrl = HRef(queryText, startPage + 1); } else { lnkNext.Visible = false; } } else { txtMoreResults.Visible = false; lnkPrevious.Visible = false; lnkNext.Visible = false; } } else { txtSearchText.Text = ""; txtShowResults.Text = "0 - 0"; txtTotalResults.Text = "0"; txtMoreResults.Visible = false; lnkPrevious.Visible = false; lnkNext.Visible = false; } DateTime end = DateTime.Now; TimeSpan span = end.Subtract(start); double roundMs = Math.Round(span.TotalMilliseconds, 2); txtMiliseconds.Text = roundMs.ToString(); }
/// <summary> /// Saves the splitted content files of the document to HTML files into a directory. /// </summary> /// <param name="node">Current node on the recursive search</param> /// <param name="savedFiles">The content file names saved</param> /// <param name="directoryDstPath">Directory path where the content files will be stored</param> /// <param name="decorator">Tool to generate and decorate the HTML content files</param> /// <param name="indexer">Tool to index the saved content files. It can be null, if the content /// does not need to be indexed.</param> private void SaveContentFiles(ChmDocumentNode node, List <string> savedFiles, string directoryDstPath, HtmlPageDecorator decorator, WebIndex indexer) { string fileName = node.SaveContent(this, directoryDstPath, decorator, indexer); if (fileName != null) { savedFiles.Add(fileName); } foreach (ChmDocumentNode child in node.Children) { SaveContentFiles(child, savedFiles, directoryDstPath, decorator, indexer); } }
/// <summary> /// Saves the splitted content of this node into a file, if it has any. /// </summary> /// <param name="document">Owner of this node</param> /// <param name="directoryDstPath">Directory path where the content files will be stored</param> /// <param name="decorator">Tool to generate and decorate the HTML content files</param> /// <param name="indexer">Tool to index the saved content files. It can be null, if the content /// does not need to be indexed.</param> /// <returns>The content file name saved. Is this node has no content, it returns null</returns> public string SaveContent(ChmDocument document, string directoryDstPath, HtmlPageDecorator decorator, WebIndex indexer) { if (SplittedPartBody == null) { return(null); } // Save the section, adding header, footers, etc: string filePath = Path.Combine(directoryDstPath, DestinationFileName); decorator.ProcessAndSavePage(this, document, filePath); if (indexer != null) { // Store the document at the full text search index: indexer.AddPage(DestinationFileName, Title, SplittedPartBody); } return(DestinationFileName); }