/// <summary> /// Gets an ordered <see cref="IReadOnlyList{ChunkTreeResult}"/> of parsed <see cref="ChunkTree"/>s and /// file paths for each <c>_ViewImports</c> that is applicable to the page located at /// <paramref name="pagePath"/>. The list is ordered so that the <see cref="ChunkTreeResult"/>'s /// <see cref="ChunkTreeResult.ChunkTree"/> for the <c>_ViewImports</c> closest to the /// <paramref name="pagePath"/> in the file system appears first. /// </summary> /// <param name="pagePath">The path of the page to locate inherited chunks for.</param> /// <returns>A <see cref="IReadOnlyList{ChunkTreeResult}"/> of parsed <c>_ViewImports</c> /// <see cref="ChunkTree"/>s and their file paths.</returns> /// <remarks> /// The resulting <see cref="IReadOnlyList{ChunkTreeResult}"/> is ordered so that the result /// for a _ViewImport closest to the application root appears first and the _ViewImport /// closest to the page appears last i.e. /// [ /_ViewImport, /Views/_ViewImport, /Views/Home/_ViewImport ] /// </remarks> public virtual IReadOnlyList <ChunkTreeResult> GetInheritedChunkTreeResults(string pagePath) { if (pagePath == null) { throw new ArgumentNullException(nameof(pagePath)); } var inheritedChunkTreeResults = new List <ChunkTreeResult>(); var templateEngine = new RazorTemplateEngine(_razorHost); foreach (var viewImportsPath in ViewHierarchyUtility.GetViewImportsLocations(pagePath)) { // viewImportsPath contains the app-relative path of the _ViewImports. // Since the parsing of a _ViewImports would cause parent _ViewImports to be parsed // we need to ensure the paths are app-relative to allow the GetGlobalFileLocations // for the current _ViewImports to succeed. var chunkTree = _chunkTreeCache.GetOrAdd( viewImportsPath, fileInfo => ParseViewFile( templateEngine, fileInfo, viewImportsPath)); if (chunkTree != null) { var result = new ChunkTreeResult(chunkTree, viewImportsPath); inheritedChunkTreeResults.Insert(0, result); } } return(inheritedChunkTreeResults); }
/// <summary> /// Gets an ordered <see cref="IReadOnlyList{ChunkTreeResult}"/> of parsed <see cref="ChunkTree"/>s and /// file paths for each <c>_ViewImports</c> that is applicable to the page located at /// <paramref name="pagePath"/>. The list is ordered so that the <see cref="ChunkTreeResult"/>'s /// <see cref="ChunkTreeResult.ChunkTree"/> for the <c>_ViewImports</c> closest to the /// <paramref name="pagePath"/> in the file system appears first. /// </summary> /// <param name="pagePath">The path of the page to locate inherited chunks for.</param> /// <returns>A <see cref="IReadOnlyList{ChunkTreeResult}"/> of parsed <c>_ViewImports</c> /// <see cref="ChunkTree"/>s and their file paths.</returns> /// <remarks> /// The resulting <see cref="IReadOnlyList{ChunkTreeResult}"/> is ordered so that the result /// for a _ViewImport closest to the application root appears first and the _ViewImport /// closest to the page appears last i.e. /// [ /_ViewImport, /Views/_ViewImport, /Views/Home/_ViewImport ] /// </remarks> public virtual IReadOnlyList<ChunkTreeResult> GetInheritedChunkTreeResults(string pagePath) { if (pagePath == null) { throw new ArgumentNullException(nameof(pagePath)); } var inheritedChunkTreeResults = new List<ChunkTreeResult>(); var templateEngine = new RazorTemplateEngine(_razorHost); foreach (var viewImportsPath in ViewHierarchyUtility.GetViewImportsLocations(pagePath)) { // viewImportsPath contains the app-relative path of the _ViewImports. // Since the parsing of a _ViewImports would cause parent _ViewImports to be parsed // we need to ensure the paths are app-relative to allow the GetGlobalFileLocations // for the current _ViewImports to succeed. var chunkTree = _chunkTreeCache.GetOrAdd( viewImportsPath, fileInfo => ParseViewFile( templateEngine, fileInfo, viewImportsPath)); if (chunkTree != null) { var result = new ChunkTreeResult(chunkTree, viewImportsPath); inheritedChunkTreeResults.Insert(0, result); } } return inheritedChunkTreeResults; }