예제 #1
0
 public override bool Filter( IFileInfo File )
 {
     if ( !File.Exists ) {
         return false; // It can't be read-only if it doesn't exist
     }
     return File.IsReadOnly;
 }
예제 #2
0
        public override bool Filter( IFileInfo File )
        {
            bool results = false;

            foreach ( FilterBase filter in this.Filters ) {
                if ( filter.Filter( File ) ) {
                    results = true; // One passed
                    break;
                }
            }

            return results;
        }
예제 #3
0
        public void TestIt()
        {
            FileInfo fi = new FileInfo( Assembly.GetExecutingAssembly().CodeBase.Substring( 8 ) ); // Get past file://
            Assert.AreEqual( true, fi.Exists );

            IFileInfo ifi = new IFileInfo( fi.FullName );

            Assert.AreEqual( fi.FullName, ifi.FullName );
            Assert.AreEqual( fi.Exists, ifi.Exists );
            Assert.AreEqual( fi.Length, ifi.Length );
            Assert.AreEqual( fi.IsReadOnly, ifi.IsReadOnly );
            Assert.AreEqual( fi.LastWriteTime, ifi.LastWriteTime );
        }
예제 #4
0
        public override bool Filter( IFileInfo IFileInfo )
        {
            string stringPattern = ( this.StringFilter ?? "" ).Trim();
            string regexPattern = ( this.RegexFilter ?? "" ).Trim();
            bool casesensitive = this.CaseSensitive;

            if ( string.IsNullOrEmpty( stringPattern ) == string.IsNullOrEmpty( regexPattern ) ) {
                throw new BuildException( "<restrict> <contains .../> </restrict> requires exactly one string=\"\" or regex=\"\"." );
            }

            string content = IFileInfo.Contents;
            if ( string.IsNullOrEmpty( content ) ) {
                return false; // A blank file doesn't match any filter
            }

            bool match = false; // It hasn't matched yet

            if ( !string.IsNullOrEmpty( stringPattern ) ) {
                // Check for a name match

                if ( casesensitive ) {
                    // Case sensitive
                    match = content.Contains( stringPattern );
                } else {
                    // Case insensitive
                    match = content.Contains( stringPattern, StringComparison.InvariantCultureIgnoreCase );
                }

            } else if ( !string.IsNullOrEmpty( regexPattern ) ) {
                // Check for a regex match

                RegexOptions options = RegexOptions.Multiline | RegexOptions.CultureInvariant;
                if ( !casesensitive ) {
                    options |= RegexOptions.IgnoreCase;
                }
                try {
                    match = Regex.IsMatch( content, regexPattern, options );
                } catch ( ArgumentException ex ) {
                    throw new BuildException( string.Format( "Error in Regex: {0}, Message: {1}", regexPattern, ex.Message ), ex );
                }
            }

            return match;
        }
예제 #5
0
        public override bool Filter( IFileInfo File )
        {
            if ( !File.Exists ) {
                return false; // Can't compare the date of a file that doesn't exist
            }

            double filterSize = this.SizeInK;
            double fileSize = (double)File.Length / 1024.0;

            bool results = false;

            switch ( this.When ) {
                case SizeWhen.equal:
                case SizeWhen.eq:
                    results = ( fileSize == filterSize );
                    break;
                case SizeWhen.greater:
                case SizeWhen.gt:
                    results = ( fileSize > filterSize );
                    break;
                case SizeWhen.less:
                case SizeWhen.lt:
                    results = ( fileSize < filterSize );
                    break;
                case SizeWhen.greaterorequal:
                case SizeWhen.ge:
                    results = ( fileSize >= filterSize );
                    break;
                case SizeWhen.notequal:
                case SizeWhen.ne:
                    results = ( fileSize != filterSize );
                    break;
                case SizeWhen.lessorequal:
                case SizeWhen.le:
                    results = ( fileSize <= filterSize );
                    break;
                default:
                    throw new ValidationException( this.When + " is not a valid when" );
            }

            return results;
        }
예제 #6
0
        public void ContentsTest()
        {
            FileInfo fi = new FileInfo( contentTestFile );
            Assert.AreEqual( true, fi.Exists );

            IFileInfo ifi = new IFileInfo( fi.FullName );

            Assert.AreEqual( fi.FullName, ifi.FullName );
            Assert.AreEqual( fi.Exists, ifi.Exists );
            Assert.AreEqual( fi.Length, ifi.Length );
            Assert.AreEqual( fi.IsReadOnly, ifi.IsReadOnly );
            Assert.AreEqual( fi.LastWriteTime, ifi.LastWriteTime );

            string content = ifi.Contents;
            Assert.IsNotNull( content );

            string expectedContent = File.ReadAllText( contentTestFile );
            Assert.IsNotNull( expectedContent );

            Assert.AreEqual( expectedContent, content );
            Assert.IsTrue( content.Contains( "localhost" ) );
        }
예제 #7
0
        public override bool Filter( IFileInfo File )
        {
            int failCount = 0;
            int passCount = 0;

            foreach ( FilterBase filter in this.Filters ) {
                if ( filter.Filter( File ) ) {
                    passCount++;
                } else {
                    failCount++;
                }
            }

            bool results = false;

            if ( passCount == failCount ) {
                results = AllowTie;
            } else {
                results = ( passCount > failCount );
            }

            return results;
        }
예제 #8
0
 public override bool Filter( IFileInfo File )
 {
     return state;
 }
예제 #9
0
 public override bool Filter( IFileInfo File )
 {
     return !base.Filter( File );
 }
