Exemple #1
0
        /// <summary>
        /// Creates an array of regex objects. There will be one for each of the search patterns specified in the searchPatterns parameter.
        /// </summary>
        /// <param name="searchPatterns">An array of one or more search patterns. Set to null if no search patterns are specified.</param>
        /// <param name="ifNullDefaultPattern">Specifies the default search pattern to create when search patterns is null.</param>
        /// <returns>An array of PFSearchPattern objects that encapsulate regex processing.</returns>
        /// <remarks>Search patterns are composed of the Windows wildcard characters for file system searches.</remarks>
        public PFSearchPattern[] GetSearchPatternRegexObjects(string[] searchPatterns, string ifNullDefaultPattern)
        {
            PFSearchPattern[] regexPatterns = null;
            int    numPatterns   = 1;
            string searchPattern = string.Empty;

            if (searchPatterns != null)
            {
                numPatterns   = searchPatterns.Length;
                regexPatterns = new PFSearchPattern[numPatterns];
                for (int i = 0; i < searchPatterns.Length; i++)
                {
                    searchPattern    = searchPatterns[i];
                    regexPatterns[i] = new PFSearchPattern(String.IsNullOrEmpty(searchPattern) ? ifNullDefaultPattern : searchPattern);
                }
            }
            else
            {
                regexPatterns    = new PFSearchPattern[1];
                regexPatterns[0] = new PFSearchPattern(ifNullDefaultPattern);
            }



            return(regexPatterns);
        }
Exemple #2
0
        public static void SearchPatternTest()
        {
            PFSearchPattern[] regexInclude = new PFSearchPattern[2];
            PFSearchPattern[] regexExclude = new PFSearchPattern[2];
            string            textToSearch = string.Empty;
            bool isMatch = false;

            try
            {
                _msg.Length = 0;
                _msg.Append("SearchPatternTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                regexInclude[0] = new PFSearchPattern("*test*");
                regexInclude[1] = new PFSearchPattern("First*");
                regexExclude[0] = new PFSearchPattern("*remove*");
                regexExclude[1] = new PFSearchPattern("DELETE:*");

                textToSearch = "This test is the first.";
                isMatch      = IsMatchToPattern(regexInclude, textToSearch);
                OutputSearchResult("INCLUDE", regexInclude, textToSearch, isMatch);

                textToSearch = "FIRST: this is it.";
                isMatch      = IsMatchToPattern(regexInclude, textToSearch);
                OutputSearchResult("INCLUDE", regexInclude, textToSearch, isMatch);

                textToSearch = "This text is the first.";
                isMatch      = IsMatchToPattern(regexInclude, textToSearch);
                OutputSearchResult("INCLUDE", regexInclude, textToSearch, isMatch);

                textToSearch = "Please remove this.";
                isMatch      = IsMatchToPattern(regexExclude, textToSearch);
                OutputSearchResult("EXCLUDE", regexInclude, textToSearch, isMatch);

                textToSearch = "FIRST: this is it.";
                isMatch      = ExtendedSearch(regexInclude, regexExclude, textToSearch);
                OutputSearchResultExt("INCLUDE-EXCLUDE", regexInclude, regexExclude, textToSearch, isMatch);

                textToSearch = "FIRST: this this is the one to remove.";
                isMatch      = ExtendedSearch(regexInclude, regexExclude, textToSearch);
                OutputSearchResultExt("INCLUDE-EXCLUDE", regexInclude, regexExclude, textToSearch, isMatch);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... SearchPatternTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }