private void InitializeFileSystemMonitor() { FileSystemMonitor fsw = FileSystemMonitor.GetInstance(); foreach (string drive in Environment.GetLogicalDrives()) { fsw.AddMonitor(drive); } fsw.StartAllMonitors(); }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (!TrayClose) //Dont Close the application if it not exited from system tray { e.Cancel = true; this.Visible = false; //And perhaps hide the application to system tray } else // if app is closed from system tray ...... do the cleanup stuff { GlobalData.RunCrawler = false; //Stop the crawler if it is running.... GlobalData.RunScheduler = false; //Stop the scheduler if it is running.... if (!GlobalData.IndexingCompleted && GlobalData.RunMonitor) { FileSystemMonitor.GetInstance().StopAllMonitors(); // Stop all monitors } Settings.SaveSettings(); //Save settings of the application at its exit UnregisterHotKey(this.Handle, 1); //Unregister HotKey on application exit } }
internal void StartCrawler() { // install the scheduler in a separate thread new Thread(delegate() { #if Log Console.WriteLine("Initiating Resource Scheduler in file system crawler"); #endif Scheduler(); }).Start(); //Start the crawler in the current thread #if Log Console.WriteLine("Initiating file system Crawler"); #endif long start = DateTime.Now.Ticks; foreach (string drive in GlobalData.Drives) { DriveInfo di = new DriveInfo(drive); if (di.IsReady && di.DriveType == DriveType.Fixed && GlobalData.RunCrawler) { //check whether the index directory is clean or not. if not delete all files in it if (Directory.Exists(GlobalData.IndexRootPath + drive[0])) { Directory.Delete(GlobalData.IndexRootPath + drive[0], true); } Directory.CreateDirectory(GlobalData.IndexRootPath + drive[0]); //Initialize the indexer GlobalData.Indexer = new EDSIndexer(GlobalData.IndexRootPath + drive[0]); //Start File System Crawler Crawler(drive); //Optimize the indexes GlobalData.Indexer.Optimize(); GlobalData.Indexer.Close(); } } #if Log Console.WriteLine("Completed File System Crawling"); #endif if (GlobalData.RunCrawler) //only when the crawler finished its work do the following stuff.....otherwise if crawler has been terminated by closing the application donot do the following stuff { GlobalData.IndexingCompleted = true; long end = DateTime.Now.Ticks; DateTime dt = new DateTime(end - start); GlobalData.lIndexingStatus.Text = "Indexing: Completed 100% in " + (dt.Hour != 0 ? dt.Hour + "h:" : "") + (dt.Minute != 0 ? dt.Minute + "m:" : "") + (dt.Second != 0 ? dt.Second + "s: " : "") + (dt.Millisecond != 0 ? dt.Millisecond + "ms" : ""); //update the statusbar indexed documents count int docCount = 0; foreach (string dir in Directory.GetDirectories(GlobalData.IndexRootPath)) { IndexReader ir = IndexReader.Open(dir); docCount += ir.NumDocs(); ir.Close(); } if (GlobalData.MainStatusStrip != null && GlobalData.MainStatusStrip.Items.Count != 0) { GlobalData.MainStatusStrip.Items["tsslDocCount"].Text = docCount + " documents indexed "; } //Finally start file system monitor for further file system updates if (GlobalData.RunMonitor) { #if Log Console.WriteLine("Starting File System Monitor"); #endif FileSystemMonitor fsw = FileSystemMonitor.GetInstance(); foreach (string drive in Environment.GetLogicalDrives()) { fsw.AddMonitor(drive); } fsw.StartAllMonitors(); } } //after completion of crawling stop the scheduler by setting RunScheduler => false; GlobalData.RunScheduler = false; }