Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
    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();
    }