예제 #10
0
        public override void Scan()
        {
            if ( this.Files == null ) {
                throw new BuildException( " [restrict] <fileset .../> is not defined." );
            }
            if ( this.filters.Count == 0 ) {
                throw new BuildException( " [restrict] no filters defined." );
            }
            this.filters.Sort( ( a, b ) => ( (int)a.Priority ).CompareTo( (int)b.Priority ) );

            foreach ( FilterBase filter in this.filters ) {
                FilterNestedBase nested = filter as FilterNestedBase;
                if ( nested != null ) {
                    nested.NestedInitialize();
                }
            }
            if ( this.Verbose ) {
                this.Log( Level.Info, " [restrict] basedir: " + this.baseDirectory );
            }

            DirectoryScanner scanner = this.scanner; // Avoid re-reflecting every time
            try {
                StringEnumerator fileEnumerator = this.Files.FileNames.GetEnumerator();
                while ( fileEnumerator.MoveNext() ) {
                    string filename = fileEnumerator.Current;
                    if ( string.IsNullOrEmpty( filename ) ) {
                        throw new ArgumentNullException( "filename" );
                    }
                    IFileInfo fi = new IFileInfo( filename );

                    // Filter it
                    bool passed = true;
                    foreach ( FilterBase filter in this.filters ) {
                        if ( !filter.Filter( fi ) ) {
                            // This filter said not to use it
                            passed = false;
                            if ( this.Verbose ) {
                                this.Log( Level.Info, " [restrict] failed by " + filter.Description() + ": " + filename );
                            }
                            continue;
                        }
                    }

                    if ( passed ) {
                        scanner.FileNames.Add( filename );
                        if ( this.Verbose ) {
                            this.Log( Level.Info, " [restrict] passed: " + filename );
                        }
                    }
                }

                this.hasScanned = true;
            } catch ( Exception ex ) {
                throw new BuildException( " [restrict] Error building restricted results", this.Location, ex );
            }
            if ( this.FailOnEmpty && ( this.scanner.FileNames.Count == 0 ) ) {
                throw new ValidationException( " [restrict] No matching files when filtering in " + this.baseDirectory.FullName, this.Location );
            }
        }
예제 #11
0
        public override bool Filter( IFileInfo File )
        {
            string stringPattern = ( this.StringFilter ?? "" ).Trim();
            string regexPattern = ( this.RegexFilter ?? "" ).Trim();
            bool casesensitive = this.CaseSensitive;

            if ( string.IsNullOrEmpty( stringPattern ) == string.IsNullOrEmpty( regexPattern ) ) {
                throw new BuildException( "<restrict> <name .../> </restrict> requires exactly one name=\"\" or regex=\"\"." );
            }

            string filename = File.FullName;
            if ( string.IsNullOrEmpty( filename ) ) {
                return false; // A blank filename doesn't match any filename filter
            }

            if ( this.HandleDirSep ) {
                filename = filename.Replace( "\\", "/" );
            }

            bool match = false; // It hasn't matched yet

            if ( !string.IsNullOrEmpty( stringPattern ) ) {
                // Check for a name match

                if ( casesensitive ) {
                    // Case sensitive
                    match = filename.Contains( stringPattern );
                } else {
                    // Case insensitive
                    match = filename.Contains( stringPattern, StringComparison.InvariantCultureIgnoreCase );
                }

            } else if ( !string.IsNullOrEmpty( regexPattern ) ) {
                // Check for a regex match

                RegexOptions options = RegexOptions.Singleline | RegexOptions.CultureInvariant;
                if ( !casesensitive ) {
                    options |= RegexOptions.IgnoreCase;
                }
                try {
                    match = Regex.IsMatch( filename, regexPattern, options );
                } catch (ArgumentException ex) {
                    throw new BuildException( string.Format( "Error in Regex \"{0}\" on file \"{1}\", Message: {2}", regexPattern, filename, ex.Message ), ex );
                }
            }

            return match;
        }
예제 #12
0
        public override bool Filter( IFileInfo File )
        {
            if ( !File.Exists ) {
                return false; // Can't compare the date of a file that doesn't exist
            }

            DateTime matchDate = this.DateTime;
            if ( MillisecondsSinceEpoch != 0 && matchDate == epoch ) {
                matchDate = matchDate.AddMilliseconds( MillisecondsSinceEpoch );
            } else if ( MillisecondsSinceEpoch != 0 ) {
                throw new ValidationException( "There must be exactly one datetime or mills, not both" );
            } else if ( this.DateTime == epoch ) {
                // You didn't set it, but do I care?
            }

            bool results = false;

            switch ( this.When ) {
                case TimeWhen.before:
                    matchDate = matchDate.AddMilliseconds( Granularity );
                    results = ( File.LastWriteTime.Ticks < matchDate.Ticks );
                    break;
                case TimeWhen.after:
                    matchDate = matchDate.AddMilliseconds( -Granularity );
                    results = ( File.LastWriteTime.Ticks > matchDate.Ticks );
                    break;
                case TimeWhen.equal:
                    // Must match withing the window of granularity
                    DateTime start = matchDate.AddMilliseconds( -Granularity );
                    DateTime end = matchDate.AddMilliseconds( Granularity );
                    results = ( start.Ticks <= File.LastWriteTime.Ticks ) && ( end.Ticks >= File.LastWriteTime.Ticks );
                    break;
                default:
                    throw new ValidationException( this.When + " is not a valid when" );
            }

            return results;
        }
예제 #13
0
 /// <summary>
 /// Does this file match this filter?
 /// </summary>
 /// <param name="File">The file</param>
 /// <returns>Does it match the filter? yes or no</returns>
 public abstract bool Filter( IFileInfo File );
예제 #14
0
 public override bool Filter( IFileInfo File )
 {
     return File.Exists;
 }