示例#1
0
        /// <summary>
        /// Try to resolve, read and return the content by the requested path.
        /// All includes (respresented by AutoIncludeName e.g. _viewStart) from the
        /// current folder until te virtual root folder are inserted as well.
        /// The nearest include is inserted as the last, so the nearest include
        /// defines any possible  override (e.g. Layout setting).
        /// </summary>
        /// <remarks>
        /// The content itself is never cached.
        /// </remarks>
        /// <param name="requestedPath">The requested path.</param>
        /// <returns>The content or null if no content was found</returns>
        public string TryGetContent(string requestedPath)
        {
            var resourceName = TryGetResourceName(requestedPath);

            if (resourceName == null)
            {
                return(null);
            }

            var content = ContentProvider.TryGetContent(resourceName);

            if (content == null || _autoIncludeName == null)
            {
                return(content);
            }

            var virtualPath = TryGetVirtualPath(requestedPath);

            var sb             = new StringBuilder(content);
            var nearestInclude = _pathBuilder
                                 .New()
                                 .CombineWith(virtualPath)
                                 .RemoveLastPart()
                                 .CombineWith(_autoIncludeName)
                                 .AddOrKeepExtension(_defaultExtension);

            var includes = FindAutoIncludes(nearestInclude).ToList();

            foreach (var include in includes)
            {
                //sb.Insert(0, Environment.NewLine);
                sb.Insert(0, ContentProvider.TryGetContent(include));
            }
            return(sb.ToString());
        }