public void Persist(IndexDatabase indexDatabase)
        {
            IFormatter binaryFormatter = new BinaryFormatter();

            string appDataFolderPath = Environment.GetEnvironmentVariable("appdata");

            Directory.CreateDirectory(string.Format("{0}\\{1}",appDataFolderPath,"KMPSearcher"));

            string indexDatabaseFileName = string.Format("{0}\\KMPSearcher\\KMPIDB.db", appDataFolderPath);

            using (Stream idbStream = new FileStream(indexDatabaseFileName, FileMode.Create, FileAccess.Write))
            {
                binaryFormatter.Serialize(idbStream, indexDatabase);
                idbStream.Close();

            }
        }
        public void TestIndexDatabaseSerialization()
        {
            IndexRecord indexRecord1 = new IndexRecord(@"C:\DummyFile.txt",new List<int>() { 1,2,3,4,5 });
            IndexRecord indexRecord2 = new IndexRecord(@"C:\DummyFile1.txt", new List<int>() { 1, 2, 3 });

            List<IndexRecord> indexRecords = new List<IndexRecord>() { indexRecord1, indexRecord2 };

            Dictionary<string,List<IndexRecord>> searchPatternToIndexRecords = new Dictionary<string,List<IndexRecord>>();

            searchPatternToIndexRecords.Add("Test",indexRecords);

            IndexDatabase indexDatabase = new IndexDatabase(searchPatternToIndexRecords,DateTime.Now);

            //serialize the index database
            IndexDatabaseWriter writer = new IndexDatabaseWriter();
            writer.Persist(indexDatabase);
        }
Exemplo n.º 3
0
        private void FetchFilesAndIndex(string[] filePathsToIndex)
        {
            foreach (string filePath in filePathsToIndex)
            {

                _directoryTreeWalker = new DirectoryTreeWalker();

                _directoryTreeWalker.SearchSubDirectories = true;

                _directoryTreeWalker.WalkTheTree(filePath);

                List<string> files = _directoryTreeWalker.Files;

                IndexInternal(files);

            }
            _indexDatabase = new IndexDatabase(_indexDatabaseEntries, DateTime.UtcNow);
            //persist the entire database to the disk
            IndexDatabaseWriter idbWriter = new IndexDatabaseWriter();
            idbWriter.Persist(_indexDatabase);
        }