Exemplo n.º 1
0
        public void StopAllMonitors()
        {
            foreach (string key in monitor.Keys)
            {
                monitor[key].EnableRaisingEvents = true;
            }

            EDSIndexer.OptimizeAllIndexes();  //finally optimize all indexes which have been updated by file system monitor

            //Stop the scheduler Thread
            fileSystemMonitorScheduler.Dispose();
        }
        void IndexGatheredFiles(object state)
        {
            try
            {
                #region Deleting files from the indexes
                //Iterate over all the directories present in the %appdata%\EDS\indexes folder
                if (GlobalData.DeletedFiles.Count > 0)
                {
                    foreach (string dir in Directory.GetDirectories(GlobalData.IndexRootPath))
                    {
                        //Deletion of files from indexes
                        IndexReader reader = IndexReader.Open(dir);
                        lock (GlobalData.DeletedFiles)
                        {
                            //foreach (string path in GlobalData.DeletedFiles)
                            while (GlobalData.DeletedFiles.Count != 0)
                            {
                                reader.DeleteDocuments(new Term("path", GlobalData.DeletedFiles[0]));
                                GlobalData.lIndexingStatus.Text = GlobalData.DeletedFiles[0] + " is deleted from indexes";
                                GlobalData.DeletedFiles.RemoveAt(0);
                            }
                        }
                        reader.Close();
                    }
                }
                #endregion

                #region indexing newly created files
                //Indexing of new Files
                if (GlobalData.CreatedFiles.Count > 0)
                {
                    lock (GlobalData.CreatedFiles)
                    {
                        //   foreach (string path in GlobalData.CreatedFiles)
                        while (GlobalData.CreatedFiles.Count != 0)
                        {
                            string path = GlobalData.CreatedFiles[0];
                            //Get the respective content handler. If no content handler is present return the default handler
                            IEDSParser parser = GlobalData.Parsers.ContainsKey(Path.GetExtension(path).ToLower()) ?
                                                GlobalData.Parsers[Path.GetExtension(path).ToLower()] : GlobalData.Parsers["*.*"];
                            if (parser != null)  //For some nasty reason the file got deleted or doesnot exist
                            {
                                StringDictionary properties = parser.GetProperties(path);
                                if (properties != null)
                                {
                                    //Initialize the indexer
                                    EDSIndexer indexer = new EDSIndexer(GlobalData.IndexRootPath + path[0]);
                                    indexer.Index(properties);
                                    indexer.Close();

                                }
                            }
                            GlobalData.lIndexingStatus.Text = GlobalData.CreatedFiles[0] + " is newly indexed";
                            GlobalData.CreatedFiles.RemoveAt(0);
                        }
                    }
                }
                #endregion

                #region Updating already indexed files

                lock (GlobalData.ChangedFiles)
                {
                    //foreach (string path in GlobalData.ChangedFiles)
                    while (GlobalData.ChangedFiles.Count != 0)
                    {
                        string path = GlobalData.ChangedFiles[0];
                        //first delete that document
                        foreach (string dir in Directory.GetDirectories(GlobalData.IndexRootPath))
                        {
                            //Deletion of files from indexes
                            IndexReader reader = IndexReader.Open(dir);
                            reader.DeleteDocuments(new Term("path", path));
                            bool deleted = reader.HasDeletions();
                            reader.Close();
                            if (deleted) break;
                        }
                        //reindex the document
                        //Get the respective content handler. If no content handler is present return the default handler
                        IEDSParser parser = GlobalData.Parsers.ContainsKey(Path.GetExtension(path).ToLower()) ?
                                            GlobalData.Parsers[Path.GetExtension(path).ToLower()] : GlobalData.Parsers["*.*"];
                        if (parser != null)  //For some nasty reason the file got deleted or doesnot exist
                        {
                            StringDictionary properties = parser.GetProperties(path);
                            if (properties != null)
                            {
                                //Initialize the indexer
                                EDSIndexer indexer = new EDSIndexer(GlobalData.IndexRootPath + path[0]);
                                indexer.Index(properties);
                                indexer.Close();
                            }
                        }
                        GlobalData.lIndexingStatus.Text = path + " is updated in the indexes";
                        GlobalData.ChangedFiles.RemoveAt(0);
                    }
                }

                #endregion

                #region Updating renamed files
                lock (GlobalData.RenamedFiles)
                {
                    //foreach (string path in GlobalData.ChangedFiles)
                    while (GlobalData.RenamedFiles.Count != 0)
                    {
                        string path = GlobalData.RenamedFiles[0].OldFullPath;
                        //first delete the old document
                        foreach (string dir in Directory.GetDirectories(GlobalData.IndexRootPath))
                        {
                            //Deletion of files from indexes
                            IndexReader reader = IndexReader.Open(dir);
                            reader.DeleteDocuments(new Term("path", path));
                            bool deleted = reader.HasDeletions();
                            reader.Close();
                            if (deleted) break;
                        }
                        //reindex the new document
                        //Get the respective content handler. If no content handler is present return the default handler
                        path = GlobalData.RenamedFiles[0].FullPath;
                        IEDSParser parser = GlobalData.Parsers.ContainsKey(Path.GetExtension(path).ToLower()) ?
                                            GlobalData.Parsers[Path.GetExtension(path).ToLower()] : GlobalData.Parsers["*.*"];
                        if (parser != null)  //For some nasty reason the file got deleted or doesnot exist
                        {
                            StringDictionary properties = parser.GetProperties(path);
                            if (properties != null)
                            {
                                //Initialize the indexer
                                EDSIndexer indexer = new EDSIndexer(GlobalData.IndexRootPath + path[0]);
                                indexer.Index(properties);
                                indexer.Close();
                            }
                        }
                        GlobalData.lIndexingStatus.Text = "Renamed file " + path + " is updated in the indexes";
                        GlobalData.RenamedFiles.RemoveAt(0);
                    }
                }
                #endregion

            }
            catch (Exception ex)
            {
            #if Log
            Console.WriteLine(ex);
            #endif
            }
        }
