Exemple #1
0
 internal DocumentFile(DocumentFileProvider fileProvider, FilePath path)
 {
     _fileProvider = fileProvider ?? throw new ArgumentNullException(nameof(fileProvider));
     if (!fileProvider.Files.TryGetValue(path, out _document))
     {
         _document = null;
     }
     Path = path ?? throw new ArgumentNullException(nameof(path));
 }
Exemple #2
0
        /// <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());
        }
Exemple #3
0
        /// <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());
        }
 internal DocumentDirectory(DocumentFileProvider fileProvider, DirectoryPath path)
 {
     _fileProvider = fileProvider ?? throw new ArgumentNullException(nameof(fileProvider));
     Path          = path ?? throw new ArgumentNullException(nameof(path));
 }
 internal DocumentDirectory(DocumentFileProvider fileProvider, NormalizedPath path)
 {
     _fileProvider = fileProvider ?? throw new ArgumentNullException(nameof(fileProvider));
     path.ThrowIfNull(nameof(path));
     Path = path;
 }