예제 #1
0
        /// <summary>
        /// Evaluates the File and Text filters for a provided file. Returns true if both match, otherwise false.
        /// </summary>
        private async Task <bool> SearchFile(string filePath)
        {
            // file filter matches
            if (FileFilter.Evaluate(filePath) == false)
            {
                return(false);
            }

            // dont read files over certain size (setting in MB)
            long fileSizeLimit = 1024 * 1024 * _appSettings.FileSizeLimit;
            long fileSize      = new FileInfo(filePath).Length;

            if (fileSizeLimit < fileSize)
            {
                return(false);
            }



            string fileContents;

            try
            {
                // need entire contents to test regex
                fileContents = await File.ReadAllTextAsync(filePath);
            } catch (Exception e)
            {
                //throw e
                return(false); // ignore file read errors
            }

            // evaluate text filter
            if (TextFilter.Evaluate(fileContents))
            {
                return(true);
            }

            return(false);
        }