/// <summary> /// Challenge a relative path. This method ignores the <see cref="MatchBehavior"/> property. /// </summary> /// <param name="rootedFilePath">The relative path to challenge.</param> /// <param name="r">Result of the match. If a rule has been found, it contains the <see cref="FileNameFilter.Root"/> as its <see cref="Result.RemovableRoot"/>.</param> /// <returns>The <see cref="FilterMatchResult"/>.</returns> public FilterMatchResult IncludedFile(string rootedFilePath, out Result r) { FilterMatchResult match = FilterMatchResult.None; string filterRoot = null; foreach (FileNameFilter filter in Filters) { match = filter.FilePathMatch(rootedFilePath); if (match != FilterMatchResult.None) { filterRoot = filter.Root ?? String.Empty; break; } } if (filterRoot == null) { Debug.Assert(match == FilterMatchResult.None); r = new Result(rootedFilePath, String.Empty, rootedFilePath); } else { r = new Result(rootedFilePath, filterRoot, rootedFilePath.Substring(filterRoot.Length)); } return(match); }
/// <summary> /// Returns the list of file paths included by this FileGroupTarget. /// It can throw an <see cref="UnmatchedFileException"/> if <see cref="MatchBehavior"/> is <see cref="FileFilterMatchBehavior.NoneIsUnmatchedFileException"/>. /// </summary> /// <param name="root">The path of the directory into which we must look for included file paths.</param> /// <returns>The list of included file paths relative to <paramref name="root"/>.</returns> public IEnumerable <Result> IncludedFiles(string root, IVirtualFileStorage fs) { if (string.IsNullOrWhiteSpace(root)) { throw new ArgumentException("root must be not null nor whitespace", "root"); } if (fs == null) { throw new ArgumentNullException("fs"); } foreach (string fullName in fs.EnumerateFiles(root)) { FilterMatchResult m = FilterMatchResult.None; string filePath = fullName.Substring(root.Length); string filterRoot = null; foreach (FileNameFilter filter in Filters) { m = filter.FilePathMatch(filePath); if (m != FilterMatchResult.Excluded) { filterRoot = filter.Root ?? String.Empty; } if (m != FilterMatchResult.None) { break; } } if (m == FilterMatchResult.None && _matchBehavior == FileFilterMatchBehavior.NoneIsUnmatchedFileException) { throw new UnmatchedFileException(fullName); } if (m == FilterMatchResult.Included || (m == FilterMatchResult.None && _matchBehavior == FileFilterMatchBehavior.NoneIsIncluded)) { yield return(new Result(filePath, filterRoot, filePath.Substring(filterRoot.Length))); } } }