/// <summary> /// Filters the documents by destination. /// </summary> /// <remarks> /// This module filters documents using "or" logic. If you want to also apply /// "and" conditions, chain additional calls. /// </remarks> /// <typeparam name="TDocument">The document type.</typeparam> /// <param name="documents">The documents.</param> /// <param name="patterns">The globbing pattern(s) to match.</param> /// <returns>The documents that match the globbing pattern(s).</returns> public static DocumentList <TDocument> FilterDestinations <TDocument>(this IEnumerable <TDocument> documents, IEnumerable <string> patterns) where TDocument : IDocument { _ = documents ?? throw new ArgumentNullException(nameof(documents)); _ = patterns ?? throw new ArgumentNullException(nameof(patterns)); DocumentFileProvider fileProvider = new DocumentFileProvider((IEnumerable <IDocument>)documents, false); IEnumerable <IFile> matches = Globber.GetFiles(fileProvider.GetDirectory("/"), patterns); return(matches.Select(x => x.Path).Distinct().Select(match => fileProvider.GetDocument(match)).Cast <TDocument>().ToDocumentList()); }
/// <summary> /// Filters the documents by source. /// </summary> /// <remarks> /// This module filters documents using "or" logic. If you want to also apply /// "and" conditions, chain additional calls. /// </remarks> /// <typeparam name="TDocument">The document type.</typeparam> /// <param name="documents">The documents.</param> /// <param name="patterns">The globbing pattern(s) to match.</param> /// <returns>The documents that match the globbing pattern(s).</returns> public static DocumentList <TDocument> FilterSources <TDocument>(this IEnumerable <TDocument> documents, IEnumerable <string> patterns) where TDocument : IDocument { _ = documents ?? throw new ArgumentNullException(nameof(documents)); _ = patterns ?? throw new ArgumentNullException(nameof(patterns)); DocumentFileProvider fileProvider = new DocumentFileProvider((IEnumerable <IDocument>)documents, true); IEnumerable <IDirectory> directories = IExecutionContext.Current.FileSystem .GetInputDirectories() .Select(x => fileProvider.GetDirectory(x.Path)); IEnumerable <IFile> matches = directories.SelectMany(x => Globber.GetFiles(x, patterns)); return(matches.Select(x => x.Path).Distinct().Select(match => fileProvider.GetDocument(match)).Cast <TDocument>().ToDocumentList()); }