Exemplo n.º 3
0
        void IndexGatheredFiles(object state)
        {
            try
            {
                #region Deleting files from the indexes
                //Iterate over all the directories present in the %appdata%\EDS\indexes folder
                if (GlobalData.DeletedFiles.Count > 0)
                {
                    foreach (string dir in Directory.GetDirectories(GlobalData.IndexRootPath))
                    {
                        //Deletion of files from indexes
                        IndexReader reader = IndexReader.Open(dir);
                        lock (GlobalData.DeletedFiles)
                        {
                            //foreach (string path in GlobalData.DeletedFiles)
                            while (GlobalData.DeletedFiles.Count != 0)
                            {
                                reader.DeleteDocuments(new Term("path", GlobalData.DeletedFiles[0]));
                                GlobalData.lIndexingStatus.Text = GlobalData.DeletedFiles[0] + " is deleted from indexes";
                                GlobalData.DeletedFiles.RemoveAt(0);
                            }
                        }
                        reader.Close();
                    }
                }
                #endregion

                #region indexing newly created files
                //Indexing of new Files
                if (GlobalData.CreatedFiles.Count > 0)
                {
                    lock (GlobalData.CreatedFiles)
                    {
                        //   foreach (string path in GlobalData.CreatedFiles)
                        while (GlobalData.CreatedFiles.Count != 0)
                        {
                            string path = GlobalData.CreatedFiles[0];
                            //Get the respective content handler. If no content handler is present return the default handler
                            IEDSParser parser = GlobalData.Parsers.ContainsKey(Path.GetExtension(path).ToLower()) ?
                                                GlobalData.Parsers[Path.GetExtension(path).ToLower()] : GlobalData.Parsers["*.*"];
                            if (parser != null)  //For some nasty reason the file got deleted or doesnot exist
                            {
                                StringDictionary properties = parser.GetProperties(path);
                                if (properties != null)
                                {
                                    //Initialize the indexer
                                    EDSIndexer indexer = new EDSIndexer(GlobalData.IndexRootPath + path[0]);
                                    indexer.Index(properties);
                                    indexer.Close();
                                }
                            }
                            GlobalData.lIndexingStatus.Text = GlobalData.CreatedFiles[0] + " is newly indexed";
                            GlobalData.CreatedFiles.RemoveAt(0);
                        }
                    }
                }
                #endregion

                #region Updating already indexed files

                lock (GlobalData.ChangedFiles)
                {
                    //foreach (string path in GlobalData.ChangedFiles)
                    while (GlobalData.ChangedFiles.Count != 0)
                    {
                        string path = GlobalData.ChangedFiles[0];
                        //first delete that document
                        foreach (string dir in Directory.GetDirectories(GlobalData.IndexRootPath))
                        {
                            //Deletion of files from indexes
                            IndexReader reader = IndexReader.Open(dir);
                            reader.DeleteDocuments(new Term("path", path));
                            bool deleted = reader.HasDeletions();
                            reader.Close();
                            if (deleted)
                            {
                                break;
                            }
                        }
                        //reindex the document
                        //Get the respective content handler. If no content handler is present return the default handler
                        IEDSParser parser = GlobalData.Parsers.ContainsKey(Path.GetExtension(path).ToLower()) ?
                                            GlobalData.Parsers[Path.GetExtension(path).ToLower()] : GlobalData.Parsers["*.*"];
                        if (parser != null)  //For some nasty reason the file got deleted or doesnot exist
                        {
                            StringDictionary properties = parser.GetProperties(path);
                            if (properties != null)
                            {
                                //Initialize the indexer
                                EDSIndexer indexer = new EDSIndexer(GlobalData.IndexRootPath + path[0]);
                                indexer.Index(properties);
                                indexer.Close();
                            }
                        }
                        GlobalData.lIndexingStatus.Text = path + " is updated in the indexes";
                        GlobalData.ChangedFiles.RemoveAt(0);
                    }
                }

                #endregion

                #region Updating renamed files
                lock (GlobalData.RenamedFiles)
                {
                    //foreach (string path in GlobalData.ChangedFiles)
                    while (GlobalData.RenamedFiles.Count != 0)
                    {
                        string path = GlobalData.RenamedFiles[0].OldFullPath;
                        //first delete the old document
                        foreach (string dir in Directory.GetDirectories(GlobalData.IndexRootPath))
                        {
                            //Deletion of files from indexes
                            IndexReader reader = IndexReader.Open(dir);
                            reader.DeleteDocuments(new Term("path", path));
                            bool deleted = reader.HasDeletions();
                            reader.Close();
                            if (deleted)
                            {
                                break;
                            }
                        }
                        //reindex the new document
                        //Get the respective content handler. If no content handler is present return the default handler
                        path = GlobalData.RenamedFiles[0].FullPath;
                        IEDSParser parser = GlobalData.Parsers.ContainsKey(Path.GetExtension(path).ToLower()) ?
                                            GlobalData.Parsers[Path.GetExtension(path).ToLower()] : GlobalData.Parsers["*.*"];
                        if (parser != null)  //For some nasty reason the file got deleted or doesnot exist
                        {
                            StringDictionary properties = parser.GetProperties(path);
                            if (properties != null)
                            {
                                //Initialize the indexer
                                EDSIndexer indexer = new EDSIndexer(GlobalData.IndexRootPath + path[0]);
                                indexer.Index(properties);
                                indexer.Close();
                            }
                        }
                        GlobalData.lIndexingStatus.Text = "Renamed file " + path + " is updated in the indexes";
                        GlobalData.RenamedFiles.RemoveAt(0);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
#if Log
                Console.WriteLine(ex);
#endif
            }
        }