コード例 #1
0
        /// <summary>
        /// Filters the given list of file.s
        ///
        /// If passed mode is inclusive the filter passes thru any files,
        /// which match at least one of the patterns contained in the list defined by the Patterns property.
        ///
        /// If passed mode is exclusive the filter filters out all files,
        /// which match at least one of the patterns contained in the list defined by the Pattens property.
        /// </summary>
        /// <param name="files">List of files, which should be filtered.</param>
        /// <param name="mode">Filter mode.</param>
        /// <returns>Filtered list of files.</returns>
        public IEnumerable <string> Filter(IEnumerable <string> files, FileFilterMode mode)
        {
            Regex[] patterns = Patterns != null?Patterns.Select(pattern => new Regex(pattern, RegexOptions.IgnoreCase)).ToArray() : new Regex[0];

            foreach (var filePath in files)
            {
                string fileName = System.IO.Path.GetFileName(filePath);
                if (Patterns == null || Patterns.Length == 0)
                {
                    if (mode == FileFilterMode.Inclusive)
                    {
                        yield return(filePath);
                    }
                }
                else
                {
                    bool isMatch = false;
                    foreach (var pattern in patterns)
                    {
                        if (pattern.IsMatch(fileName))
                        {
                            isMatch = true;
                            break;
                        }
                    }

                    if (isMatch ^ (mode == FileFilterMode.Exclusive))
                    {
                        yield return(filePath);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Filters the given list of file.s
        ///
        /// If passed mode is inclusive the filter passes thru any files,
        /// which match at least one of the patterns contained in the list defined by the Patterns property.
        ///
        /// If passed mode is exclusive the filter filters out all files,
        /// which match at least one of the patterns contained in the list defined by the Pattens property.
        /// </summary>
        /// <param name="files">List of files, which should be filtered.</param>
        /// <param name="mode">Filter mode.</param>
        /// <returns>Filtered list of files.</returns>
        public IEnumerable <string> Filter(IEnumerable <string> files, FileFilterMode mode)
        {
            foreach (var filePath in files)
            {
                string fileName = System.IO.Path.GetFileName(filePath);
                if (Patterns == null || Patterns.Length == 0)
                {
                    if (mode == FileFilterMode.Inclusive)
                    {
                        yield return(filePath);
                    }
                }
                else
                {
                    bool isMatch = false;
                    foreach (var pattern in Patterns)
                    {
                        if (Microsoft.VisualBasic.CompilerServices.Operators.LikeString(fileName, pattern, Microsoft.VisualBasic.CompareMethod.Text))
                        {
                            isMatch = true;
                            break;
                        }
                    }

                    if (isMatch ^ (mode == FileFilterMode.Exclusive))
                    {
                        yield return(filePath);
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Appends a regex file filter to the last file enumerator added to the compound file enumerator.
        /// </summary>
        /// <param name="mode">Mode, in which the file filter should operate.</param>
        /// <param name="patterns">Regex patterns of files, which should either pass thru or be filtered out depending on the specified filter mode.</param>
        /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns>
        public CompoundFileEnumeratorBuilder RegexFilter(FileFilterMode mode, params string[] patterns)
        {
            if (mCurrentFilterChain == null)
            {
                mCurrentFilterChain = new Filters.FilterChain();
            }

            mCurrentFilterChain.Filters.Add(new Filters.RegExFileFilter(mode, patterns));

            return(this);
        }
コード例 #4
0
 /// <summary>
 /// Either passes thru all files, or filters all out depending on value of mode parameter.
 /// </summary>
 /// <param name="files">List of files to be filtered.</param>
 /// <param name="mode">Filter mode.</param>
 /// <returns>Filtered list of files.</returns>
 public IEnumerable <string> Filter(IEnumerable <string> files, FileFilterMode mode)
 {
     if (mode == FileFilterMode.Inclusive)
     {
         foreach (var filePath in files)
         {
             yield return(filePath);
         }
     }
     else
     {
         yield break;
     }
 }
コード例 #5
0
        /// <summary>
        /// Appends a file filter to the previously added file enumerator.
        /// </summary>
        /// <typeparam name="FILTER_TYPE">Type of the filter to be appended.</typeparam>
        /// <param name="mode">Mode, in which the file filter should operate.</param>
        /// <param name="constructorArguments">Constructor arguments to be passed to the filter constructor.</param>
        /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns>
        public CompoundFileEnumeratorBuilder Filter <FILTER_TYPE>(FileFilterMode mode, params object[] constructorArguments) where FILTER_TYPE : IInvertibleFileFilter
        {
            if (mCurrentFilterChain == null)
            {
                mCurrentFilterChain = new Filters.FilterChain();
            }

            var filter = Activator.CreateInstance(typeof(FILTER_TYPE), constructorArguments) as IInvertibleFileFilter;

            filter.Mode = mode;
            mCurrentFilterChain.Filters.Add(filter);

            return(this);
        }
コード例 #6
0
        /// <summary>
        /// Appends a file filter to the previously added file enumerator.
        /// </summary>
        /// <param name="filterType">Type of the filter to be appended.</param>
        /// <param name="mode">Mode, in which the file filter should operate.</param>
        /// <param name="constructorArguments">Constructor arguments to be passed to the filter constructor.</param>
        /// <returns>CompoundFileEnumeratorBuilder creating the current compound file enumerator.</returns>
        public CompoundFileEnumeratorBuilder Filter(Type filterType, FileFilterMode mode, params object[] constructorArguments)
        {
            if (filterType == null || !typeof(IInvertibleFileFilter).IsAssignableFrom(filterType))
            {
                return(this);
            }

            if (mCurrentFilterChain == null)
            {
                mCurrentFilterChain = new Filters.FilterChain();
            }

            var filter = Activator.CreateInstance(filterType, constructorArguments) as IInvertibleFileFilter;

            filter.Mode = mode;
            mCurrentFilterChain.Filters.Add(filter);

            return(this);
        }
コード例 #7
0
 /// <summary>
 /// Initialization constructor.
 /// </summary>
 /// <param name="mode">Filter mode.</param>
 /// <param name="patterns">List of regex patterns.</param>
 public RegExFileFilter(FileFilterMode mode, params string[] patterns)
 {
     Patterns = patterns;
     Mode     = mode;
 }
コード例 #8
0
 /// <summary>
 /// Initialization constructor.
 /// </summary>
 /// <param name="mode">Filter mode.</param>
 /// <param name="patterns">List of wildcard patterns.</param>
 public WildCardFileFilter(FileFilterMode mode, params string[] patterns)
 {
     Patterns = patterns;
     Mode     = mode;
 }
コード例 #9
0
 /// <summary>
 /// Initialization constructor.
 /// </summary>
 /// <param name="mode">Filter mode.</param>
 public PassThruFileFilter(FileFilterMode mode)
 {
     Mode = mode;
 }