public static GenericDirectoryParser GetInstance()
 {
     if (dirParser == null)
     {
         dirParser = new GenericDirectoryParser();
     }
     return(dirParser);
 }
        /// <summary>
        /// This Method is responsible for Crawling a given Volume or Path recursively.
        /// This method periodically checks the shared state variable 'crawlerState' and
        /// crawls the given path only when it is set to CrawlerState.Run
        ///
        /// Note: The shared variable is modified by the scheduler periodically depending on the
        ///       availability of system resources
        /// </summary>
        /// <param name="path">Path to a root volume or a directory whose contents are to be crawled recursively</param>
        private void Crawler(string path)
        {
            if (GlobalData.RunCrawler)  //assume the app is running and user has not exited the application
            {
                try
                {
                    //Process files
                    foreach (string file in Directory.GetFiles(path))
                    {
                        GlobalData.lIndexingStatus.Text = "Indexing: " + file;
                        if (crawlerState == CrawlerState.Run)  //Is the system in idle state
                        {
                            //Get the respective content handler. If no content handler is present return the default handler
                            IEDSParser parser = GlobalData.Parsers.ContainsKey(Path.GetExtension(file).ToLower()) ?
                                                GlobalData.Parsers[Path.GetExtension(file).ToLower()] : GlobalData.Parsers["*.*"];
                            if (parser != null)  //For some nasty reason the file got deleted or doesnot exist
                            {
                                StringDictionary properties = parser.GetProperties(file);
                                if (properties != null)
                                {
#if Log
                                    Console.WriteLine("Indexing File:" + file);
#endif
                                    GlobalData.Indexer.Index(properties);
                                }
                            }
                        }
                        else if (crawlerState == CrawlerState.Stop)                                                       //If the system is not ready
                        {
                            while (crawlerState == CrawlerState.Stop && GlobalData.RunScheduler && GlobalData.RunCrawler) //Check the status for every 1 sec
                            {
                                Thread.Sleep(1000);
                            }
                        }
                        else if (!GlobalData.RunCrawler)
                        {
                            break;                                 //if app is already close then we should also stop the crawler
                        }
                    }

                    //Process Directories
                    foreach (string dir in Directory.GetDirectories(path))
                    {
                        if (Path.GetFileName(dir).ToLower() != "recycler" ||
                            !string.IsNullOrEmpty(Path.GetDirectoryName(Path.GetDirectoryName(dir))))
                        {
                            GenericDirectoryParser parser = GenericDirectoryParser.GetInstance();
                            if (parser != null)
                            {
                                StringDictionary properties = parser.GetProperties(dir);
                                if (properties != null)
                                {
#if Log
                                    Console.WriteLine("Indexing Directory:" + dir);
#endif
                                    GlobalData.Indexer.Index(properties);
                                }
                            }
                            Crawler(dir);
                        }
                    }
                }
                catch (UnauthorizedAccessException uae) { }
            }
        }
 public static GenericDirectoryParser GetInstance()
 {
     if (dirParser == null) dirParser = new GenericDirectoryParser();
     return dirParser;
 }