Пример #1
0
 //--- constructor -----------------------
 public MatchSet( CtrlFilter[] list, bool isCaseSensitive )
 {
     List<MatchPath> ifo = new List<MatchPath>();
     List<MatchPath> ifi = new List<MatchPath>();
     List<MatchPath> hfo = new List<MatchPath>();
     List<MatchPath> hfi = new List<MatchPath>();
     if( list != null )
     {
         foreach( CtrlFilter f in list )
         {
             string s = f.Pattern;
             if( ! string.IsNullOrEmpty( s ) )
             {
                 s = s.Trim();
                 if( ! string.IsNullOrEmpty( s ) )
                 {
                     MatchPath mp = new MatchPath( f.Action, s, isCaseSensitive );
                     switch( f.Action )
                     {
                         case CtrlFilter.ActionType.Include:  if( mp.IsDirectory ) { ifo.Add( mp ); } else { ifi.Add( mp ); } break;
                         case CtrlFilter.ActionType.Exclude:  if( mp.IsDirectory ) { ifo.Add( mp ); } else { ifi.Add( mp ); } break;
                         case CtrlFilter.ActionType.History:  if( mp.IsDirectory ) { hfo.Add( mp ); } else { hfi.Add( mp ); } break;
                     }
                 }
             }
         }
     }
     this.includeFolder  = ifo.ToArray();
     this.includeFile    = ifi.ToArray();
     this.historyFolder  = hfo.ToArray();
     this.historyFile    = hfi.ToArray();
 }
Пример #2
0
		void LogMatch( MatchSet.SetType type, MatchPath pattern, string path )
		{
			if( pattern.Debug )
			{
				path += "   (" + pattern.Pattern + ")";
			}
			Log( Status( 0, type, path ) );
		}
Пример #3
0
 bool IsIncluded( MatchPath[] list, string path )
 {
     bool b = true;  //..if no patterns match, assume folder/file is included
     foreach( MatchPath mp in list )
     {
         if( mp.Matches( path ) )
         {
             switch( mp.Action )
             {
                 //..all patterns are applied in order.  The result is based on the last match.
                 case CtrlFilter.ActionType.Include:  b = true ;  break;
                 case CtrlFilter.ActionType.Exclude:  b = false;  break;
             }
         }
     }
     return b;
 }
Пример #4
0
 bool IsHistory( MatchPath[] list, string path )
 {
     foreach( MatchPath mp in list )
     {
         if( mp.Matches( path ) )
         {
             //..no history is kept for this folder/file
             return false;
         }
     }
     //..history will be maintained for this folder/file
     return true;
 }
Пример #5
0
 static void Test( List<string> err, MatchPath p, string txt, bool match )
 {
     if( p.Matches( txt ) != match )
     {
         err.Add( "\"" + p.Pattern + "\" --> \"" + p.Regex + "\" --> \"" + txt + "\" --> expect " + match );
     }
 }
Пример #6
0
        public static string[] Test()
        {
            List<string> err = new List<string>();
            MatchPath p;

            p = new MatchPath( CtrlFilter.ActionType.Include, @"*.txt", false );
            {
                Test( err, p, @"abc.txt", true );
                Test( err, p, @"/abc/def.txt", true );
            }
            p = new MatchPath( CtrlFilter.ActionType.Include, @"d*e.txt", false );
            {
                Test( err, p, @"/abc/de.txt", true );
                Test( err, p, @"/abc/dfg/hie.txt", false );
            }
            p = new MatchPath( CtrlFilter.ActionType.Include, @"fred/Bar?ney.*", false );
            {
                Test( err, p, @"/abc/fred/Barney.pdf", true );
                Test( err, p, @"/abc/def/ghfred/Barney.txt", false );
                Test( err, p, @"/abc/def/fred/BarZney.txt", true );
                Test( err, p, @"/abc/def/fred/BarZZney.txt", false );
                Test( err, p, @"\abc\def\fred\Barney.txt", true );
            }
            p = new MatchPath( CtrlFilter.ActionType.Include, @"*fred/Bar?ney.*", false );
            {
                Test( err, p, @"/abc/fred/Barney.pdf", true );
                Test( err, p, @"/abc/def/ghfred/Barney.txt", true );
            }
            p = new MatchPath( CtrlFilter.ActionType.Include, @"/fred/Bar?ney.*", false );
            {
                Test( err, p, @"/abc/fred/Barney.pdf", false );
                Test( err, p, @"/fred/Barney.txt", true );
            }
            p = new MatchPath( CtrlFilter.ActionType.Include, @"/hello/.../fred/Bar?ney.*", false );
            {
                Test( err, p, @"/hello/there/fred/Barney.pdf", true );
                Test( err, p, @"/hello/there/how/are/you/fred/Barney.txt", true );
                Test( err, p, @"/hello/fred/Barney.txt", true );
            }
            p = new MatchPath( CtrlFilter.ActionType.Include, @"/hello/.../there/.../fred/Bar?ney.*", false );
            {
                Test( err, p, @"/hello/there/fred/Barney.pdf", true );
                Test( err, p, @"/hello/there/how/are/you/fred/Barney.txt", true );
                Test( err, p, @"/hello/fred/Barney.txt", false );
                Test( err, p, @"/hello/fred/there/Barney.txt", false );
            }
            p = new MatchPath( CtrlFilter.ActionType.Include, @"/hello/.../there/.../fred/Bar?ney.*", false );
            {
                Test( err, p, @"/hello/hi/there/way/fred/Barney.pdf", true );
                Test( err, p, @"/hello/hi/how/there/how/are/you/fred/Barney.txt", true );
                Test( err, p, @"/hello/there/fred/Barney.txt", true );
            }

            return err.ToArray();
        }