public void TestFilterEvaluationFailure()
        {
            FilterCondition parentDirectoryCondition = new FilterCondition(FileMetaAttributesStringConstants.FileMetaAttributeParentDirectory, FileFilterOperator.Equals,
                                                                   @"C:\Projects\Classifier\findfilesutil\Trunk\src\KMPAlgorithmTestRunner\KMPAlgorithmTestRunner\TestData", FilterAttributeDataType.String);
            FilterCondition fileExtensionFilterCondition = new FilterCondition(FileMetaAttributesStringConstants.FileMetaAttributeFileExtension, FileFilterOperator.Equals, "xls", FilterAttributeDataType.String);

            List<FilterCondition> filterConditions = new List<FilterCondition>();
            filterConditions.Add(parentDirectoryCondition);
            filterConditions.Add(fileExtensionFilterCondition);

            //Get information about a test file and then create a dummy filter condition based on the
            //file attribites of the test file

            FileInfo fileInfo = new FileInfo(@"C:\Projects\Classifier\findfilesutil\Trunk\src\KMPAlgorithmTestRunner\KMPAlgorithmTestRunner\TestData\Microsoft.txt");

            FilterCondition fileCreateCondition = new FilterCondition(FileMetaAttributesStringConstants.FileMetaAttributeCreationTime, FileFilterOperator.Equals, fileInfo.CreationTime.Ticks.ToString(), FilterAttributeDataType.Long);
            FileMetaAttributes fileAttributes = new FileMetaAttributes(fileInfo.DirectoryName, fileInfo.CreationTime.Ticks, fileInfo.LastWriteTime.Ticks, fileInfo.Length, fileInfo.Extension, @"HORNET\\prahaladd");

            filterConditions.Add(fileCreateCondition);

            FileMetaAttributeFilter fileFilter = new FileMetaAttributeFilter(filterConditions);

            FileFilterEvaluator filterEvaluator = new FileFilterEvaluator(fileFilter, fileAttributes);

            bool result = filterEvaluator.EvaluateFilter();

            Assert.IsFalse(result);
        }
        public void SearchInFiles(bool searchSubDirectories, FileMetaAttributeFilter fileFilter)
        {
            DirectoryTreeWalker directoryTreeWalker = new DirectoryTreeWalker();
            directoryTreeWalker.SearchSubDirectories = searchSubDirectories;
            directoryTreeWalker.WalkTheTree(SearchRootPath);

            //ok now the tree has been walked. Get the list of all the text files and then determine the presence of the strings
            string fileContent = string.Empty;

            foreach (string file in directoryTreeWalker.Files)
            {
                if (!Utilities.IsTextFile(file))
                    continue;

                FileMetaAttributes fileAttributes = Utilities.GetFileMetaAttributes(file);

                if (null != fileFilter && !Utilities.EvaluateMetaAttributeFilters(fileAttributes, fileFilter))
                    continue;

                fileContent = Utilities.ReadTextFromFiles(file);

                KMPEngine kmpEngine = new KMPEngine(fileContent, SearchPattern);

                List<int> occurences = kmpEngine.Find(true, true);

                if (occurences.Count == 0)
                    continue;

                if (occurences[0] != -1)
                {

                    _fileNamesWithContentPresent.Add(file);

                    _fileNameToOccurencePositionsMap.Add(file, occurences);
                }
            }
        }
Exemplo n.º 3
0
 public static bool EvaluateMetaAttributeFilters(FileMetaAttributes fileAttributes, FileMetaAttributeFilter filter)
 {
     FileFilterEvaluator filterEvaluator = new FileFilterEvaluator(filter,fileAttributes);
     return filterEvaluator.EvaluateFilter();
 }
 /// <summary>
 /// Creates an instance of a file filter evaluator
 /// </summary>
 /// <param name="fileFilter">The file filter to be evaluated</param>
 /// <param name="fileAttributes">The attributes of the file against which the filter will be evaluated</param>
 public FileFilterEvaluator(FileMetaAttributeFilter fileFilter, FileMetaAttributes fileAttributes)
 {
     _fileFilter = fileFilter;
     _fileAttributes = fileAttributes;
 }