Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the Grep class.
        /// </summary>
        /// <history>
        /// [Curtis_Beard]		07/12/2006	Created
        /// [Andrew_Radford]    13/08/2009  Added Const. dependency on ISearchSpec, IFileFilterSpec
        /// [Curtis_Beard]		05/28/2015	FIX: 69, Created for speed improvements for encoding detection
        /// </history>
        public Grep(ISearchSpec searchSpec, IFileFilterSpec filterSpec)
        {
            if (searchSpec.EncodingDetectionOptions == null)
             {
            throw new ArgumentNullException("ISearchSpec.EncodingDetectionOptions", "EncodingDetectionOptions must not be null");
             }

             SearchSpec = searchSpec;
             FileFilterSpec = filterSpec;
             MatchResults = new List<MatchResult>();

             if (FileFilterSpec.FilterItems != null)
             {
            // get first file->minimum hit count filter (should only be 1)
            var fileCountFilter = (from f in FileFilterSpec.FilterItems where f.FilterType.Category == FilterType.Categories.File && f.FilterType.SubCategory == FilterType.SubCategories.MinimumHitCount select f).FirstOrDefault();

            if (fileCountFilter != null)
            {
               int.TryParse(fileCountFilter.Value, out userFilterCount);
            }
             }

             if (SearchSpec.EncodingDetectionOptions.DetectFileEncoding && SearchSpec.EncodingDetectionOptions.UseEncodingCache)
             {
            EncodingCache.Instance.Load(SearchSpec.EncodingDetectionOptions.PerformanceSetting);
             }
        }
Exemple #2
0
        /// <summary>
        /// Return true if the file does not pass the fileFilterSpec, i.e should be skipped
        /// </summary>
        /// <param name="file">FileInfo object of current file</param>
        /// <param name="fileFilterSpec">Current file filter settings</param>
        /// <param name="filterItem">Item causing filtering, null if none</param>
        /// <param name="filterValue">Output of actual filter value</param>
        /// <returns>true if file does not pass file filter settings, false otherwise</returns>
        /// <history>
        /// [Andrew_Radford]    13/08/2009  Created
        /// [Curtis_Beard]	   03/07/2012	ADD: 3131609, exclusions
        /// </history>
        private static bool ShouldFilterOut(FileInfo file, IFileFilterSpec fileFilterSpec, out FilterItem filterItem, out string filterValue)
        {
            filterItem = null;
             filterValue = string.Empty;

             if (fileFilterSpec.FilterItems != null && fileFilterSpec.FilterItems.Count > 0)
             {
            var fileFilterItems = from f in fileFilterSpec.FilterItems where f.FilterType.Category == FilterType.Categories.File select f;
            foreach (FilterItem item in fileFilterItems)
            {
               filterValue = string.Empty;
               if (item.ShouldExcludeFile(file, out filterValue))
               {
                  filterItem = item;
                  return true;
               }
            }
             }

             return false;
        }
Exemple #3
0
        /// <summary>
        /// Logs a start search message to log file.
        /// </summary>
        /// <param name="searchSpec">Current search specification</param>
        /// <param name="fileFilterSpec">Current file filter specification</param>
        /// <history>
        /// [Curtis_Beard]		05/15/2015	Initial
        /// [Curtis_Beard]	   05/26/2015	FIX: 69, add performance setting, cache for file encoding detection
        /// </history>
        private void LogStartSearchMessage(ISearchSpec searchSpec, IFileFilterSpec fileFilterSpec)
        {
            StringBuilder searchTextOptions = new StringBuilder();
             LogSearchOptionHelper(searchTextOptions, searchSpec.UseRegularExpressions, "regex");
             LogSearchOptionHelper(searchTextOptions, searchSpec.UseCaseSensitivity, "case sensitive");
             LogSearchOptionHelper(searchTextOptions, searchSpec.UseWholeWordMatching, "whole word");
             LogSearchOptionHelper(searchTextOptions, searchSpec.UseNegation, "negation");
             LogSearchOptionHelper(searchTextOptions, searchSpec.ReturnOnlyFileNames, "only file names");
             LogSearchOptionHelper(searchTextOptions, searchSpec.ContextLines > 0, string.Format("{0} context lines", searchSpec.ContextLines));

             if (searchTextOptions.Length > 0)
             {
            searchTextOptions.Insert(0, "[");
            searchTextOptions.Append("]");
             }

             StringBuilder fileEncoding = new StringBuilder();
             if (searchSpec.EncodingDetectionOptions.DetectFileEncoding)
             {
            fileEncoding.Append("[");
            fileEncoding.Append("detect encoding");
            fileEncoding.AppendFormat(", performance set at {0}", Enum.GetName(typeof(EncodingOptions.Performance), GeneralSettings.EncodingPerformance).ToLower());

            if (searchSpec.EncodingDetectionOptions.UseEncodingCache)
            {
               fileEncoding.Append(", cache enabled");
            }

            fileEncoding.Append("]");
             }

             LogClient.Instance.Logger.Info("Search started in '{0}'{1} against {2}{3} for {4}{5}",
            searchSpec.StartFilePaths != null && searchSpec.StartFilePaths.Length > 0 ? string.Join(", ", searchSpec.StartFilePaths) : string.Join(", ", searchSpec.StartDirectories),
            searchSpec.SearchInSubfolders ? "[include sub folders]" : "",
            fileFilterSpec.FileFilter,
            fileEncoding.ToString(),
            searchSpec.SearchText,
            searchTextOptions.ToString());
        }