using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Runtime.Remoting.Messaging;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Keyoti.SearchEngine.Search;
using Keyoti.SearchEngine;
using Keyoti.SearchEngine.DataAccess.IndexableSourceRecords;
namespace RunCrawlBuild
{
/// <summary>
/// Summary description for _Default.
/// </summary>
public partial class _Default : System.Web.UI.Page
{
private delegate void CrawlBuildDelegate();
Configuration Configuration = new Configuration(); //this is required in versions 3 onwards, and should be removed in older versions
private IAsyncResult CrawlBuildAsync()
{
CrawlBuildDelegate CrawlBuildDelegate = new CrawlBuildDelegate(CrawlBuild);
IAsyncResult ar = CrawlBuildDelegate.BeginInvoke(new AsyncCallback(MyCallback), null);
return ar;
}
private void MyCallback(IAsyncResult ar)
{
AsyncResult aResult = (AsyncResult)ar;
CrawlBuildDelegate CrawlBuildDelegate = (CrawlBuildDelegate)aResult.AsyncDelegate;
CrawlBuildDelegate.EndInvoke(ar);
}
void CrawlBuild()
{
try
{
Application["runningCB"] = true;
Keyoti.SearchEngine.Index.DocumentImporter webSiteSpider = new Keyoti.SearchEngine.Index.DocumentImporter(Configuration); //in 2.2 and older versions the Configuration arg should be removed
Keyoti.SearchEngine.Index.DocumentIndex docIdx = new Keyoti.SearchEngine.Index.DocumentIndex(Configuration); //in 2.2 and older versions the Configuration arg should be removed
webSiteSpider.Open();
//use these lines to import a particular website
string startUrl = "http://localhost/";
webSiteSpider.Import(new Keyoti.SearchEngine.DataAccess.IndexableSourceRecords.WebsiteBasedIndexableSourceRecord(startUrl));
//use these lines to refresh existing sources
/*ArrayList existingSources = webSiteSpider.GetIndexableSourceRecords();
foreach (IndexableSourceRecord record in existingSources)
{
webSiteSpider.Import(record);
}
*/
webSiteSpider.Close();
docIdx.Open();
docIdx.Build();
docIdx.Close();
}
catch (Exception ex)
{
throw ex;
}
finally
{
Application["runningCB"] = false;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
Configuration.IndexDirectory = @"C:\Inetpub\wwwroot\RunCrawlBuild\IndexDirectory";
if ((Application["runningCB"] == null) ||
((Application["runningCB"] != null) && (!((bool)Application["runningCB"]))))
CrawlBuildAsync();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}